mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-30 12:18:11 +00:00
chore: fmt
This commit is contained in:
@@ -1,17 +1,17 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||
import { TypeOrmModule, TypeOrmModuleOptions } from '@nestjs/typeorm';
|
||||
import { Module } from "@nestjs/common";
|
||||
import { ConfigModule, ConfigService } from "@nestjs/config";
|
||||
import { TypeOrmModule, TypeOrmModuleOptions } from "@nestjs/typeorm";
|
||||
|
||||
import appConfig from './config/app.config';
|
||||
import databaseConfig from './config/database.config';
|
||||
import appConfig from "./config/app.config";
|
||||
import databaseConfig from "./config/database.config";
|
||||
|
||||
import { TicketsModule } from './modules/tickets/tickets.module';
|
||||
import { SchedulesModule } from './modules/schedules/schedules.module';
|
||||
import { PassengersModule } from './modules/passengers/passengers.module';
|
||||
import { SeatsModule } from './modules/seats/seats.module';
|
||||
import { StationsModule } from './modules/stations/stations.module';
|
||||
import { PaymentsModule } from './modules/payments/payments.module';
|
||||
import { NotificationsModule } from './modules/notifications/notifications.module';
|
||||
import { TicketsModule } from "./modules/tickets/tickets.module";
|
||||
import { SchedulesModule } from "./modules/schedules/schedules.module";
|
||||
import { PassengersModule } from "./modules/passengers/passengers.module";
|
||||
import { SeatsModule } from "./modules/seats/seats.module";
|
||||
import { StationsModule } from "./modules/stations/stations.module";
|
||||
import { PaymentsModule } from "./modules/payments/payments.module";
|
||||
import { NotificationsModule } from "./modules/notifications/notifications.module";
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
@@ -22,7 +22,7 @@ import { NotificationsModule } from './modules/notifications/notifications.modul
|
||||
TypeOrmModule.forRootAsync({
|
||||
inject: [ConfigService],
|
||||
useFactory: (config: ConfigService): TypeOrmModuleOptions =>
|
||||
config.get<TypeOrmModuleOptions>('database')!,
|
||||
config.get<TypeOrmModuleOptions>("database")!,
|
||||
}),
|
||||
TicketsModule,
|
||||
SchedulesModule,
|
||||
|
||||
@@ -1 +1 @@
|
||||
export { HttpExceptionFilter } from '@edr/api-common';
|
||||
export { HttpExceptionFilter } from "@edr/api-common";
|
||||
|
||||
@@ -1 +1 @@
|
||||
export { ResponseTransformInterceptor } from '@edr/api-common';
|
||||
export { ResponseTransformInterceptor } from "@edr/api-common";
|
||||
|
||||
@@ -1 +1 @@
|
||||
export { createValidationPipe } from '@edr/api-common';
|
||||
export { createValidationPipe } from "@edr/api-common";
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { registerAs } from '@nestjs/config';
|
||||
import { registerAs } from "@nestjs/config";
|
||||
|
||||
export default registerAs('app', () => ({
|
||||
env: process.env.NODE_ENV ?? 'development',
|
||||
port: parseInt(process.env.PORT ?? '3002', 10),
|
||||
apiPrefix: 'api',
|
||||
export default registerAs("app", () => ({
|
||||
env: process.env.NODE_ENV ?? "development",
|
||||
port: parseInt(process.env.PORT ?? "3002", 10),
|
||||
apiPrefix: "api",
|
||||
}));
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
import { registerAs } from '@nestjs/config';
|
||||
import { TypeOrmModuleOptions } from '@nestjs/typeorm';
|
||||
import { registerAs } from "@nestjs/config";
|
||||
import { TypeOrmModuleOptions } from "@nestjs/typeorm";
|
||||
|
||||
export default registerAs('database', (): TypeOrmModuleOptions => ({
|
||||
type: 'postgres',
|
||||
host: process.env.DB_HOST ?? 'localhost',
|
||||
port: parseInt(process.env.DB_PORT ?? '5434', 10),
|
||||
username: process.env.DB_USER ?? 'postgres',
|
||||
password: process.env.DB_PASSWORD ?? '',
|
||||
database: process.env.DB_NAME ?? 'edr_passenger',
|
||||
entities: [__dirname + '/../**/*.entity.{ts,js}'],
|
||||
migrations: [__dirname + '/../../migrations/*.{ts,js}'],
|
||||
synchronize: process.env.NODE_ENV === 'development',
|
||||
logging: process.env.NODE_ENV === 'development',
|
||||
}));
|
||||
export default registerAs(
|
||||
"database",
|
||||
(): TypeOrmModuleOptions => ({
|
||||
type: "postgres",
|
||||
host: process.env.DB_HOST ?? "localhost",
|
||||
port: parseInt(process.env.DB_PORT ?? "5434", 10),
|
||||
username: process.env.DB_USER ?? "postgres",
|
||||
password: process.env.DB_PASSWORD ?? "",
|
||||
database: process.env.DB_NAME ?? "edr_passenger",
|
||||
entities: [__dirname + "/../**/*.entity.{ts,js}"],
|
||||
migrations: [__dirname + "/../../migrations/*.{ts,js}"],
|
||||
synchronize: process.env.NODE_ENV === "development",
|
||||
logging: process.env.NODE_ENV === "development",
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -1,28 +1,32 @@
|
||||
import 'reflect-metadata';
|
||||
import { NestFactory } from '@nestjs/core';
|
||||
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
|
||||
import { HttpExceptionFilter, ResponseTransformInterceptor, createValidationPipe } from '@edr/api-common';
|
||||
import "reflect-metadata";
|
||||
import { NestFactory } from "@nestjs/core";
|
||||
import { DocumentBuilder, SwaggerModule } from "@nestjs/swagger";
|
||||
import {
|
||||
HttpExceptionFilter,
|
||||
ResponseTransformInterceptor,
|
||||
createValidationPipe,
|
||||
} from "@edr/api-common";
|
||||
|
||||
import { AppModule } from './app.module';
|
||||
import { AppModule } from "./app.module";
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create(AppModule, { cors: true });
|
||||
|
||||
app.setGlobalPrefix('api');
|
||||
app.setGlobalPrefix("api");
|
||||
app.useGlobalPipes(createValidationPipe());
|
||||
app.useGlobalFilters(new HttpExceptionFilter());
|
||||
app.useGlobalInterceptors(new ResponseTransformInterceptor());
|
||||
|
||||
const config = new DocumentBuilder()
|
||||
.setTitle('EDR Passenger API')
|
||||
.setDescription('API for the EDR Passenger Management application')
|
||||
.setVersion('0.1.0')
|
||||
.setTitle("EDR Passenger API")
|
||||
.setDescription("API for the EDR Passenger Management application")
|
||||
.setVersion("0.1.0")
|
||||
.addBearerAuth()
|
||||
.build();
|
||||
const document = SwaggerModule.createDocument(app, config);
|
||||
SwaggerModule.setup('api/docs', app, document);
|
||||
SwaggerModule.setup("api/docs", app, document);
|
||||
|
||||
const port = parseInt(process.env.PORT ?? '3002', 10);
|
||||
const port = parseInt(process.env.PORT ?? "3002", 10);
|
||||
await app.listen(port);
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`[passenger-api] listening on http://localhost:${port}`);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { Module } from "@nestjs/common";
|
||||
|
||||
import { NotificationsService } from './notifications.service';
|
||||
import { NotificationsService } from "./notifications.service";
|
||||
|
||||
@Module({
|
||||
providers: [NotificationsService],
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
import { Injectable, Logger } from "@nestjs/common";
|
||||
|
||||
@Injectable()
|
||||
export class NotificationsService {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { IsDateString, IsEmail, IsOptional, IsString } from 'class-validator';
|
||||
import { IsDateString, IsEmail, IsOptional, IsString } from "class-validator";
|
||||
|
||||
export class CreatePassengerDto {
|
||||
@IsString()
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
import { BaseEntity } from '@edr/api-common';
|
||||
import { Column, Entity } from 'typeorm';
|
||||
import { BaseEntity } from "@edr/api-common";
|
||||
import { Column, Entity } from "typeorm";
|
||||
|
||||
@Entity({ name: 'passengers' })
|
||||
@Entity({ name: "passengers" })
|
||||
export class Passenger extends BaseEntity {
|
||||
@Column({ name: 'full_name', type: 'varchar', length: 256 })
|
||||
@Column({ name: "full_name", type: "varchar", length: 256 })
|
||||
fullName!: string;
|
||||
|
||||
@Column({ name: 'email', type: 'varchar', length: 256, unique: true })
|
||||
@Column({ name: "email", type: "varchar", length: 256, unique: true })
|
||||
email!: string;
|
||||
|
||||
@Column({ name: 'phone', type: 'varchar', length: 32 })
|
||||
@Column({ name: "phone", type: "varchar", length: 32 })
|
||||
phone!: string;
|
||||
|
||||
@Column({ name: 'national_id', type: 'varchar', length: 64, nullable: true })
|
||||
@Column({ name: "national_id", type: "varchar", length: 64, nullable: true })
|
||||
nationalId?: string | null;
|
||||
|
||||
@Column({ name: 'date_of_birth', type: 'date', nullable: true })
|
||||
@Column({ name: "date_of_birth", type: "date", nullable: true })
|
||||
dateOfBirth?: string | null;
|
||||
}
|
||||
|
||||
@@ -1,30 +1,37 @@
|
||||
import { Body, Controller, Get, Param, ParseUUIDPipe, Post } from '@nestjs/common';
|
||||
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Get,
|
||||
Param,
|
||||
ParseUUIDPipe,
|
||||
Post,
|
||||
} from "@nestjs/common";
|
||||
import { ApiOperation, ApiTags } from "@nestjs/swagger";
|
||||
|
||||
import { CreatePassengerDto } from './dto/create-passenger.dto';
|
||||
import { PassengersService } from './passengers.service';
|
||||
import { CreatePassengerDto } from "./dto/create-passenger.dto";
|
||||
import { PassengersService } from "./passengers.service";
|
||||
|
||||
@ApiTags('passengers')
|
||||
@ApiTags("passengers")
|
||||
// @UseGuards(JwtAuthGuard) — TODO: integrate @edr/auth
|
||||
@Controller('passengers')
|
||||
@Controller("passengers")
|
||||
export class PassengersController {
|
||||
constructor(private readonly passengersService: PassengersService) {}
|
||||
|
||||
@Post()
|
||||
@ApiOperation({ summary: 'Register a new passenger' })
|
||||
@ApiOperation({ summary: "Register a new passenger" })
|
||||
create(@Body() dto: CreatePassengerDto) {
|
||||
return this.passengersService.create(dto);
|
||||
}
|
||||
|
||||
@Get()
|
||||
@ApiOperation({ summary: 'List all passengers' })
|
||||
@ApiOperation({ summary: "List all passengers" })
|
||||
findAll() {
|
||||
return this.passengersService.findAll();
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
@ApiOperation({ summary: 'Get a passenger by ID' })
|
||||
findOne(@Param('id', ParseUUIDPipe) id: string) {
|
||||
@Get(":id")
|
||||
@ApiOperation({ summary: "Get a passenger by ID" })
|
||||
findOne(@Param("id", ParseUUIDPipe) id: string) {
|
||||
return this.passengersService.findById(id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { Module } from "@nestjs/common";
|
||||
import { TypeOrmModule } from "@nestjs/typeorm";
|
||||
|
||||
import { Passenger } from './entities/passenger.entity';
|
||||
import { PassengersController } from './passengers.controller';
|
||||
import { PassengersRepository } from './passengers.repository';
|
||||
import { PassengersService } from './passengers.service';
|
||||
import { Passenger } from "./entities/passenger.entity";
|
||||
import { PassengersController } from "./passengers.controller";
|
||||
import { PassengersRepository } from "./passengers.repository";
|
||||
import { PassengersService } from "./passengers.service";
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([Passenger])],
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { BaseRepository } from '@edr/api-common';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { BaseRepository } from "@edr/api-common";
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { InjectRepository } from "@nestjs/typeorm";
|
||||
import { Repository } from "typeorm";
|
||||
|
||||
import { Passenger } from './entities/passenger.entity';
|
||||
import { Passenger } from "./entities/passenger.entity";
|
||||
|
||||
@Injectable()
|
||||
export class PassengersRepository extends BaseRepository<Passenger> {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { Injectable, NotFoundException } from "@nestjs/common";
|
||||
|
||||
import { CreatePassengerDto } from './dto/create-passenger.dto';
|
||||
import { Passenger } from './entities/passenger.entity';
|
||||
import { PassengersRepository } from './passengers.repository';
|
||||
import { CreatePassengerDto } from "./dto/create-passenger.dto";
|
||||
import { Passenger } from "./entities/passenger.entity";
|
||||
import { PassengersRepository } from "./passengers.repository";
|
||||
|
||||
@Injectable()
|
||||
export class PassengersService {
|
||||
@@ -15,7 +15,7 @@ export class PassengersService {
|
||||
|
||||
/** List every passenger (alphabetical). */
|
||||
findAll(): Promise<Passenger[]> {
|
||||
return this.passengersRepository.findAll({ order: { fullName: 'ASC' } });
|
||||
return this.passengersRepository.findAll({ order: { fullName: "ASC" } });
|
||||
}
|
||||
|
||||
/** Get a single passenger by ID. */
|
||||
|
||||
@@ -1,32 +1,37 @@
|
||||
import { BaseEntity } from '@edr/api-common';
|
||||
import { Passenger } from '@edr/types';
|
||||
import { Column, Entity } from 'typeorm';
|
||||
import { BaseEntity } from "@edr/api-common";
|
||||
import { Passenger } from "@edr/types";
|
||||
import { Column, Entity } from "typeorm";
|
||||
|
||||
@Entity({ name: 'payments' })
|
||||
@Entity({ name: "payments" })
|
||||
export class Payment extends BaseEntity {
|
||||
@Column({ name: 'ticket_id', type: 'uuid' })
|
||||
@Column({ name: "ticket_id", type: "uuid" })
|
||||
ticketId!: string;
|
||||
|
||||
@Column({ name: 'amount', type: 'numeric', precision: 10, scale: 2 })
|
||||
@Column({ name: "amount", type: "numeric", precision: 10, scale: 2 })
|
||||
amount!: number;
|
||||
|
||||
@Column({ name: 'currency', type: 'varchar', length: 8, default: 'ETB' })
|
||||
@Column({ name: "currency", type: "varchar", length: 8, default: "ETB" })
|
||||
currency!: string;
|
||||
|
||||
@Column({
|
||||
name: 'status',
|
||||
type: 'enum',
|
||||
name: "status",
|
||||
type: "enum",
|
||||
enum: Passenger.PaymentStatus,
|
||||
default: Passenger.PaymentStatus.Pending,
|
||||
})
|
||||
status!: Passenger.PaymentStatus;
|
||||
|
||||
@Column({ name: 'provider', type: 'varchar', length: 64 })
|
||||
@Column({ name: "provider", type: "varchar", length: 64 })
|
||||
provider!: string;
|
||||
|
||||
@Column({ name: 'provider_transaction_id', type: 'varchar', length: 256, nullable: true })
|
||||
@Column({
|
||||
name: "provider_transaction_id",
|
||||
type: "varchar",
|
||||
length: 256,
|
||||
nullable: true,
|
||||
})
|
||||
providerTransactionId?: string | null;
|
||||
|
||||
@Column({ name: 'paid_at', type: 'timestamptz', nullable: true })
|
||||
@Column({ name: "paid_at", type: "timestamptz", nullable: true })
|
||||
paidAt?: Date | null;
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
import { Controller, Get, Param, ParseUUIDPipe } from '@nestjs/common';
|
||||
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||
import { Controller, Get, Param, ParseUUIDPipe } from "@nestjs/common";
|
||||
import { ApiOperation, ApiTags } from "@nestjs/swagger";
|
||||
|
||||
import { PaymentsService } from './payments.service';
|
||||
import { PaymentsService } from "./payments.service";
|
||||
|
||||
@ApiTags('payments')
|
||||
@ApiTags("payments")
|
||||
// @UseGuards(JwtAuthGuard) — TODO: integrate @edr/auth
|
||||
@Controller('payments')
|
||||
@Controller("payments")
|
||||
export class PaymentsController {
|
||||
constructor(private readonly paymentsService: PaymentsService) {}
|
||||
|
||||
@Get('ticket/:ticketId')
|
||||
@ApiOperation({ summary: 'List payments for a ticket' })
|
||||
findByTicket(@Param('ticketId', ParseUUIDPipe) ticketId: string) {
|
||||
@Get("ticket/:ticketId")
|
||||
@ApiOperation({ summary: "List payments for a ticket" })
|
||||
findByTicket(@Param("ticketId", ParseUUIDPipe) ticketId: string) {
|
||||
return this.paymentsService.findByTicket(ticketId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { Module } from "@nestjs/common";
|
||||
import { TypeOrmModule } from "@nestjs/typeorm";
|
||||
|
||||
import { Payment } from './entities/payment.entity';
|
||||
import { PaymentsController } from './payments.controller';
|
||||
import { PaymentsService } from './payments.service';
|
||||
import { Payment } from "./entities/payment.entity";
|
||||
import { PaymentsController } from "./payments.controller";
|
||||
import { PaymentsService } from "./payments.service";
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([Payment])],
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { InjectRepository } from "@nestjs/typeorm";
|
||||
import { Repository } from "typeorm";
|
||||
|
||||
import { Payment } from './entities/payment.entity';
|
||||
import { Payment } from "./entities/payment.entity";
|
||||
|
||||
@Injectable()
|
||||
export class PaymentsService {
|
||||
@@ -15,7 +15,7 @@ export class PaymentsService {
|
||||
findByTicket(ticketId: string): Promise<Payment[]> {
|
||||
return this.paymentsRepository.find({
|
||||
where: { ticketId },
|
||||
order: { createdAt: 'DESC' },
|
||||
order: { createdAt: "DESC" },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
import { Passenger } from '@edr/types';
|
||||
import { IsDateString, IsEnum, IsNumber, IsOptional, IsString, IsUUID, Min } from 'class-validator';
|
||||
import { Passenger } from "@edr/types";
|
||||
import {
|
||||
IsDateString,
|
||||
IsEnum,
|
||||
IsNumber,
|
||||
IsOptional,
|
||||
IsString,
|
||||
IsUUID,
|
||||
Min,
|
||||
} from "class-validator";
|
||||
|
||||
export class CreateScheduleDto {
|
||||
@IsString()
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
import { BaseEntity } from '@edr/api-common';
|
||||
import { Passenger } from '@edr/types';
|
||||
import { Column, Entity } from 'typeorm';
|
||||
import { BaseEntity } from "@edr/api-common";
|
||||
import { Passenger } from "@edr/types";
|
||||
import { Column, Entity } from "typeorm";
|
||||
|
||||
@Entity({ name: 'schedules' })
|
||||
@Entity({ name: "schedules" })
|
||||
export class Schedule extends BaseEntity {
|
||||
@Column({ name: 'train_code', type: 'varchar', length: 32 })
|
||||
@Column({ name: "train_code", type: "varchar", length: 32 })
|
||||
trainCode!: string;
|
||||
|
||||
@Column({ name: 'origin_station_id', type: 'uuid' })
|
||||
@Column({ name: "origin_station_id", type: "uuid" })
|
||||
originStationId!: string;
|
||||
|
||||
@Column({ name: 'destination_station_id', type: 'uuid' })
|
||||
@Column({ name: "destination_station_id", type: "uuid" })
|
||||
destinationStationId!: string;
|
||||
|
||||
@Column({ name: 'departure_time', type: 'timestamptz' })
|
||||
@Column({ name: "departure_time", type: "timestamptz" })
|
||||
departureTime!: Date;
|
||||
|
||||
@Column({ name: 'arrival_time', type: 'timestamptz' })
|
||||
@Column({ name: "arrival_time", type: "timestamptz" })
|
||||
arrivalTime!: Date;
|
||||
|
||||
@Column({
|
||||
name: 'status',
|
||||
type: 'enum',
|
||||
name: "status",
|
||||
type: "enum",
|
||||
enum: Passenger.ScheduleStatus,
|
||||
default: Passenger.ScheduleStatus.Scheduled,
|
||||
})
|
||||
status!: Passenger.ScheduleStatus;
|
||||
|
||||
@Column({ name: 'base_price', type: 'numeric', precision: 10, scale: 2 })
|
||||
@Column({ name: "base_price", type: "numeric", precision: 10, scale: 2 })
|
||||
basePrice!: number;
|
||||
}
|
||||
|
||||
@@ -1,30 +1,37 @@
|
||||
import { Body, Controller, Get, Param, ParseUUIDPipe, Post } from '@nestjs/common';
|
||||
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Get,
|
||||
Param,
|
||||
ParseUUIDPipe,
|
||||
Post,
|
||||
} from "@nestjs/common";
|
||||
import { ApiOperation, ApiTags } from "@nestjs/swagger";
|
||||
|
||||
import { CreateScheduleDto } from './dto/create-schedule.dto';
|
||||
import { SchedulesService } from './schedules.service';
|
||||
import { CreateScheduleDto } from "./dto/create-schedule.dto";
|
||||
import { SchedulesService } from "./schedules.service";
|
||||
|
||||
@ApiTags('schedules')
|
||||
@ApiTags("schedules")
|
||||
// @UseGuards(JwtAuthGuard) — TODO: integrate @edr/auth
|
||||
@Controller('schedules')
|
||||
@Controller("schedules")
|
||||
export class SchedulesController {
|
||||
constructor(private readonly schedulesService: SchedulesService) {}
|
||||
|
||||
@Post()
|
||||
@ApiOperation({ summary: 'Publish a new train schedule' })
|
||||
@ApiOperation({ summary: "Publish a new train schedule" })
|
||||
create(@Body() dto: CreateScheduleDto) {
|
||||
return this.schedulesService.create(dto);
|
||||
}
|
||||
|
||||
@Get()
|
||||
@ApiOperation({ summary: 'List all schedules' })
|
||||
@ApiOperation({ summary: "List all schedules" })
|
||||
findAll() {
|
||||
return this.schedulesService.findAll();
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
@ApiOperation({ summary: 'Get a schedule by ID' })
|
||||
findOne(@Param('id', ParseUUIDPipe) id: string) {
|
||||
@Get(":id")
|
||||
@ApiOperation({ summary: "Get a schedule by ID" })
|
||||
findOne(@Param("id", ParseUUIDPipe) id: string) {
|
||||
return this.schedulesService.findById(id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { Module } from "@nestjs/common";
|
||||
import { TypeOrmModule } from "@nestjs/typeorm";
|
||||
|
||||
import { Schedule } from './entities/schedule.entity';
|
||||
import { SchedulesController } from './schedules.controller';
|
||||
import { SchedulesRepository } from './schedules.repository';
|
||||
import { SchedulesService } from './schedules.service';
|
||||
import { Schedule } from "./entities/schedule.entity";
|
||||
import { SchedulesController } from "./schedules.controller";
|
||||
import { SchedulesRepository } from "./schedules.repository";
|
||||
import { SchedulesService } from "./schedules.service";
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([Schedule])],
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { BaseRepository } from '@edr/api-common';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { BaseRepository } from "@edr/api-common";
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { InjectRepository } from "@nestjs/typeorm";
|
||||
import { Repository } from "typeorm";
|
||||
|
||||
import { Schedule } from './entities/schedule.entity';
|
||||
import { Schedule } from "./entities/schedule.entity";
|
||||
|
||||
@Injectable()
|
||||
export class SchedulesRepository extends BaseRepository<Schedule> {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { Injectable, NotFoundException } from "@nestjs/common";
|
||||
|
||||
import { CreateScheduleDto } from './dto/create-schedule.dto';
|
||||
import { Schedule } from './entities/schedule.entity';
|
||||
import { SchedulesRepository } from './schedules.repository';
|
||||
import { CreateScheduleDto } from "./dto/create-schedule.dto";
|
||||
import { Schedule } from "./entities/schedule.entity";
|
||||
import { SchedulesRepository } from "./schedules.repository";
|
||||
|
||||
@Injectable()
|
||||
export class SchedulesService {
|
||||
@@ -19,7 +19,9 @@ export class SchedulesService {
|
||||
|
||||
/** List every published schedule. */
|
||||
findAll(): Promise<Schedule[]> {
|
||||
return this.schedulesRepository.findAll({ order: { departureTime: 'ASC' } });
|
||||
return this.schedulesRepository.findAll({
|
||||
order: { departureTime: "ASC" },
|
||||
});
|
||||
}
|
||||
|
||||
/** Get a single schedule by ID. */
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
import { BaseEntity } from '@edr/api-common';
|
||||
import { Passenger } from '@edr/types';
|
||||
import { Column, Entity } from 'typeorm';
|
||||
import { BaseEntity } from "@edr/api-common";
|
||||
import { Passenger } from "@edr/types";
|
||||
import { Column, Entity } from "typeorm";
|
||||
|
||||
@Entity({ name: 'seats' })
|
||||
@Entity({ name: "seats" })
|
||||
export class Seat extends BaseEntity {
|
||||
@Column({ name: 'schedule_id', type: 'uuid' })
|
||||
@Column({ name: "schedule_id", type: "uuid" })
|
||||
scheduleId!: string;
|
||||
|
||||
@Column({ name: 'seat_number', type: 'varchar', length: 16 })
|
||||
@Column({ name: "seat_number", type: "varchar", length: 16 })
|
||||
seatNumber!: string;
|
||||
|
||||
@Column({ name: 'seat_class', type: 'enum', enum: Passenger.SeatClass })
|
||||
@Column({ name: "seat_class", type: "enum", enum: Passenger.SeatClass })
|
||||
seatClass!: Passenger.SeatClass;
|
||||
|
||||
@Column({
|
||||
name: 'status',
|
||||
type: 'enum',
|
||||
name: "status",
|
||||
type: "enum",
|
||||
enum: Passenger.SeatStatus,
|
||||
default: Passenger.SeatStatus.Available,
|
||||
})
|
||||
status!: Passenger.SeatStatus;
|
||||
|
||||
@Column({ name: 'price', type: 'numeric', precision: 10, scale: 2 })
|
||||
@Column({ name: "price", type: "numeric", precision: 10, scale: 2 })
|
||||
price!: number;
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
import { Controller, Get, Param, ParseUUIDPipe } from '@nestjs/common';
|
||||
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||
import { Controller, Get, Param, ParseUUIDPipe } from "@nestjs/common";
|
||||
import { ApiOperation, ApiTags } from "@nestjs/swagger";
|
||||
|
||||
import { SeatsService } from './seats.service';
|
||||
import { SeatsService } from "./seats.service";
|
||||
|
||||
@ApiTags('seats')
|
||||
@ApiTags("seats")
|
||||
// @UseGuards(JwtAuthGuard) — TODO: integrate @edr/auth
|
||||
@Controller('seats')
|
||||
@Controller("seats")
|
||||
export class SeatsController {
|
||||
constructor(private readonly seatsService: SeatsService) {}
|
||||
|
||||
@Get('schedule/:scheduleId')
|
||||
@ApiOperation({ summary: 'List seats for a schedule' })
|
||||
findBySchedule(@Param('scheduleId', ParseUUIDPipe) scheduleId: string) {
|
||||
@Get("schedule/:scheduleId")
|
||||
@ApiOperation({ summary: "List seats for a schedule" })
|
||||
findBySchedule(@Param("scheduleId", ParseUUIDPipe) scheduleId: string) {
|
||||
return this.seatsService.findBySchedule(scheduleId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { Module } from "@nestjs/common";
|
||||
import { TypeOrmModule } from "@nestjs/typeorm";
|
||||
|
||||
import { Seat } from './entities/seat.entity';
|
||||
import { SeatsController } from './seats.controller';
|
||||
import { SeatsService } from './seats.service';
|
||||
import { Seat } from "./entities/seat.entity";
|
||||
import { SeatsController } from "./seats.controller";
|
||||
import { SeatsService } from "./seats.service";
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([Seat])],
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { InjectRepository } from "@nestjs/typeorm";
|
||||
import { Repository } from "typeorm";
|
||||
|
||||
import { Seat } from './entities/seat.entity';
|
||||
import { Seat } from "./entities/seat.entity";
|
||||
|
||||
@Injectable()
|
||||
export class SeatsService {
|
||||
@@ -15,7 +15,7 @@ export class SeatsService {
|
||||
findBySchedule(scheduleId: string): Promise<Seat[]> {
|
||||
return this.seatsRepository.find({
|
||||
where: { scheduleId },
|
||||
order: { seatNumber: 'ASC' },
|
||||
order: { seatNumber: "ASC" },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { IsNumber, IsOptional, IsString } from 'class-validator';
|
||||
import { IsNumber, IsOptional, IsString } from "class-validator";
|
||||
|
||||
export class CreateStationDto {
|
||||
@IsString()
|
||||
|
||||
@@ -1,23 +1,35 @@
|
||||
import { BaseEntity } from '@edr/api-common';
|
||||
import { Column, Entity } from 'typeorm';
|
||||
import { BaseEntity } from "@edr/api-common";
|
||||
import { Column, Entity } from "typeorm";
|
||||
|
||||
@Entity({ name: 'stations' })
|
||||
@Entity({ name: "stations" })
|
||||
export class Station extends BaseEntity {
|
||||
@Column({ name: 'code', type: 'varchar', length: 16, unique: true })
|
||||
@Column({ name: "code", type: "varchar", length: 16, unique: true })
|
||||
code!: string;
|
||||
|
||||
@Column({ name: 'name', type: 'varchar', length: 128 })
|
||||
@Column({ name: "name", type: "varchar", length: 128 })
|
||||
name!: string;
|
||||
|
||||
@Column({ name: 'city', type: 'varchar', length: 128 })
|
||||
@Column({ name: "city", type: "varchar", length: 128 })
|
||||
city!: string;
|
||||
|
||||
@Column({ name: 'country', type: 'varchar', length: 64 })
|
||||
@Column({ name: "country", type: "varchar", length: 64 })
|
||||
country!: string;
|
||||
|
||||
@Column({ name: 'latitude', type: 'numeric', precision: 9, scale: 6, nullable: true })
|
||||
@Column({
|
||||
name: "latitude",
|
||||
type: "numeric",
|
||||
precision: 9,
|
||||
scale: 6,
|
||||
nullable: true,
|
||||
})
|
||||
latitude?: number | null;
|
||||
|
||||
@Column({ name: 'longitude', type: 'numeric', precision: 9, scale: 6, nullable: true })
|
||||
@Column({
|
||||
name: "longitude",
|
||||
type: "numeric",
|
||||
precision: 9,
|
||||
scale: 6,
|
||||
nullable: true,
|
||||
})
|
||||
longitude?: number | null;
|
||||
}
|
||||
|
||||
@@ -1,30 +1,37 @@
|
||||
import { Body, Controller, Get, Param, ParseUUIDPipe, Post } from '@nestjs/common';
|
||||
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Get,
|
||||
Param,
|
||||
ParseUUIDPipe,
|
||||
Post,
|
||||
} from "@nestjs/common";
|
||||
import { ApiOperation, ApiTags } from "@nestjs/swagger";
|
||||
|
||||
import { CreateStationDto } from './dto/create-station.dto';
|
||||
import { StationsService } from './stations.service';
|
||||
import { CreateStationDto } from "./dto/create-station.dto";
|
||||
import { StationsService } from "./stations.service";
|
||||
|
||||
@ApiTags('stations')
|
||||
@ApiTags("stations")
|
||||
// @UseGuards(JwtAuthGuard) — TODO: integrate @edr/auth
|
||||
@Controller('stations')
|
||||
@Controller("stations")
|
||||
export class StationsController {
|
||||
constructor(private readonly stationsService: StationsService) {}
|
||||
|
||||
@Post()
|
||||
@ApiOperation({ summary: 'Register a new station' })
|
||||
@ApiOperation({ summary: "Register a new station" })
|
||||
create(@Body() dto: CreateStationDto) {
|
||||
return this.stationsService.create(dto);
|
||||
}
|
||||
|
||||
@Get()
|
||||
@ApiOperation({ summary: 'List all stations' })
|
||||
@ApiOperation({ summary: "List all stations" })
|
||||
findAll() {
|
||||
return this.stationsService.findAll();
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
@ApiOperation({ summary: 'Get a station by ID' })
|
||||
findOne(@Param('id', ParseUUIDPipe) id: string) {
|
||||
@Get(":id")
|
||||
@ApiOperation({ summary: "Get a station by ID" })
|
||||
findOne(@Param("id", ParseUUIDPipe) id: string) {
|
||||
return this.stationsService.findById(id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { Module } from "@nestjs/common";
|
||||
import { TypeOrmModule } from "@nestjs/typeorm";
|
||||
|
||||
import { Station } from './entities/station.entity';
|
||||
import { StationsController } from './stations.controller';
|
||||
import { StationsService } from './stations.service';
|
||||
import { Station } from "./entities/station.entity";
|
||||
import { StationsController } from "./stations.controller";
|
||||
import { StationsService } from "./stations.service";
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([Station])],
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
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 { CreateStationDto } from "./dto/create-station.dto";
|
||||
import { Station } from "./entities/station.entity";
|
||||
|
||||
@Injectable()
|
||||
export class StationsService {
|
||||
@@ -20,7 +20,7 @@ export class StationsService {
|
||||
|
||||
/** List every station (alphabetical). */
|
||||
findAll(): Promise<Station[]> {
|
||||
return this.stationsRepository.find({ order: { name: 'ASC' } });
|
||||
return this.stationsRepository.find({ order: { name: "ASC" } });
|
||||
}
|
||||
|
||||
/** Get a single station by ID. */
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
import { Passenger } from '@edr/types';
|
||||
import { IsDateString, IsEnum, IsNumber, IsOptional, IsString, IsUUID, Min } from 'class-validator';
|
||||
import { Passenger } from "@edr/types";
|
||||
import {
|
||||
IsDateString,
|
||||
IsEnum,
|
||||
IsNumber,
|
||||
IsOptional,
|
||||
IsString,
|
||||
IsUUID,
|
||||
Min,
|
||||
} from "class-validator";
|
||||
|
||||
export class CreateTicketDto {
|
||||
@IsString()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Passenger } from '@edr/types';
|
||||
import { Type } from 'class-transformer';
|
||||
import { IsEnum, IsInt, IsOptional, IsUUID, Min } from 'class-validator';
|
||||
import { Passenger } from "@edr/types";
|
||||
import { Type } from "class-transformer";
|
||||
import { IsEnum, IsInt, IsOptional, IsUUID, Min } from "class-validator";
|
||||
|
||||
export class FilterTicketDto {
|
||||
@IsOptional()
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
import { BaseEntity } from '@edr/api-common';
|
||||
import { Passenger } from '@edr/types';
|
||||
import { Column, Entity } from 'typeorm';
|
||||
import { BaseEntity } from "@edr/api-common";
|
||||
import { Passenger } from "@edr/types";
|
||||
import { Column, Entity } from "typeorm";
|
||||
|
||||
@Entity({ name: 'tickets' })
|
||||
@Entity({ name: "tickets" })
|
||||
export class Ticket extends BaseEntity {
|
||||
@Column({ name: 'reference', type: 'varchar', length: 64, unique: true })
|
||||
@Column({ name: "reference", type: "varchar", length: 64, unique: true })
|
||||
reference!: string;
|
||||
|
||||
@Column({ name: 'passenger_id', type: 'uuid' })
|
||||
@Column({ name: "passenger_id", type: "uuid" })
|
||||
passengerId!: string;
|
||||
|
||||
@Column({ name: 'schedule_id', type: 'uuid' })
|
||||
@Column({ name: "schedule_id", type: "uuid" })
|
||||
scheduleId!: string;
|
||||
|
||||
@Column({ name: 'seat_id', type: 'uuid' })
|
||||
@Column({ name: "seat_id", type: "uuid" })
|
||||
seatId!: string;
|
||||
|
||||
@Column({
|
||||
name: 'status',
|
||||
type: 'enum',
|
||||
name: "status",
|
||||
type: "enum",
|
||||
enum: Passenger.TicketStatus,
|
||||
default: Passenger.TicketStatus.Reserved,
|
||||
})
|
||||
status!: Passenger.TicketStatus;
|
||||
|
||||
@Column({ name: 'price_paid', type: 'numeric', precision: 10, scale: 2 })
|
||||
@Column({ name: "price_paid", type: "numeric", precision: 10, scale: 2 })
|
||||
pricePaid!: number;
|
||||
|
||||
@Column({ name: 'issued_at', type: 'timestamptz' })
|
||||
@Column({ name: "issued_at", type: "timestamptz" })
|
||||
issuedAt!: Date;
|
||||
}
|
||||
|
||||
@@ -1,38 +1,48 @@
|
||||
import { Body, Controller, Delete, Get, HttpCode, Param, ParseUUIDPipe, Post, Query } from '@nestjs/common';
|
||||
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Delete,
|
||||
Get,
|
||||
HttpCode,
|
||||
Param,
|
||||
ParseUUIDPipe,
|
||||
Post,
|
||||
Query,
|
||||
} from "@nestjs/common";
|
||||
import { ApiOperation, ApiTags } from "@nestjs/swagger";
|
||||
|
||||
import { CreateTicketDto } from './dto/create-ticket.dto';
|
||||
import { FilterTicketDto } from './dto/filter-ticket.dto';
|
||||
import { TicketsService } from './tickets.service';
|
||||
import { CreateTicketDto } from "./dto/create-ticket.dto";
|
||||
import { FilterTicketDto } from "./dto/filter-ticket.dto";
|
||||
import { TicketsService } from "./tickets.service";
|
||||
|
||||
@ApiTags('tickets')
|
||||
@ApiTags("tickets")
|
||||
// @UseGuards(JwtAuthGuard) — TODO: integrate @edr/auth
|
||||
@Controller('tickets')
|
||||
@Controller("tickets")
|
||||
export class TicketsController {
|
||||
constructor(private readonly ticketsService: TicketsService) {}
|
||||
|
||||
@Post()
|
||||
@ApiOperation({ summary: 'Issue a new passenger ticket' })
|
||||
@ApiOperation({ summary: "Issue a new passenger ticket" })
|
||||
create(@Body() dto: CreateTicketDto) {
|
||||
return this.ticketsService.create(dto);
|
||||
}
|
||||
|
||||
@Get()
|
||||
@ApiOperation({ summary: 'List passenger tickets (paginated)' })
|
||||
@ApiOperation({ summary: "List passenger tickets (paginated)" })
|
||||
findAll(@Query() filter: FilterTicketDto) {
|
||||
return this.ticketsService.findAll(filter);
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
@ApiOperation({ summary: 'Get a ticket by ID' })
|
||||
findOne(@Param('id', ParseUUIDPipe) id: string) {
|
||||
@Get(":id")
|
||||
@ApiOperation({ summary: "Get a ticket by ID" })
|
||||
findOne(@Param("id", ParseUUIDPipe) id: string) {
|
||||
return this.ticketsService.findById(id);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
@Delete(":id")
|
||||
@HttpCode(204)
|
||||
@ApiOperation({ summary: 'Cancel a ticket' })
|
||||
cancel(@Param('id', ParseUUIDPipe) id: string) {
|
||||
@ApiOperation({ summary: "Cancel a ticket" })
|
||||
cancel(@Param("id", ParseUUIDPipe) id: string) {
|
||||
return this.ticketsService.cancel(id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { Module } from "@nestjs/common";
|
||||
import { TypeOrmModule } from "@nestjs/typeorm";
|
||||
|
||||
import { Ticket } from './entities/ticket.entity';
|
||||
import { TicketsController } from './tickets.controller';
|
||||
import { TicketsRepository } from './tickets.repository';
|
||||
import { TicketsService } from './tickets.service';
|
||||
import { Ticket } from "./entities/ticket.entity";
|
||||
import { TicketsController } from "./tickets.controller";
|
||||
import { TicketsRepository } from "./tickets.repository";
|
||||
import { TicketsService } from "./tickets.service";
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([Ticket])],
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { BaseRepository } from '@edr/api-common';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { BaseRepository } from "@edr/api-common";
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { InjectRepository } from "@nestjs/typeorm";
|
||||
import { Repository } from "typeorm";
|
||||
|
||||
import { Ticket } from './entities/ticket.entity';
|
||||
import { Ticket } from "./entities/ticket.entity";
|
||||
|
||||
@Injectable()
|
||||
export class TicketsRepository extends BaseRepository<Ticket> {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { Injectable, NotFoundException } from "@nestjs/common";
|
||||
|
||||
import { CreateTicketDto } from './dto/create-ticket.dto';
|
||||
import { FilterTicketDto } from './dto/filter-ticket.dto';
|
||||
import { Ticket } from './entities/ticket.entity';
|
||||
import { TicketsRepository } from './tickets.repository';
|
||||
import { CreateTicketDto } from "./dto/create-ticket.dto";
|
||||
import { FilterTicketDto } from "./dto/filter-ticket.dto";
|
||||
import { Ticket } from "./entities/ticket.entity";
|
||||
import { TicketsRepository } from "./tickets.repository";
|
||||
|
||||
@Injectable()
|
||||
export class TicketsService {
|
||||
@@ -18,7 +18,9 @@ export class TicketsService {
|
||||
}
|
||||
|
||||
/** Paginated list of tickets matching the filter. */
|
||||
async findAll(filter: FilterTicketDto): Promise<{ items: Ticket[]; total: number }> {
|
||||
async findAll(
|
||||
filter: FilterTicketDto,
|
||||
): Promise<{ items: Ticket[]; total: number }> {
|
||||
const page = filter.page ?? 1;
|
||||
const pageSize = filter.pageSize ?? 20;
|
||||
const [items, total] = await this.ticketsRepository.findAndCount({
|
||||
@@ -29,7 +31,7 @@ export class TicketsService {
|
||||
},
|
||||
skip: (page - 1) * pageSize,
|
||||
take: pageSize,
|
||||
order: { createdAt: 'DESC' },
|
||||
order: { createdAt: "DESC" },
|
||||
});
|
||||
return { items, total };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user