test: 补充订单业务测试和数据库验证
This commit is contained in:
1 parent
7dfa603ba8
commit
50f405932b
13 files changed
+421
-20
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { BadRequestException, Injectable, NotFoundException } from "@nestjs/common";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { BookingStatus, Prisma } from "@prisma/client";
|
||||
import { PrismaService } from "./prisma.service.js";
|
||||
|
||||
export interface CreateBookingInput {
|
||||
@@ -116,14 +116,35 @@ export class BookingService {
|
||||
return this.prisma.booking.update({ where: { id }, data: { status: "cancelled" } });
|
||||
}
|
||||
|
||||
async listForAdmin(brandId: string) {
|
||||
async listForAdmin(
|
||||
brandId: string,
|
||||
options: { status?: BookingStatus; unreadOnly?: boolean; tagId?: string } = {},
|
||||
) {
|
||||
return this.prisma.booking.findMany({
|
||||
where: { brandId },
|
||||
where: {
|
||||
brandId,
|
||||
...(options.status ? { status: options.status } : {}),
|
||||
...(options.unreadOnly ? { isRead: false } : {}),
|
||||
...(options.tagId ? { tags: { some: { tagId: options.tagId } } } : {}),
|
||||
},
|
||||
orderBy: { createdAt: "desc" },
|
||||
include: { items: true, tags: { include: { tag: true } } },
|
||||
});
|
||||
}
|
||||
|
||||
async getForAdmin(brandId: string, id: string) {
|
||||
const booking = await this.prisma.booking.findFirst({
|
||||
where: { id, brandId },
|
||||
include: { items: true, tags: { include: { tag: true } }, service: true },
|
||||
});
|
||||
if (!booking) throw new NotFoundException("订单不存在");
|
||||
return booking;
|
||||
}
|
||||
|
||||
async unreadCountForAdmin(brandId: string) {
|
||||
return { count: await this.prisma.booking.count({ where: { brandId, isRead: false } }) };
|
||||
}
|
||||
|
||||
async updateStatus(
|
||||
brandId: string,
|
||||
id: string,
|
||||
|
||||
Reference in new issue
Block a user