mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-26 18:42:49 +00:00
Project Initialization
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
|
||||
import { CreateScheduleDto } from './dto/create-schedule.dto';
|
||||
import { Schedule } from './entities/schedule.entity';
|
||||
import { SchedulesRepository } from './schedules.repository';
|
||||
|
||||
@Injectable()
|
||||
export class SchedulesService {
|
||||
constructor(private readonly schedulesRepository: SchedulesRepository) {}
|
||||
|
||||
/** Publish a new train schedule. */
|
||||
create(dto: CreateScheduleDto): Promise<Schedule> {
|
||||
return this.schedulesRepository.create({
|
||||
...dto,
|
||||
departureTime: new Date(dto.departureTime),
|
||||
arrivalTime: new Date(dto.arrivalTime),
|
||||
});
|
||||
}
|
||||
|
||||
/** List every published schedule. */
|
||||
findAll(): Promise<Schedule[]> {
|
||||
return this.schedulesRepository.findAll({ order: { departureTime: 'ASC' } });
|
||||
}
|
||||
|
||||
/** Get a single schedule by ID. */
|
||||
async findById(id: string): Promise<Schedule> {
|
||||
const schedule = await this.schedulesRepository.findById(id);
|
||||
if (!schedule) {
|
||||
throw new NotFoundException(`Schedule ${id} not found`);
|
||||
}
|
||||
return schedule;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user