feat: 回填旧服务的业务提供项关联
This commit is contained in:
1 parent
600b1d64b4
commit
537838532a
3 files changed
+76
-11
No files matched your search
@@ -0,0 +1,32 @@
|
||||
INSERT INTO "Offering" (
|
||||
"id", "brandId", "kind", "name", "summary", "description", "coverUrl",
|
||||
"priceText", "priceAmount", "isEnabled", "sortOrder", "config", "createdAt", "updatedAt"
|
||||
)
|
||||
SELECT
|
||||
gen_random_uuid()::text,
|
||||
s."brandId",
|
||||
'service',
|
||||
s."name",
|
||||
NULL,
|
||||
s."description",
|
||||
s."coverUrl",
|
||||
s."priceText",
|
||||
s."priceAmount",
|
||||
s."isEnabled",
|
||||
s."sortOrder",
|
||||
s."config",
|
||||
s."createdAt",
|
||||
s."updatedAt"
|
||||
FROM "Service" s
|
||||
WHERE s."offeringId" IS NULL
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM "Offering" o
|
||||
WHERE o."brandId" = s."brandId" AND o."name" = s."name"
|
||||
);
|
||||
|
||||
UPDATE "Service" s
|
||||
SET "offeringId" = o."id"
|
||||
FROM "Offering" o
|
||||
WHERE s."offeringId" IS NULL
|
||||
AND o."brandId" = s."brandId"
|
||||
AND o."name" = s."name";
|
||||
+29
-8
@@ -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")
|
||||
|
||||
@@ -396,8 +396,14 @@ test("admin can read and update brand and service configuration", async () => {
|
||||
},
|
||||
});
|
||||
assert.equal(createdService.statusCode, 201);
|
||||
createdServiceId = JSON.parse(createdService.body).id;
|
||||
assert.equal(JSON.parse(createdService.body).categoryKey, "consulting");
|
||||
const createdServiceBody = JSON.parse(createdService.body);
|
||||
createdServiceId = createdServiceBody.id;
|
||||
assert.equal(createdServiceBody.categoryKey, "consulting");
|
||||
assert.ok(createdServiceBody.offeringId);
|
||||
const createdOffering = await prisma.offering.findUnique({
|
||||
where: { id: createdServiceBody.offeringId },
|
||||
});
|
||||
assert.equal(createdOffering?.name, "集成测试通用服务");
|
||||
} finally {
|
||||
await prisma.brandProfile.update({
|
||||
where: { id: brandId },
|
||||
@@ -411,7 +417,12 @@ test("admin can read and update brand and service configuration", async () => {
|
||||
where: { id: serviceBefore.id },
|
||||
data: { priceText: serviceBefore.priceText, sortOrder: serviceBefore.sortOrder },
|
||||
});
|
||||
if (createdServiceId) await prisma.service.delete({ where: { id: createdServiceId } });
|
||||
if (createdServiceId) {
|
||||
const deletedService = await prisma.service.delete({ where: { id: createdServiceId } });
|
||||
if (deletedService.offeringId) {
|
||||
await prisma.offering.delete({ where: { id: deletedService.offeringId } });
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -521,6 +532,7 @@ test("customer can create and cancel a package booking", async () => {
|
||||
where: { brandId, isEnabled: true, priceAmount: { not: null } },
|
||||
});
|
||||
assert.ok(service);
|
||||
assert.ok(service.offeringId);
|
||||
const created = await request("/customer/bookings", {
|
||||
method: "POST",
|
||||
headers: { authorization: `Bearer ${customerToken}` },
|
||||
|
||||
Reference in new issue
Block a user