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")
|
@Post("services")
|
||||||
createService(@Req() request: FastifyRequest, @Body() body: CreateServiceDto): Promise<unknown> {
|
async createService(
|
||||||
|
@Req() request: FastifyRequest,
|
||||||
|
@Body() body: CreateServiceDto,
|
||||||
|
): Promise<unknown> {
|
||||||
this.requireAdmin(request);
|
this.requireAdmin(request);
|
||||||
const { config, ...fields } = body;
|
const { config, ...fields } = body;
|
||||||
return this.prisma.service.create({
|
const brandId = this.brandId();
|
||||||
data: {
|
return this.prisma.$transaction(async (tx) => {
|
||||||
...fields,
|
const offering = await tx.offering.create({
|
||||||
brandId: this.brandId(),
|
data: {
|
||||||
categoryKey: body.categoryKey ?? "standard",
|
brandId,
|
||||||
...(config === undefined ? {} : { config: config as Prisma.InputJsonValue }),
|
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")
|
@Patch("services/:id")
|
||||||
|
|||||||
@@ -396,8 +396,14 @@ test("admin can read and update brand and service configuration", async () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
assert.equal(createdService.statusCode, 201);
|
assert.equal(createdService.statusCode, 201);
|
||||||
createdServiceId = JSON.parse(createdService.body).id;
|
const createdServiceBody = JSON.parse(createdService.body);
|
||||||
assert.equal(JSON.parse(createdService.body).categoryKey, "consulting");
|
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 {
|
} finally {
|
||||||
await prisma.brandProfile.update({
|
await prisma.brandProfile.update({
|
||||||
where: { id: brandId },
|
where: { id: brandId },
|
||||||
@@ -411,7 +417,12 @@ test("admin can read and update brand and service configuration", async () => {
|
|||||||
where: { id: serviceBefore.id },
|
where: { id: serviceBefore.id },
|
||||||
data: { priceText: serviceBefore.priceText, sortOrder: serviceBefore.sortOrder },
|
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 } },
|
where: { brandId, isEnabled: true, priceAmount: { not: null } },
|
||||||
});
|
});
|
||||||
assert.ok(service);
|
assert.ok(service);
|
||||||
|
assert.ok(service.offeringId);
|
||||||
const created = await request("/customer/bookings", {
|
const created = await request("/customer/bookings", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { authorization: `Bearer ${customerToken}` },
|
headers: { authorization: `Bearer ${customerToken}` },
|
||||||
|
|||||||
Reference in new issue
Block a user