mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-07 20:05:41 +00:00
chore: fmt
This commit is contained in:
@@ -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