test: 补充订单业务测试和数据库验证
This commit is contained in:
1 parent
7dfa603ba8
commit
50f405932b
13 files changed
+421
-20
No files matched your search
+47
-2
@@ -7,11 +7,12 @@ import {
|
||||
Module,
|
||||
Param,
|
||||
Post,
|
||||
Query,
|
||||
Req,
|
||||
ValidationPipe,
|
||||
} from "@nestjs/common";
|
||||
import { NestFactory } from "@nestjs/core";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { BookingStatus, Prisma } from "@prisma/client";
|
||||
import { FastifyAdapter } from "@nestjs/platform-fastify";
|
||||
import type { NestFastifyApplication } from "@nestjs/platform-fastify";
|
||||
import { PrismaService } from "./prisma.service.js";
|
||||
@@ -22,6 +23,9 @@ import { CreateTagDto, UpdateBookingStatusDto, UpdateBookingTagsDto } from "./ad
|
||||
import { AdminAuthService } from "./admin-auth.service.js";
|
||||
import { AdminLoginDto } from "./admin-auth.dto.js";
|
||||
import type { FastifyRequest } from "fastify";
|
||||
import { Transform } from "class-transformer";
|
||||
import type { TransformFnParams } from "class-transformer";
|
||||
import { IsBoolean, IsEnum, IsOptional, IsString } from "class-validator";
|
||||
import { readIdentity, signIdentity } from "./auth.js";
|
||||
import { ApiExceptionFilter, RequestIdMiddleware } from "./http.js";
|
||||
|
||||
@@ -104,6 +108,26 @@ export class AdminSessionController {
|
||||
}
|
||||
}
|
||||
|
||||
class AdminBookingQueryDto {
|
||||
@IsOptional()
|
||||
@IsEnum(BookingStatus)
|
||||
status?: BookingStatus;
|
||||
|
||||
@IsOptional()
|
||||
@Transform((params: TransformFnParams): unknown => {
|
||||
const value: unknown = params.value;
|
||||
if (value === "true") return true;
|
||||
if (value === "false") return false;
|
||||
return value;
|
||||
})
|
||||
@IsBoolean()
|
||||
unreadOnly?: boolean;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
tagId?: string;
|
||||
}
|
||||
|
||||
@Controller("customer/bookings")
|
||||
export class CustomerBookingController {
|
||||
constructor(
|
||||
@@ -162,10 +186,31 @@ export class CustomerBookingController {
|
||||
export class AdminBookingController {
|
||||
constructor(private readonly bookings: BookingService) {}
|
||||
@Get()
|
||||
list(@Req() request: FastifyRequest): Promise<unknown> {
|
||||
list(
|
||||
@Req() request: FastifyRequest,
|
||||
@Query() query: AdminBookingQueryDto,
|
||||
): Promise<unknown> {
|
||||
this.requireAdmin(request);
|
||||
return this.bookings.listForAdmin(
|
||||
process.env.DEFAULT_BRAND_ID ?? "00000000-0000-0000-0000-000000000001",
|
||||
query,
|
||||
);
|
||||
}
|
||||
|
||||
@Get("unread-count")
|
||||
unreadCount(@Req() request: FastifyRequest): Promise<unknown> {
|
||||
this.requireAdmin(request);
|
||||
return this.bookings.unreadCountForAdmin(
|
||||
process.env.DEFAULT_BRAND_ID ?? "00000000-0000-0000-0000-000000000001",
|
||||
);
|
||||
}
|
||||
|
||||
@Get(":id")
|
||||
detail(@Req() request: FastifyRequest, @Param("id") id: string): Promise<unknown> {
|
||||
this.requireAdmin(request);
|
||||
return this.bookings.getForAdmin(
|
||||
process.env.DEFAULT_BRAND_ID ?? "00000000-0000-0000-0000-000000000001",
|
||||
id,
|
||||
);
|
||||
}
|
||||
@Post(":id/status")
|
||||
|
||||
Reference in new issue
Block a user