Adicionando rota que retorna se usuário é status motorista

This commit is contained in:
Matheus Albino Brunhara
2022-06-20 17:27:25 -05:00
parent 9c59fe64de
commit 8d77f0dae5
3 changed files with 119 additions and 52 deletions

View File

@@ -0,0 +1,33 @@
import { getRepository } from 'typeorm';
import AppError from '../errors/AppError';
import User from '../models/User';
import Van from '../models/Van';
interface Request {
id_user: string;
}
class CheckIfUserHasVansService {
public async execute({ id_user }: Request): Promise<Boolean> {
const usersRepository = getRepository(User);
const vansRepository = getRepository(Van);
const user = await usersRepository.findOne({
where: { id_user },
});
if (!user) {
throw new AppError('O usuário informado não foi encontrado.', 404);
}
const vanExists = await vansRepository.findOne({
where: { user },
});
return !!vanExists
}
}
export default CheckIfUserHasVansService;