refactor: 移除旧服务模型统一使用业务提供项

This commit is contained in:
que01 committed 2026-09-21 17:11:45 +08:00
1 parent ca85a583ce
commit 844a3bd715
13 files changed
+92 -146

No files matched your search

+22 -57
View File
@@ -82,12 +82,11 @@ export class PublicController {
const offerings = await this.prisma.offering.findMany({
where: { isEnabled: true },
orderBy: { sortOrder: "asc" },
include: { services: { where: { isEnabled: true }, take: 1 } },
});
return offerings.map(({ services, ...offering }) => ({
return offerings.map((offering) => ({
...offering,
bookingEnabled: services[0]?.bookingEnabled ?? false,
categoryKey: services[0]?.categoryKey ?? offering.kind,
bookingEnabled: true,
categoryKey: offering.kind,
}));
}
}
@@ -559,7 +558,7 @@ export class AdminConfigController {
@Get("services")
listServices(@Req() request: FastifyRequest): Promise<unknown> {
this.requireAdmin(request);
return this.prisma.service.findMany({
return this.prisma.offering.findMany({
where: { brandId: this.brandId() },
orderBy: { sortOrder: "asc" },
});
@@ -570,32 +569,15 @@ export class AdminConfigController {
@Body() body: CreateServiceDto,
): Promise<unknown> {
this.requireAdmin(request);
const { config, ...fields } = body;
const { config, categoryKey, ...fields } = body;
const brandId = this.brandId();
return this.prisma.$transaction(async (tx) => {
const offering = await tx.offering.create({
data: {
brandId,
kind: "service",
name: body.name,
description: body.description,
coverUrl: body.coverUrl ?? null,
priceText: body.priceText ?? null,
priceAmount: body.priceAmount ?? null,
isEnabled: body.isEnabled ?? true,
sortOrder: body.sortOrder ?? 0,
...(config === undefined ? {} : { config: config as Prisma.InputJsonValue }),
},
});
return tx.service.create({
data: {
...fields,
brandId,
offeringId: offering.id,
categoryKey: body.categoryKey ?? "standard",
...(config === undefined ? {} : { config: config as Prisma.InputJsonValue }),
},
});
return this.prisma.offering.create({
data: {
...fields,
brandId,
kind: categoryKey ?? "service",
...(config === undefined ? {} : { config: config as Prisma.InputJsonValue }),
},
});
}
@Patch("services/:id")
@@ -605,33 +587,16 @@ export class AdminConfigController {
@Body() body: UpdateServiceDto,
): Promise<unknown> {
this.requireAdmin(request);
const service = await this.prisma.service.findFirst({ where: { id, brandId: this.brandId() } });
if (!service) throw new BadRequestException("服务不存在");
const { config, ...fields } = body;
return this.prisma.$transaction(async (tx) => {
const updated = await tx.service.update({
where: { id },
data: {
...fields,
...(config === undefined ? {} : { config: config as Prisma.InputJsonValue }),
},
});
if (service.offeringId) {
await tx.offering.update({
where: { id: service.offeringId },
data: {
name: updated.name,
description: updated.description,
coverUrl: updated.coverUrl,
priceText: updated.priceText,
priceAmount: updated.priceAmount,
isEnabled: updated.isEnabled,
sortOrder: updated.sortOrder,
config: updated.config ?? Prisma.JsonNull,
},
});
}
return updated;
const item = await this.prisma.offering.findFirst({ where: { id, brandId: this.brandId() } });
if (!item) throw new BadRequestException("业务提供项不存在");
const { config, categoryKey, ...fields } = body;
return this.prisma.offering.update({
where: { id },
data: {
...fields,
...(categoryKey === undefined ? {} : { kind: categoryKey }),
...(config === undefined ? {} : { config: config as Prisma.InputJsonValue }),
},
});
}
}