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,34 @@
import { Injectable, NotFoundException } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { CreateStationDto } from './dto/create-station.dto';
import { Station } from './entities/station.entity';
@Injectable()
export class StationsService {
constructor(
@InjectRepository(Station)
private readonly stationsRepository: Repository<Station>,
) {}
/** Register a new station. */
create(dto: CreateStationDto): Promise<Station> {
const entity = this.stationsRepository.create(dto);
return this.stationsRepository.save(entity);
}
/** List every station (alphabetical). */
findAll(): Promise<Station[]> {
return this.stationsRepository.find({ order: { name: 'ASC' } });
}
/** Get a single station by ID. */
async findById(id: string): Promise<Station> {
const station = await this.stationsRepository.findOne({ where: { id } });
if (!station) {
throw new NotFoundException(`Station ${id} not found`);
}
return station;
}
}