| 4 | |
| 5 | @Injectable() |
| 6 | export class BusService { |
| 7 | constructor(private readonly prismaService: PrismaService) {} |
| 8 | async getBusSchedule() { |
| 9 | return { |
| 10 | today: new Date(), |
| 11 | schedule: await this.prismaService.schedule.findMany({}), |
| 12 | }; |
| 13 | } |
| 14 | |
| 15 | async createBus(bus: any) { |
| 16 | try { |
| 17 | const busData = await this.prismaService.bus.findFirst({ |
| 18 | where: { |
| 19 | number: bus.number, |
| 20 | }, |
| 21 | }); |
| 22 | if (busData) { |
| 23 | throw new HttpException('Bus already exists', 400); |
| 24 | } else { |
| 25 | return this.prismaService.bus.create({ |
| 26 | data: { |
| 27 | ...bus, |
| 28 | }, |
| 29 | }); |
| 30 | } |
| 31 | } catch (error) { |
| 32 | throw new HttpException(error.message, error.status); |
| 33 | } |
| 34 | } |
| 35 | async getConductors() { |
| 36 | return this.prismaService.conductor.findMany({}); |
| 37 | } |
| 38 | async getConductorById(conductorId: string) { |
| 39 | const conductor = await this.prismaService.conductor.findFirst({ |
| 40 | where: { |
| 41 | id: conductorId, |
| 42 | }, |
| 43 | }); |
| 44 | if (!conductor) { |
| 45 | throw new HttpException('Conductor not found', 404); |
| 46 | } |
| 47 | return conductor; |
| 48 | } |
| 49 | async getContractors() { |
| 50 | return this.prismaService.contractor.findMany({}); |
| 51 | } |
| 52 | async getContractorById(contractorId: string) { |
| 53 | const contractor = await this.prismaService.contractor.findFirst({ |
| 54 | where: { |
| 55 | id: contractorId, |
| 56 | }, |
| 57 | }); |
| 58 | if (!contractor) { |
| 59 | throw new HttpException('Conductor not found', 404); |
| 60 | } |
| 61 | return contractor; |
| 62 | } |
| 63 | async createContractor(contractor: any) { |
nothing calls this directly
no outgoing calls
no test coverage detected