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