mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-26 18:42:49 +00:00
chore: fmt
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -52,11 +52,19 @@
|
||||
"typescript": "^5.5.4"
|
||||
},
|
||||
"jest": {
|
||||
"moduleFileExtensions": ["js", "json", "ts"],
|
||||
"moduleFileExtensions": [
|
||||
"js",
|
||||
"json",
|
||||
"ts"
|
||||
],
|
||||
"rootDir": "src",
|
||||
"testRegex": ".*\\.spec\\.ts$",
|
||||
"transform": { "^.+\\.(t|j)s$": "ts-jest" },
|
||||
"collectCoverageFrom": ["**/*.(t|j)s"],
|
||||
"transform": {
|
||||
"^.+\\.(t|j)s$": "ts-jest"
|
||||
},
|
||||
"collectCoverageFrom": [
|
||||
"**/*.(t|j)s"
|
||||
],
|
||||
"coverageDirectory": "../coverage",
|
||||
"testEnvironment": "node"
|
||||
}
|
||||
|
||||
@@ -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 { BookingsModule } from './modules/bookings/bookings.module';
|
||||
import { ConsignmentsModule } from './modules/consignments/consignments.module';
|
||||
import { TrainsModule } from './modules/trains/trains.module';
|
||||
import { CustomersModule } from './modules/customers/customers.module';
|
||||
import { TrackingModule } from './modules/tracking/tracking.module';
|
||||
import { BillingModule } from './modules/billing/billing.module';
|
||||
import { NotificationsModule } from './modules/notifications/notifications.module';
|
||||
import { BookingsModule } from "./modules/bookings/bookings.module";
|
||||
import { ConsignmentsModule } from "./modules/consignments/consignments.module";
|
||||
import { TrainsModule } from "./modules/trains/trains.module";
|
||||
import { CustomersModule } from "./modules/customers/customers.module";
|
||||
import { TrackingModule } from "./modules/tracking/tracking.module";
|
||||
import { BillingModule } from "./modules/billing/billing.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")!,
|
||||
}),
|
||||
BookingsModule,
|
||||
ConsignmentsModule,
|
||||
|
||||
@@ -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 ?? '3001', 10),
|
||||
apiPrefix: 'api',
|
||||
export default registerAs("app", () => ({
|
||||
env: process.env.NODE_ENV ?? "development",
|
||||
port: parseInt(process.env.PORT ?? "3001", 10),
|
||||
apiPrefix: "api",
|
||||
}));
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
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 ?? '5433', 10),
|
||||
username: process.env.DB_USER ?? 'postgres',
|
||||
password: process.env.DB_PASSWORD ?? '',
|
||||
database: process.env.DB_NAME ?? 'edr_freight',
|
||||
entities: [__dirname + '/../**/*.entity.{ts,js}'],
|
||||
migrations: [__dirname + '/../../migrations/*.{ts,js}'],
|
||||
// Never enable synchronize in production. Use migrations.
|
||||
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 ?? "5433", 10),
|
||||
username: process.env.DB_USER ?? "postgres",
|
||||
password: process.env.DB_PASSWORD ?? "",
|
||||
database: process.env.DB_NAME ?? "edr_freight",
|
||||
entities: [__dirname + "/../**/*.entity.{ts,js}"],
|
||||
migrations: [__dirname + "/../../migrations/*.{ts,js}"],
|
||||
// Never enable synchronize in production. Use migrations.
|
||||
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 Freight API')
|
||||
.setDescription('API for the EDR Freight Management application')
|
||||
.setVersion('0.1.0')
|
||||
.setTitle("EDR Freight API")
|
||||
.setDescription("API for the EDR Freight 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 ?? '3001', 10);
|
||||
const port = parseInt(process.env.PORT ?? "3001", 10);
|
||||
await app.listen(port);
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`[freight-api] listening on http://localhost:${port}`);
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
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 { BillingService } from './billing.service';
|
||||
import { BillingService } from "./billing.service";
|
||||
|
||||
@ApiTags('billing')
|
||||
@ApiTags("billing")
|
||||
// @UseGuards(JwtAuthGuard) — TODO: integrate @edr/auth
|
||||
@Controller('billing')
|
||||
@Controller("billing")
|
||||
export class BillingController {
|
||||
constructor(private readonly billingService: BillingService) {}
|
||||
|
||||
@Get('invoices')
|
||||
@ApiOperation({ summary: 'List all invoices' })
|
||||
@Get("invoices")
|
||||
@ApiOperation({ summary: "List all invoices" })
|
||||
findAll() {
|
||||
return this.billingService.findAll();
|
||||
}
|
||||
|
||||
@Get('invoices/booking/:bookingId')
|
||||
@ApiOperation({ summary: 'List invoices for a booking' })
|
||||
findByBooking(@Param('bookingId', ParseUUIDPipe) bookingId: string) {
|
||||
@Get("invoices/booking/:bookingId")
|
||||
@ApiOperation({ summary: "List invoices for a booking" })
|
||||
findByBooking(@Param("bookingId", ParseUUIDPipe) bookingId: string) {
|
||||
return this.billingService.findByBooking(bookingId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 { BillingController } from './billing.controller';
|
||||
import { BillingService } from './billing.service';
|
||||
import { Invoice } from './entities/invoice.entity';
|
||||
import { BillingController } from "./billing.controller";
|
||||
import { BillingService } from "./billing.service";
|
||||
import { Invoice } from "./entities/invoice.entity";
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([Invoice])],
|
||||
|
||||
@@ -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 { Invoice } from './entities/invoice.entity';
|
||||
import { Invoice } from "./entities/invoice.entity";
|
||||
|
||||
@Injectable()
|
||||
export class BillingService {
|
||||
@@ -13,11 +13,14 @@ export class BillingService {
|
||||
|
||||
/** List every invoice (most recent first). */
|
||||
findAll(): Promise<Invoice[]> {
|
||||
return this.invoicesRepository.find({ order: { issuedAt: 'DESC' } });
|
||||
return this.invoicesRepository.find({ order: { issuedAt: "DESC" } });
|
||||
}
|
||||
|
||||
/** List invoices for a given booking. */
|
||||
findByBooking(bookingId: string): Promise<Invoice[]> {
|
||||
return this.invoicesRepository.find({ where: { bookingId }, order: { issuedAt: 'DESC' } });
|
||||
return this.invoicesRepository.find({
|
||||
where: { bookingId },
|
||||
order: { issuedAt: "DESC" },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
import { BaseEntity } from '@edr/api-common';
|
||||
import { Freight } from '@edr/types';
|
||||
import { Column, Entity } from 'typeorm';
|
||||
import { BaseEntity } from "@edr/api-common";
|
||||
import { Freight } from "@edr/types";
|
||||
import { Column, Entity } from "typeorm";
|
||||
|
||||
@Entity({ name: 'invoices' })
|
||||
@Entity({ name: "invoices" })
|
||||
export class Invoice extends BaseEntity {
|
||||
@Column({ name: 'booking_id', type: 'uuid' })
|
||||
@Column({ name: "booking_id", type: "uuid" })
|
||||
bookingId!: string;
|
||||
|
||||
@Column({ name: 'invoice_number', type: 'varchar', length: 64, unique: true })
|
||||
@Column({ name: "invoice_number", type: "varchar", length: 64, unique: true })
|
||||
invoiceNumber!: string;
|
||||
|
||||
@Column({ name: 'amount', type: 'numeric', precision: 14, scale: 2 })
|
||||
@Column({ name: "amount", type: "numeric", precision: 14, 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: Freight.PaymentStatus,
|
||||
default: Freight.PaymentStatus.Pending,
|
||||
})
|
||||
status!: Freight.PaymentStatus;
|
||||
|
||||
@Column({ name: 'issued_at', type: 'timestamptz' })
|
||||
@Column({ name: "issued_at", type: "timestamptz" })
|
||||
issuedAt!: Date;
|
||||
|
||||
@Column({ name: 'due_at', type: 'timestamptz' })
|
||||
@Column({ name: "due_at", type: "timestamptz" })
|
||||
dueAt!: 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 { BookingsService } from './bookings.service';
|
||||
import { CreateBookingDto } from './dto/create-booking.dto';
|
||||
import { FilterBookingDto } from './dto/filter-booking.dto';
|
||||
import { BookingsService } from "./bookings.service";
|
||||
import { CreateBookingDto } from "./dto/create-booking.dto";
|
||||
import { FilterBookingDto } from "./dto/filter-booking.dto";
|
||||
|
||||
@ApiTags('bookings')
|
||||
@ApiTags("bookings")
|
||||
// @UseGuards(JwtAuthGuard) — TODO: integrate @edr/auth
|
||||
@Controller('bookings')
|
||||
@Controller("bookings")
|
||||
export class BookingsController {
|
||||
constructor(private readonly bookingsService: BookingsService) {}
|
||||
|
||||
@Post()
|
||||
@ApiOperation({ summary: 'Create a new freight booking' })
|
||||
@ApiOperation({ summary: "Create a new freight booking" })
|
||||
create(@Body() dto: CreateBookingDto) {
|
||||
return this.bookingsService.create(dto);
|
||||
}
|
||||
|
||||
@Get()
|
||||
@ApiOperation({ summary: 'List freight bookings (paginated)' })
|
||||
@ApiOperation({ summary: "List freight bookings (paginated)" })
|
||||
findAll(@Query() filter: FilterBookingDto) {
|
||||
return this.bookingsService.findAll(filter);
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
@ApiOperation({ summary: 'Get a freight booking by ID' })
|
||||
findOne(@Param('id', ParseUUIDPipe) id: string) {
|
||||
@Get(":id")
|
||||
@ApiOperation({ summary: "Get a freight booking by ID" })
|
||||
findOne(@Param("id", ParseUUIDPipe) id: string) {
|
||||
return this.bookingsService.findById(id);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
@Delete(":id")
|
||||
@HttpCode(204)
|
||||
@ApiOperation({ summary: 'Soft-delete a freight booking' })
|
||||
remove(@Param('id', ParseUUIDPipe) id: string) {
|
||||
@ApiOperation({ summary: "Soft-delete a freight booking" })
|
||||
remove(@Param("id", ParseUUIDPipe) id: string) {
|
||||
return this.bookingsService.remove(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 { BookingsController } from './bookings.controller';
|
||||
import { BookingsRepository } from './bookings.repository';
|
||||
import { BookingsService } from './bookings.service';
|
||||
import { Booking } from './entities/booking.entity';
|
||||
import { BookingsController } from "./bookings.controller";
|
||||
import { BookingsRepository } from "./bookings.repository";
|
||||
import { BookingsService } from "./bookings.service";
|
||||
import { Booking } from "./entities/booking.entity";
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([Booking])],
|
||||
|
||||
@@ -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 { Booking } from './entities/booking.entity';
|
||||
import { Booking } from "./entities/booking.entity";
|
||||
|
||||
@Injectable()
|
||||
export class BookingsRepository extends BaseRepository<Booking> {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { Injectable, NotFoundException } from "@nestjs/common";
|
||||
|
||||
import { BookingsRepository } from './bookings.repository';
|
||||
import { CreateBookingDto } from './dto/create-booking.dto';
|
||||
import { FilterBookingDto } from './dto/filter-booking.dto';
|
||||
import { Booking } from './entities/booking.entity';
|
||||
import { BookingsRepository } from "./bookings.repository";
|
||||
import { CreateBookingDto } from "./dto/create-booking.dto";
|
||||
import { FilterBookingDto } from "./dto/filter-booking.dto";
|
||||
import { Booking } from "./entities/booking.entity";
|
||||
|
||||
@Injectable()
|
||||
export class BookingsService {
|
||||
@@ -18,7 +18,9 @@ export class BookingsService {
|
||||
}
|
||||
|
||||
/** Return a paginated list of bookings matching the filter. */
|
||||
async findAll(filter: FilterBookingDto): Promise<{ items: Booking[]; total: number }> {
|
||||
async findAll(
|
||||
filter: FilterBookingDto,
|
||||
): Promise<{ items: Booking[]; total: number }> {
|
||||
const page = filter.page ?? 1;
|
||||
const pageSize = filter.pageSize ?? 20;
|
||||
const [items, total] = await this.bookingsRepository.findAndCount({
|
||||
@@ -28,7 +30,7 @@ export class BookingsService {
|
||||
},
|
||||
skip: (page - 1) * pageSize,
|
||||
take: pageSize,
|
||||
order: { createdAt: 'DESC' },
|
||||
order: { createdAt: "DESC" },
|
||||
});
|
||||
return { items, total };
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Freight } from '@edr/types';
|
||||
import { Freight } from "@edr/types";
|
||||
import {
|
||||
IsDateString,
|
||||
IsEnum,
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
IsString,
|
||||
IsUUID,
|
||||
Min,
|
||||
} from 'class-validator';
|
||||
} from "class-validator";
|
||||
|
||||
export class CreateBookingDto {
|
||||
@IsString()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Freight } from '@edr/types';
|
||||
import { Type } from 'class-transformer';
|
||||
import { IsEnum, IsInt, IsOptional, IsUUID, Min } from 'class-validator';
|
||||
import { Freight } from "@edr/types";
|
||||
import { Type } from "class-transformer";
|
||||
import { IsEnum, IsInt, IsOptional, IsUUID, Min } from "class-validator";
|
||||
|
||||
export class FilterBookingDto {
|
||||
@IsOptional()
|
||||
|
||||
@@ -1,35 +1,41 @@
|
||||
import { BaseEntity } from '@edr/api-common';
|
||||
import { Freight } from '@edr/types';
|
||||
import { Column, Entity } from 'typeorm';
|
||||
import { BaseEntity } from "@edr/api-common";
|
||||
import { Freight } from "@edr/types";
|
||||
import { Column, Entity } from "typeorm";
|
||||
|
||||
@Entity({ name: 'bookings' })
|
||||
@Entity({ name: "bookings" })
|
||||
export class Booking extends BaseEntity {
|
||||
@Column({ name: 'reference', type: 'varchar', length: 64, unique: true })
|
||||
@Column({ name: "reference", type: "varchar", length: 64, unique: true })
|
||||
reference!: string;
|
||||
|
||||
@Column({ name: 'customer_id', type: 'uuid' })
|
||||
@Column({ name: "customer_id", type: "uuid" })
|
||||
customerId!: string;
|
||||
|
||||
@Column({ name: 'train_id', type: 'uuid', nullable: true })
|
||||
@Column({ name: "train_id", type: "uuid", nullable: true })
|
||||
trainId?: string | null;
|
||||
|
||||
@Column({
|
||||
name: 'status',
|
||||
type: 'enum',
|
||||
name: "status",
|
||||
type: "enum",
|
||||
enum: Freight.BookingStatus,
|
||||
default: Freight.BookingStatus.Draft,
|
||||
})
|
||||
status!: Freight.BookingStatus;
|
||||
|
||||
@Column({ name: 'scheduled_date', type: 'timestamptz' })
|
||||
@Column({ name: "scheduled_date", type: "timestamptz" })
|
||||
scheduledDate!: Date;
|
||||
|
||||
@Column({ name: 'total_amount', type: 'numeric', precision: 14, scale: 2, default: 0 })
|
||||
@Column({
|
||||
name: "total_amount",
|
||||
type: "numeric",
|
||||
precision: 14,
|
||||
scale: 2,
|
||||
default: 0,
|
||||
})
|
||||
totalAmount!: number;
|
||||
|
||||
@Column({
|
||||
name: 'payment_status',
|
||||
type: 'enum',
|
||||
name: "payment_status",
|
||||
type: "enum",
|
||||
enum: Freight.PaymentStatus,
|
||||
default: Freight.PaymentStatus.Pending,
|
||||
})
|
||||
|
||||
@@ -1,31 +1,39 @@
|
||||
import { Body, Controller, Get, Param, ParseUUIDPipe, Post, Query } from '@nestjs/common';
|
||||
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Get,
|
||||
Param,
|
||||
ParseUUIDPipe,
|
||||
Post,
|
||||
Query,
|
||||
} from "@nestjs/common";
|
||||
import { ApiOperation, ApiTags } from "@nestjs/swagger";
|
||||
|
||||
import { ConsignmentsService } from './consignments.service';
|
||||
import { CreateConsignmentDto } from './dto/create-consignment.dto';
|
||||
import { FilterConsignmentDto } from './dto/filter-consignment.dto';
|
||||
import { ConsignmentsService } from "./consignments.service";
|
||||
import { CreateConsignmentDto } from "./dto/create-consignment.dto";
|
||||
import { FilterConsignmentDto } from "./dto/filter-consignment.dto";
|
||||
|
||||
@ApiTags('consignments')
|
||||
@ApiTags("consignments")
|
||||
// @UseGuards(JwtAuthGuard) — TODO: integrate @edr/auth
|
||||
@Controller('consignments')
|
||||
@Controller("consignments")
|
||||
export class ConsignmentsController {
|
||||
constructor(private readonly consignmentsService: ConsignmentsService) {}
|
||||
|
||||
@Post()
|
||||
@ApiOperation({ summary: 'Create a new consignment' })
|
||||
@ApiOperation({ summary: "Create a new consignment" })
|
||||
create(@Body() dto: CreateConsignmentDto) {
|
||||
return this.consignmentsService.create(dto);
|
||||
}
|
||||
|
||||
@Get()
|
||||
@ApiOperation({ summary: 'List consignments (paginated)' })
|
||||
@ApiOperation({ summary: "List consignments (paginated)" })
|
||||
findAll(@Query() filter: FilterConsignmentDto) {
|
||||
return this.consignmentsService.findAll(filter);
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
@ApiOperation({ summary: 'Get a consignment by ID' })
|
||||
findOne(@Param('id', ParseUUIDPipe) id: string) {
|
||||
@Get(":id")
|
||||
@ApiOperation({ summary: "Get a consignment by ID" })
|
||||
findOne(@Param("id", ParseUUIDPipe) id: string) {
|
||||
return this.consignmentsService.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 { ConsignmentsController } from './consignments.controller';
|
||||
import { ConsignmentsRepository } from './consignments.repository';
|
||||
import { ConsignmentsService } from './consignments.service';
|
||||
import { Consignment } from './entities/consignment.entity';
|
||||
import { ConsignmentsController } from "./consignments.controller";
|
||||
import { ConsignmentsRepository } from "./consignments.repository";
|
||||
import { ConsignmentsService } from "./consignments.service";
|
||||
import { Consignment } from "./entities/consignment.entity";
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([Consignment])],
|
||||
|
||||
@@ -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 { Consignment } from './entities/consignment.entity';
|
||||
import { Consignment } from "./entities/consignment.entity";
|
||||
|
||||
@Injectable()
|
||||
export class ConsignmentsRepository extends BaseRepository<Consignment> {
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { Injectable, NotFoundException } from "@nestjs/common";
|
||||
|
||||
import { ConsignmentsRepository } from './consignments.repository';
|
||||
import { CreateConsignmentDto } from './dto/create-consignment.dto';
|
||||
import { FilterConsignmentDto } from './dto/filter-consignment.dto';
|
||||
import { Consignment } from './entities/consignment.entity';
|
||||
import { ConsignmentsRepository } from "./consignments.repository";
|
||||
import { CreateConsignmentDto } from "./dto/create-consignment.dto";
|
||||
import { FilterConsignmentDto } from "./dto/filter-consignment.dto";
|
||||
import { Consignment } from "./entities/consignment.entity";
|
||||
|
||||
@Injectable()
|
||||
export class ConsignmentsService {
|
||||
constructor(private readonly consignmentsRepository: ConsignmentsRepository) {}
|
||||
constructor(
|
||||
private readonly consignmentsRepository: ConsignmentsRepository,
|
||||
) {}
|
||||
|
||||
/** Create a new consignment for a freight booking. */
|
||||
create(dto: CreateConsignmentDto): Promise<Consignment> {
|
||||
@@ -15,7 +17,9 @@ export class ConsignmentsService {
|
||||
}
|
||||
|
||||
/** Return a paginated list of consignments. */
|
||||
async findAll(filter: FilterConsignmentDto): Promise<{ items: Consignment[]; total: number }> {
|
||||
async findAll(
|
||||
filter: FilterConsignmentDto,
|
||||
): Promise<{ items: Consignment[]; total: number }> {
|
||||
const page = filter.page ?? 1;
|
||||
const pageSize = filter.pageSize ?? 20;
|
||||
const [items, total] = await this.consignmentsRepository.findAndCount({
|
||||
@@ -25,7 +29,7 @@ export class ConsignmentsService {
|
||||
},
|
||||
skip: (page - 1) * pageSize,
|
||||
take: pageSize,
|
||||
order: { createdAt: 'DESC' },
|
||||
order: { createdAt: "DESC" },
|
||||
});
|
||||
return { items, total };
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Freight } from '@edr/types';
|
||||
import { IsEnum, IsNumber, IsString, IsUUID, Min } from 'class-validator';
|
||||
import { Freight } from "@edr/types";
|
||||
import { IsEnum, IsNumber, IsString, IsUUID, Min } from "class-validator";
|
||||
|
||||
export class CreateConsignmentDto {
|
||||
@IsUUID()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Freight } from '@edr/types';
|
||||
import { Type } from 'class-transformer';
|
||||
import { IsEnum, IsInt, IsOptional, IsUUID, Min } from 'class-validator';
|
||||
import { Freight } from "@edr/types";
|
||||
import { Type } from "class-transformer";
|
||||
import { IsEnum, IsInt, IsOptional, IsUUID, Min } from "class-validator";
|
||||
|
||||
export class FilterConsignmentDto {
|
||||
@IsOptional()
|
||||
|
||||
@@ -1,32 +1,37 @@
|
||||
import { BaseEntity } from '@edr/api-common';
|
||||
import { Freight } from '@edr/types';
|
||||
import { Column, Entity } from 'typeorm';
|
||||
import { BaseEntity } from "@edr/api-common";
|
||||
import { Freight } from "@edr/types";
|
||||
import { Column, Entity } from "typeorm";
|
||||
|
||||
@Entity({ name: 'consignments' })
|
||||
@Entity({ name: "consignments" })
|
||||
export class Consignment extends BaseEntity {
|
||||
@Column({ name: 'booking_id', type: 'uuid' })
|
||||
@Column({ name: "booking_id", type: "uuid" })
|
||||
bookingId!: string;
|
||||
|
||||
@Column({ name: 'tracking_number', type: 'varchar', length: 64, unique: true })
|
||||
@Column({
|
||||
name: "tracking_number",
|
||||
type: "varchar",
|
||||
length: 64,
|
||||
unique: true,
|
||||
})
|
||||
trackingNumber!: string;
|
||||
|
||||
@Column({ name: 'cargo_type', type: 'enum', enum: Freight.CargoType })
|
||||
@Column({ name: "cargo_type", type: "enum", enum: Freight.CargoType })
|
||||
cargoType!: Freight.CargoType;
|
||||
|
||||
@Column({ name: 'weight_kg', type: 'numeric', precision: 12, scale: 2 })
|
||||
@Column({ name: "weight_kg", type: "numeric", precision: 12, scale: 2 })
|
||||
weightKg!: number;
|
||||
|
||||
@Column({
|
||||
name: 'status',
|
||||
type: 'enum',
|
||||
name: "status",
|
||||
type: "enum",
|
||||
enum: Freight.ConsignmentStatus,
|
||||
default: Freight.ConsignmentStatus.Pending,
|
||||
})
|
||||
status!: Freight.ConsignmentStatus;
|
||||
|
||||
@Column({ name: 'origin_station', type: 'varchar', length: 128 })
|
||||
@Column({ name: "origin_station", type: "varchar", length: 128 })
|
||||
originStation!: string;
|
||||
|
||||
@Column({ name: 'destination_station', type: 'varchar', length: 128 })
|
||||
@Column({ name: "destination_station", type: "varchar", length: 128 })
|
||||
destinationStation!: string;
|
||||
}
|
||||
|
||||
@@ -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 { CustomersService } from './customers.service';
|
||||
import { CreateCustomerDto } from './dto/create-customer.dto';
|
||||
import { CustomersService } from "./customers.service";
|
||||
import { CreateCustomerDto } from "./dto/create-customer.dto";
|
||||
|
||||
@ApiTags('customers')
|
||||
@ApiTags("customers")
|
||||
// @UseGuards(JwtAuthGuard) — TODO: integrate @edr/auth
|
||||
@Controller('customers')
|
||||
@Controller("customers")
|
||||
export class CustomersController {
|
||||
constructor(private readonly customersService: CustomersService) {}
|
||||
|
||||
@Post()
|
||||
@ApiOperation({ summary: 'Create a new customer' })
|
||||
@ApiOperation({ summary: "Create a new customer" })
|
||||
create(@Body() dto: CreateCustomerDto) {
|
||||
return this.customersService.create(dto);
|
||||
}
|
||||
|
||||
@Get()
|
||||
@ApiOperation({ summary: 'List all customers' })
|
||||
@ApiOperation({ summary: "List all customers" })
|
||||
findAll() {
|
||||
return this.customersService.findAll();
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
@ApiOperation({ summary: 'Get a customer by ID' })
|
||||
findOne(@Param('id', ParseUUIDPipe) id: string) {
|
||||
@Get(":id")
|
||||
@ApiOperation({ summary: "Get a customer by ID" })
|
||||
findOne(@Param("id", ParseUUIDPipe) id: string) {
|
||||
return this.customersService.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 { CustomersController } from './customers.controller';
|
||||
import { CustomersRepository } from './customers.repository';
|
||||
import { CustomersService } from './customers.service';
|
||||
import { Customer } from './entities/customer.entity';
|
||||
import { CustomersController } from "./customers.controller";
|
||||
import { CustomersRepository } from "./customers.repository";
|
||||
import { CustomersService } from "./customers.service";
|
||||
import { Customer } from "./entities/customer.entity";
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([Customer])],
|
||||
|
||||
@@ -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 { Customer } from './entities/customer.entity';
|
||||
import { Customer } from "./entities/customer.entity";
|
||||
|
||||
@Injectable()
|
||||
export class CustomersRepository extends BaseRepository<Customer> {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { Injectable, NotFoundException } from "@nestjs/common";
|
||||
|
||||
import { CustomersRepository } from './customers.repository';
|
||||
import { CreateCustomerDto } from './dto/create-customer.dto';
|
||||
import { Customer } from './entities/customer.entity';
|
||||
import { CustomersRepository } from "./customers.repository";
|
||||
import { CreateCustomerDto } from "./dto/create-customer.dto";
|
||||
import { Customer } from "./entities/customer.entity";
|
||||
|
||||
@Injectable()
|
||||
export class CustomersService {
|
||||
@@ -15,7 +15,7 @@ export class CustomersService {
|
||||
|
||||
/** List every customer (alphabetical). */
|
||||
findAll(): Promise<Customer[]> {
|
||||
return this.customersRepository.findAll({ order: { name: 'ASC' } });
|
||||
return this.customersRepository.findAll({ order: { name: "ASC" } });
|
||||
}
|
||||
|
||||
/** Get a single customer by ID. */
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { IsEmail, IsOptional, IsString } from 'class-validator';
|
||||
import { IsEmail, IsOptional, IsString } from "class-validator";
|
||||
|
||||
export class CreateCustomerDto {
|
||||
@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: 'customers' })
|
||||
@Entity({ name: "customers" })
|
||||
export class Customer extends BaseEntity {
|
||||
@Column({ name: 'name', type: 'varchar', length: 256 })
|
||||
@Column({ name: "name", type: "varchar", length: 256 })
|
||||
name!: 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: 'address', type: 'text', nullable: true })
|
||||
@Column({ name: "address", type: "text", nullable: true })
|
||||
address?: string | null;
|
||||
|
||||
@Column({ name: 'tax_id', type: 'varchar', length: 64, nullable: true })
|
||||
@Column({ name: "tax_id", type: "varchar", length: 64, nullable: true })
|
||||
taxId?: string | null;
|
||||
}
|
||||
|
||||
@@ -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,21 +1,21 @@
|
||||
import { BaseEntity } from '@edr/api-common';
|
||||
import { Freight } from '@edr/types';
|
||||
import { Column, Entity } from 'typeorm';
|
||||
import { BaseEntity } from "@edr/api-common";
|
||||
import { Freight } from "@edr/types";
|
||||
import { Column, Entity } from "typeorm";
|
||||
|
||||
@Entity({ name: 'tracking_events' })
|
||||
@Entity({ name: "tracking_events" })
|
||||
export class TrackingEvent extends BaseEntity {
|
||||
@Column({ name: 'consignment_id', type: 'uuid' })
|
||||
@Column({ name: "consignment_id", type: "uuid" })
|
||||
consignmentId!: string;
|
||||
|
||||
@Column({ name: 'location', type: 'varchar', length: 256 })
|
||||
@Column({ name: "location", type: "varchar", length: 256 })
|
||||
location!: string;
|
||||
|
||||
@Column({ name: 'status', type: 'enum', enum: Freight.ConsignmentStatus })
|
||||
@Column({ name: "status", type: "enum", enum: Freight.ConsignmentStatus })
|
||||
status!: Freight.ConsignmentStatus;
|
||||
|
||||
@Column({ name: 'occurred_at', type: 'timestamptz' })
|
||||
@Column({ name: "occurred_at", type: "timestamptz" })
|
||||
occurredAt!: Date;
|
||||
|
||||
@Column({ name: 'description', type: 'text', nullable: true })
|
||||
@Column({ name: "description", type: "text", nullable: true })
|
||||
description?: string | null;
|
||||
}
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
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 { TrackingService } from './tracking.service';
|
||||
import { TrackingService } from "./tracking.service";
|
||||
|
||||
@ApiTags('tracking')
|
||||
@ApiTags("tracking")
|
||||
// @UseGuards(JwtAuthGuard) — TODO: integrate @edr/auth
|
||||
@Controller('tracking')
|
||||
@Controller("tracking")
|
||||
export class TrackingController {
|
||||
constructor(private readonly trackingService: TrackingService) {}
|
||||
|
||||
@Get(':consignmentId')
|
||||
@ApiOperation({ summary: 'Get the tracking timeline for a consignment' })
|
||||
findByConsignment(@Param('consignmentId', ParseUUIDPipe) consignmentId: string) {
|
||||
@Get(":consignmentId")
|
||||
@ApiOperation({ summary: "Get the tracking timeline for a consignment" })
|
||||
findByConsignment(
|
||||
@Param("consignmentId", ParseUUIDPipe) consignmentId: string,
|
||||
) {
|
||||
return this.trackingService.findByConsignment(consignmentId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 { TrackingEvent } from './entities/tracking-event.entity';
|
||||
import { TrackingController } from './tracking.controller';
|
||||
import { TrackingService } from './tracking.service';
|
||||
import { TrackingEvent } from "./entities/tracking-event.entity";
|
||||
import { TrackingController } from "./tracking.controller";
|
||||
import { TrackingService } from "./tracking.service";
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([TrackingEvent])],
|
||||
|
||||
@@ -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 { TrackingEvent } from './entities/tracking-event.entity';
|
||||
import { TrackingEvent } from "./entities/tracking-event.entity";
|
||||
|
||||
@Injectable()
|
||||
export class TrackingService {
|
||||
@@ -15,7 +15,7 @@ export class TrackingService {
|
||||
findByConsignment(consignmentId: string): Promise<TrackingEvent[]> {
|
||||
return this.trackingRepository.find({
|
||||
where: { consignmentId },
|
||||
order: { occurredAt: 'ASC' },
|
||||
order: { occurredAt: "ASC" },
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Freight } from '@edr/types';
|
||||
import { IsEnum, IsNumber, IsOptional, IsString, Min } from 'class-validator';
|
||||
import { Freight } from "@edr/types";
|
||||
import { IsEnum, IsNumber, IsOptional, IsString, Min } from "class-validator";
|
||||
|
||||
export class CreateTrainDto {
|
||||
@IsString()
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
import { BaseEntity } from '@edr/api-common';
|
||||
import { Freight } from '@edr/types';
|
||||
import { Column, Entity } from 'typeorm';
|
||||
import { BaseEntity } from "@edr/api-common";
|
||||
import { Freight } from "@edr/types";
|
||||
import { Column, Entity } from "typeorm";
|
||||
|
||||
@Entity({ name: 'trains' })
|
||||
@Entity({ name: "trains" })
|
||||
export class Train extends BaseEntity {
|
||||
@Column({ name: 'code', type: 'varchar', length: 32, unique: true })
|
||||
@Column({ name: "code", type: "varchar", length: 32, unique: true })
|
||||
code!: string;
|
||||
|
||||
@Column({ name: 'capacity_tons', type: 'numeric', precision: 10, scale: 2 })
|
||||
@Column({ name: "capacity_tons", type: "numeric", precision: 10, scale: 2 })
|
||||
capacityTons!: number;
|
||||
|
||||
@Column({
|
||||
name: 'status',
|
||||
type: 'enum',
|
||||
name: "status",
|
||||
type: "enum",
|
||||
enum: Freight.TrainStatus,
|
||||
default: Freight.TrainStatus.Available,
|
||||
})
|
||||
status!: Freight.TrainStatus;
|
||||
|
||||
@Column({ name: 'notes', type: 'text', nullable: true })
|
||||
@Column({ name: "notes", type: "text", nullable: true })
|
||||
notes?: 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 { CreateTrainDto } from './dto/create-train.dto';
|
||||
import { TrainsService } from './trains.service';
|
||||
import { CreateTrainDto } from "./dto/create-train.dto";
|
||||
import { TrainsService } from "./trains.service";
|
||||
|
||||
@ApiTags('trains')
|
||||
@ApiTags("trains")
|
||||
// @UseGuards(JwtAuthGuard) — TODO: integrate @edr/auth
|
||||
@Controller('trains')
|
||||
@Controller("trains")
|
||||
export class TrainsController {
|
||||
constructor(private readonly trainsService: TrainsService) {}
|
||||
|
||||
@Post()
|
||||
@ApiOperation({ summary: 'Register a new train' })
|
||||
@ApiOperation({ summary: "Register a new train" })
|
||||
create(@Body() dto: CreateTrainDto) {
|
||||
return this.trainsService.create(dto);
|
||||
}
|
||||
|
||||
@Get()
|
||||
@ApiOperation({ summary: 'List all trains' })
|
||||
@ApiOperation({ summary: "List all trains" })
|
||||
findAll() {
|
||||
return this.trainsService.findAll();
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
@ApiOperation({ summary: 'Get a train by ID' })
|
||||
findOne(@Param('id', ParseUUIDPipe) id: string) {
|
||||
@Get(":id")
|
||||
@ApiOperation({ summary: "Get a train by ID" })
|
||||
findOne(@Param("id", ParseUUIDPipe) id: string) {
|
||||
return this.trainsService.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 { Train } from './entities/train.entity';
|
||||
import { TrainsController } from './trains.controller';
|
||||
import { TrainsRepository } from './trains.repository';
|
||||
import { TrainsService } from './trains.service';
|
||||
import { Train } from "./entities/train.entity";
|
||||
import { TrainsController } from "./trains.controller";
|
||||
import { TrainsRepository } from "./trains.repository";
|
||||
import { TrainsService } from "./trains.service";
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([Train])],
|
||||
|
||||
@@ -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 { Train } from './entities/train.entity';
|
||||
import { Train } from "./entities/train.entity";
|
||||
|
||||
@Injectable()
|
||||
export class TrainsRepository extends BaseRepository<Train> {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { Injectable, NotFoundException } from "@nestjs/common";
|
||||
|
||||
import { CreateTrainDto } from './dto/create-train.dto';
|
||||
import { Train } from './entities/train.entity';
|
||||
import { TrainsRepository } from './trains.repository';
|
||||
import { CreateTrainDto } from "./dto/create-train.dto";
|
||||
import { Train } from "./entities/train.entity";
|
||||
import { TrainsRepository } from "./trains.repository";
|
||||
|
||||
@Injectable()
|
||||
export class TrainsService {
|
||||
@@ -15,7 +15,7 @@ export class TrainsService {
|
||||
|
||||
/** List every active train. */
|
||||
findAll(): Promise<Train[]> {
|
||||
return this.trainsRepository.findAll({ order: { code: 'ASC' } });
|
||||
return this.trainsRepository.findAll({ order: { code: "ASC" } });
|
||||
}
|
||||
|
||||
/** Get a single train by ID. */
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { INestApplication } from '@nestjs/common';
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import request from 'supertest';
|
||||
import { INestApplication } from "@nestjs/common";
|
||||
import { Test, TestingModule } from "@nestjs/testing";
|
||||
import request from "supertest";
|
||||
|
||||
import { AppModule } from '../src/app.module';
|
||||
import { AppModule } from "../src/app.module";
|
||||
|
||||
describe('Freight API (e2e)', () => {
|
||||
describe("Freight API (e2e)", () => {
|
||||
let app: INestApplication;
|
||||
|
||||
beforeAll(async () => {
|
||||
@@ -20,7 +20,7 @@ describe('Freight API (e2e)', () => {
|
||||
await app.close();
|
||||
});
|
||||
|
||||
it('GET /api/bookings returns a 200 with a list', () => {
|
||||
return request(app.getHttpServer()).get('/api/bookings').expect(200);
|
||||
it("GET /api/bookings returns a 200 with a list", () => {
|
||||
return request(app.getHttpServer()).get("/api/bookings").expect(200);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user