mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-30 06:28:12 +00:00
chore: fmt
This commit is contained in:
@@ -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. */
|
||||
|
||||
Reference in New Issue
Block a user