Merge branch 'master' into feature/buscar-transporte

This commit is contained in:
Hugo Falcão
2022-06-20 02:13:05 -03:00
committed by GitHub
17 changed files with 1533 additions and 395 deletions

View File

@@ -17,6 +17,8 @@ interface Response {
id_user: string;
}
const failedLoginMessage = { message: 'Combinação incorreta de login e senha.', statusCode: 200 }
class AuthenticateUserService {
public async execute({ login, password }: Request): Promise<Response> {
const usersRepository = getRepository(User);
@@ -28,7 +30,7 @@ class AuthenticateUserService {
// TODO, ajeitar todos os HTTP status code
// Por que tem que deixar 200 para funcionar?
if (!user) {
throw new AppError('Incorrect login/password combination.', 200);
throw new AppError(failedLoginMessage.message, failedLoginMessage.statusCode);
}
// user.password -> senha criptografada
@@ -37,7 +39,7 @@ class AuthenticateUserService {
const passwordMatched = await compare(password, user.password);
if (!passwordMatched) {
throw new AppError('Incorrect login/password combination.', 200);
throw new AppError(failedLoginMessage.message, failedLoginMessage.statusCode);
}
// usuário autenticado

View File

@@ -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

View File

@@ -8,12 +8,12 @@ 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 },
});
if (!user) {
throw new AppError('User does not exist.');
throw new AppError('Usuário não existe.');
}
return user;

View File

@@ -0,0 +1,22 @@
import { getRepository } from 'typeorm';
import AppError from '../errors/AppError';
import CarModels from '../models/CarModels';
class GetCarModelsService {
public async execute(): Promise<CarModels[]> {
const carModelsRepository = getRepository(CarModels);
const carModels = await carModelsRepository.find();
if (!carModels) {
// carModels, fazer no front um tratamento para isso
throw new AppError('Não há modelos de carro cadastrados.');
};
return carModels;
}
}
export default GetCarModelsService;

View File

@@ -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);