Mais alterações em usuários
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import { MigrationInterface, QueryRunner, TableColumn } from 'typeorm';
|
||||
|
||||
export class RemoveCpfAndCnpjFieldsFromUsersTable1655711281662
|
||||
implements MigrationInterface
|
||||
{
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.dropColumns('users', ['cnpj', 'cpf']);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.addColumns('users', [
|
||||
new TableColumn({
|
||||
name: 'cpf',
|
||||
type: 'varchar',
|
||||
isNullable: true,
|
||||
}),
|
||||
new TableColumn({
|
||||
name: 'cnpj',
|
||||
type: 'varchar',
|
||||
isNullable: true,
|
||||
}),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import { MigrationInterface, QueryRunner, TableColumn } from 'typeorm';
|
||||
|
||||
export class AddDocumentAndDocumentTypeFieldsToUsersTable1655711315251
|
||||
implements MigrationInterface
|
||||
{
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.addColumns('users', [
|
||||
new TableColumn({
|
||||
name: 'document',
|
||||
type: 'varchar',
|
||||
isNullable: true,
|
||||
}),
|
||||
new TableColumn({
|
||||
name: 'document_type',
|
||||
type: 'varchar',
|
||||
isNullable: true,
|
||||
}),
|
||||
]);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.dropColumns('users', ['document_type', 'document']);
|
||||
}
|
||||
}
|
||||
@@ -39,10 +39,10 @@ class User {
|
||||
star_rating: number;
|
||||
|
||||
@Column()
|
||||
cpf: string;
|
||||
document_type: string;
|
||||
|
||||
@Column()
|
||||
cnpj: string;
|
||||
document: string;
|
||||
|
||||
@CreateDateColumn()
|
||||
created_at: Date;
|
||||
|
||||
@@ -29,16 +29,16 @@ usersRouter.get('/list', async (request, response) => {
|
||||
|
||||
let usersWithoutSensitiveInfo: userWithoutSensitiveInfo[] = [];
|
||||
|
||||
users.map(user => {
|
||||
usersWithoutSensitiveInfo.push({
|
||||
id_user: user.id_user,
|
||||
name: user.name,
|
||||
email: user.email,
|
||||
avatar_image: user.avatar_image,
|
||||
});
|
||||
});
|
||||
// users.map(user => {
|
||||
// usersWithoutSensitiveInfo.push({
|
||||
// id_user: user.id_user,
|
||||
// name: user.name,
|
||||
// email: user.email,
|
||||
// avatar_image: user.avatar_image,
|
||||
// });
|
||||
// });
|
||||
|
||||
return response.json({ data: usersWithoutSensitiveInfo });
|
||||
return response.json({ data: users });
|
||||
});
|
||||
|
||||
// TODO, criar middleware ensureIsOwnUser é necessário?
|
||||
@@ -64,11 +64,12 @@ usersRouter.get('/:id', ensureAuthenticated, async (request, response) => {
|
||||
name: user.name,
|
||||
lastname: user.lastname,
|
||||
email: user.email,
|
||||
phone_number: user.phone_number,
|
||||
birth_date: finalDate,
|
||||
avatar_image: user.avatar_image,
|
||||
bio: user.bio,
|
||||
cpf: user.cpf,
|
||||
cnpj: user.cnpj,
|
||||
document_type: user.document_type,
|
||||
document: user.document
|
||||
// created_at: user.created_at,
|
||||
// updated_at: user.updated_at,
|
||||
};
|
||||
@@ -100,7 +101,7 @@ usersRouter.post('/', async (request, response) => {
|
||||
});
|
||||
|
||||
usersRouter.patch('/edit', ensureAuthenticated, async (request, response) => {
|
||||
const { name, lastname, username, bio, email, birth_date, cpf, cnpj } = request.body;
|
||||
const { name, lastname, bio, email, phone_number, birth_date, document_type, document } = request.body;
|
||||
|
||||
const updateUserService = new UpdateUserService();
|
||||
|
||||
@@ -108,12 +109,12 @@ usersRouter.patch('/edit', ensureAuthenticated, async (request, response) => {
|
||||
id_user: request.user.id_user,
|
||||
name,
|
||||
lastname,
|
||||
username,
|
||||
bio,
|
||||
email,
|
||||
phone_number,
|
||||
birth_date,
|
||||
cpf,
|
||||
cnpj
|
||||
document_type,
|
||||
document
|
||||
});
|
||||
|
||||
return response.json({ message: 'User info sucessfully updated.' });
|
||||
|
||||
@@ -9,16 +9,16 @@ interface Request {
|
||||
id_user: string;
|
||||
name: string;
|
||||
lastname: string;
|
||||
username: string;
|
||||
bio: string;
|
||||
email: string;
|
||||
phone_number: string;
|
||||
birth_date: string;
|
||||
cpf: string;
|
||||
cnpj: string;
|
||||
document_type: string;
|
||||
document: string;
|
||||
}
|
||||
|
||||
class UpdateUserService {
|
||||
public async execute({ id_user, name, lastname, username, bio, email, birth_date, cpf, cnpj }: Request): Promise<User> {
|
||||
public async execute({ id_user, name, lastname, bio, email, phone_number, birth_date, document_type, document }: Request): Promise<User> {
|
||||
const usersRepository = getRepository(User);
|
||||
const socialRepository = getRepository(Social);
|
||||
|
||||
@@ -27,16 +27,17 @@ class UpdateUserService {
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
throw new AppError('User does not exist.');
|
||||
throw new AppError('O usuário informado não existe.');
|
||||
};
|
||||
|
||||
if (name) user.name = name
|
||||
if (lastname) user.lastname = lastname
|
||||
if (bio) user.bio = bio
|
||||
if (email) user.email = email
|
||||
if (phone_number) user.phone_number = phone_number
|
||||
|
||||
if (cpf) user.cpf = cpf
|
||||
if (cnpj) user.cnpj = cnpj
|
||||
if (document_type) user.document_type = document_type
|
||||
if (document) user.document = document
|
||||
|
||||
// user.birth_date = new Date(birth_date); // TODO, funciona?
|
||||
|
||||
|
||||
Reference in New Issue
Block a user