From 270136d24eabbbf28f4474bd328b5eebd0adbb27 Mon Sep 17 00:00:00 2001 From: que01 Date: Mon, 21 Sep 2026 13:59:14 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=B8=BA=E9=A2=84=E7=BA=A6=E5=BB=BA?= =?UTF-8?q?=E7=AB=8B=E4=B8=9A=E5=8A=A1=E6=8F=90=E4=BE=9B=E9=A1=B9=E5=85=B3?= =?UTF-8?q?=E8=81=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../migration.sql | 20 +++++++++++++++++++ apps/api/prisma/schema.prisma | 6 ++++++ apps/api/src/booking.service.ts | 2 ++ apps/api/src/template-workspace.service.ts | 2 +- 4 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 apps/api/prisma/migrations/20260921120000_add_offering_refs_to_bookings/migration.sql diff --git a/apps/api/prisma/migrations/20260921120000_add_offering_refs_to_bookings/migration.sql b/apps/api/prisma/migrations/20260921120000_add_offering_refs_to_bookings/migration.sql new file mode 100644 index 0000000..4ab8f65 --- /dev/null +++ b/apps/api/prisma/migrations/20260921120000_add_offering_refs_to_bookings/migration.sql @@ -0,0 +1,20 @@ +ALTER TABLE "Booking" ADD COLUMN "offeringId" TEXT; +ALTER TABLE "BookingItem" ADD COLUMN "offeringId" TEXT; + +UPDATE "Booking" b +SET "offeringId" = s."offeringId" +FROM "Service" s +WHERE b."serviceId" = s."id" AND s."offeringId" IS NOT NULL; + +UPDATE "BookingItem" bi +SET "offeringId" = s."offeringId" +FROM "Service" s +WHERE bi."serviceId" = s."id" AND s."offeringId" IS NOT NULL; + +ALTER TABLE "Booking" ADD CONSTRAINT "Booking_offeringId_fkey" + FOREIGN KEY ("offeringId") REFERENCES "Offering"("id") ON DELETE SET NULL ON UPDATE CASCADE; +ALTER TABLE "BookingItem" ADD CONSTRAINT "BookingItem_offeringId_fkey" + FOREIGN KEY ("offeringId") REFERENCES "Offering"("id") ON DELETE SET NULL ON UPDATE CASCADE; + +CREATE INDEX "Booking_brandId_offeringId_idx" ON "Booking"("brandId", "offeringId"); +CREATE INDEX "BookingItem_offeringId_idx" ON "BookingItem"("offeringId"); diff --git a/apps/api/prisma/schema.prisma b/apps/api/prisma/schema.prisma index 2c3f05c..3613252 100644 --- a/apps/api/prisma/schema.prisma +++ b/apps/api/prisma/schema.prisma @@ -152,6 +152,8 @@ model Offering { updatedAt DateTime @updatedAt services Service[] inquiryForms InquiryForm[] + bookings Booking[] + bookingItems BookingItem[] @@unique([brandId, name]) @@index([brandId, isEnabled, sortOrder]) } @@ -231,6 +233,8 @@ model Booking { fulfillmentType FulfillmentType? serviceId String? service Service? @relation(fields: [serviceId], references: [id], onDelete: SetNull) + offeringId String? + offering Offering? @relation(fields: [offeringId], references: [id], onDelete: SetNull) requestedDate DateTime? requestedTime String? deliveryAddress String? @@ -254,6 +258,8 @@ model BookingItem { booking Booking @relation(fields: [bookingId], references: [id], onDelete: Cascade) serviceId String? service Service? @relation(fields: [serviceId], references: [id], onDelete: SetNull) + offeringId String? + offering Offering? @relation(fields: [offeringId], references: [id], onDelete: SetNull) serviceNameSnapshot String unitPriceSnapshot Int quantity Int diff --git a/apps/api/src/booking.service.ts b/apps/api/src/booking.service.ts index 1e1f2ac..eaa758f 100644 --- a/apps/api/src/booking.service.ts +++ b/apps/api/src/booking.service.ts @@ -65,6 +65,7 @@ export class BookingService { throw new BadRequestException("套餐不存在或暂不可预订"); return { serviceId: service.id, + offeringId: service.offeringId, serviceNameSnapshot: service.name, unitPriceSnapshot: service.priceAmount, quantity: item.quantity, @@ -86,6 +87,7 @@ export class BookingService { contactPreference: input.contactPreference, fulfillmentType: input.fulfillmentType ?? null, serviceId: items[0]?.serviceId ?? input.serviceId ?? null, + offeringId: items[0]?.offeringId ?? null, requestedDate: input.requestedDate ? new Date(`${input.requestedDate}T00:00:00.000Z`) : null, diff --git a/apps/api/src/template-workspace.service.ts b/apps/api/src/template-workspace.service.ts index b3ec1b6..db507ef 100644 --- a/apps/api/src/template-workspace.service.ts +++ b/apps/api/src/template-workspace.service.ts @@ -22,7 +22,7 @@ export class TemplateWorkspaceService { brandId, templateKey, templateVersion: template.version, - configSnapshot: template, + configSnapshot: template as unknown as Prisma.InputJsonValue, }, }); await tx.brandModule.createMany({