Alterando informações de perfil
This commit is contained in:
@@ -9,13 +9,14 @@ import Social from '../models/Social';
|
||||
|
||||
interface Request {
|
||||
name: string;
|
||||
lastname: string;
|
||||
email: string;
|
||||
birth_date: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
class CreateUserService {
|
||||
public async execute({ name, email, birth_date, password }: Request): Promise<User> {
|
||||
public async execute({ name, lastname, email, birth_date, password }: Request): Promise<User> {
|
||||
const usersRepository = getRepository(User);
|
||||
const socialsRepository = getRepository(Social);
|
||||
|
||||
@@ -33,8 +34,9 @@ class CreateUserService {
|
||||
// TODO, arrumar o formato das datas e padronizar com a equipe
|
||||
|
||||
const user = usersRepository.create({
|
||||
id_user: v4(), name, email, birth_date, password: hashedPassword, avatar_image: "", bio: ""
|
||||
id_user: v4(), name, lastname, email, birth_date, password: hashedPassword, avatar_image: "", bio: ""
|
||||
});
|
||||
|
||||
await usersRepository.save(user);
|
||||
|
||||
// já criar registro na tabela Socials para evitar inconsistências
|
||||
|
||||
@@ -8,7 +8,7 @@ class CreateUserService {
|
||||
public async execute(id: string): Promise<User> {
|
||||
const usersRepository = getRepository(User);
|
||||
|
||||
const user = await usersRepository.findOne({
|
||||
let user = await usersRepository.findOne({
|
||||
where: { id_user: id },
|
||||
});
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import Social from '../models/Social';
|
||||
interface Request {
|
||||
id_user: string;
|
||||
name: string;
|
||||
lastname: string;
|
||||
username: string;
|
||||
bio: string;
|
||||
email: string;
|
||||
@@ -15,7 +16,7 @@ interface Request {
|
||||
}
|
||||
|
||||
class UpdateUserService {
|
||||
public async execute({ id_user, name, username, bio, email, birth_date }: Request): Promise<User> {
|
||||
public async execute({ id_user, name, lastname, username, bio, email, birth_date }: Request): Promise<User> {
|
||||
const usersRepository = getRepository(User);
|
||||
const socialRepository = getRepository(Social);
|
||||
|
||||
@@ -27,9 +28,12 @@ class UpdateUserService {
|
||||
throw new AppError('User does not exist.');
|
||||
};
|
||||
|
||||
user.name = name;
|
||||
user.bio = bio;
|
||||
user.birth_date = new Date(birth_date); // TODO, funciona?
|
||||
user.name = name
|
||||
user.lastname = lastname
|
||||
user.bio = bio
|
||||
user.email = email
|
||||
|
||||
// user.birth_date = new Date(birth_date); // TODO, funciona?
|
||||
|
||||
await usersRepository.save(user);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user