feat: 回填旧服务的业务提供项关联

This commit is contained in:
que01 committed 2026-09-21 16:31:50 +08:00
1 parent 600b1d64b4
commit 537838532a
3 files changed
+76 -11

No files matched your search

+29 -8
View File
@@ -570,16 +570,37 @@ export class AdminConfigController {
});
}
@Post("services")
createService(@Req() request: FastifyRequest, @Body() body: CreateServiceDto): Promise<unknown> {
async createService(
@Req() request: FastifyRequest,
@Body() body: CreateServiceDto,
): Promise<unknown> {
this.requireAdmin(request);
const { config, ...fields } = body;
return this.prisma.service.create({
data: {
...fields,
brandId: this.brandId(),
categoryKey: body.categoryKey ?? "standard",
...(config === undefined ? {} : { config: config as Prisma.InputJsonValue }),
},
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 }),
},
});
});
}
@Patch("services/:id")