Adicionando rotas e lógica para Vans e Locadores de Vans
This commit is contained in:
23
src/services/FindVanService.ts
Normal file
23
src/services/FindVanService.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { getRepository } from 'typeorm';
|
||||
|
||||
import AppError from '../errors/AppError';
|
||||
|
||||
import Van from '../models/Van';
|
||||
|
||||
class FindVanService {
|
||||
public async execute(id_van: string): Promise<Van> {
|
||||
const vansRepository = getRepository(Van);
|
||||
|
||||
const van = await vansRepository.findOne({
|
||||
where: { id_van }
|
||||
});
|
||||
|
||||
if (!van) {
|
||||
throw new AppError('Van does not exist.');
|
||||
};
|
||||
|
||||
return van;
|
||||
}
|
||||
}
|
||||
|
||||
export default FindVanService;
|
||||
Reference in New Issue
Block a user