Project Initialization

This commit is contained in:
Muluhabt
2026-05-12 15:17:16 +03:00
parent 33fa742e8a
commit 3b8b6979db
259 changed files with 15962 additions and 0 deletions

View File

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