mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-07 18:55:42 +00:00
Initial commit of edr-passenger-api alpha version
This commit is contained in:
@@ -1,34 +1,15 @@
|
||||
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";
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { PrismaService } from '../../common/prisma.service';
|
||||
import { CreateStationDto } from './stations.dto';
|
||||
|
||||
@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;
|
||||
constructor(private prisma: PrismaService) {}
|
||||
findAll() { return this.prisma.station.findMany({ orderBy: { name: 'asc' } }); }
|
||||
async findOne(id: string) {
|
||||
const s = await this.prisma.station.findUnique({ where: { id } });
|
||||
if (!s) throw new NotFoundException('Station not found');
|
||||
return s;
|
||||
}
|
||||
create(dto: CreateStationDto) { return this.prisma.station.create({ data: dto }); }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user