refactor: 统一服务兼容接口的数据来源
This commit is contained in:
1 parent
537838532a
commit
ca85a583ce
2 files changed
+37
-18
No files matched your search
+31
-18
@@ -79,21 +79,16 @@ export class PublicController {
|
||||
|
||||
@Get("services")
|
||||
async services(): Promise<unknown> {
|
||||
return this.prisma.service.findMany({
|
||||
const offerings = await this.prisma.offering.findMany({
|
||||
where: { isEnabled: true },
|
||||
orderBy: { sortOrder: "asc" },
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
description: true,
|
||||
coverUrl: true,
|
||||
priceText: true,
|
||||
priceAmount: true,
|
||||
bookingEnabled: true,
|
||||
categoryKey: true,
|
||||
config: true,
|
||||
},
|
||||
include: { services: { where: { isEnabled: true }, take: 1 } },
|
||||
});
|
||||
return offerings.map(({ services, ...offering }) => ({
|
||||
...offering,
|
||||
bookingEnabled: services[0]?.bookingEnabled ?? false,
|
||||
categoryKey: services[0]?.categoryKey ?? offering.kind,
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -613,12 +608,30 @@ export class AdminConfigController {
|
||||
const service = await this.prisma.service.findFirst({ where: { id, brandId: this.brandId() } });
|
||||
if (!service) throw new BadRequestException("服务不存在");
|
||||
const { config, ...fields } = body;
|
||||
return this.prisma.service.update({
|
||||
where: { id },
|
||||
data: {
|
||||
...fields,
|
||||
...(config === undefined ? {} : { config: config as Prisma.InputJsonValue }),
|
||||
},
|
||||
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;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user