feat: 为预约建立业务提供项关联
This commit is contained in:
1 parent
11d0424669
commit
270136d24e
4 files changed
+29
-1
No files matched your search
@@ -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");
|
||||||
@@ -152,6 +152,8 @@ model Offering {
|
|||||||
updatedAt DateTime @updatedAt
|
updatedAt DateTime @updatedAt
|
||||||
services Service[]
|
services Service[]
|
||||||
inquiryForms InquiryForm[]
|
inquiryForms InquiryForm[]
|
||||||
|
bookings Booking[]
|
||||||
|
bookingItems BookingItem[]
|
||||||
@@unique([brandId, name])
|
@@unique([brandId, name])
|
||||||
@@index([brandId, isEnabled, sortOrder])
|
@@index([brandId, isEnabled, sortOrder])
|
||||||
}
|
}
|
||||||
@@ -231,6 +233,8 @@ model Booking {
|
|||||||
fulfillmentType FulfillmentType?
|
fulfillmentType FulfillmentType?
|
||||||
serviceId String?
|
serviceId String?
|
||||||
service Service? @relation(fields: [serviceId], references: [id], onDelete: SetNull)
|
service Service? @relation(fields: [serviceId], references: [id], onDelete: SetNull)
|
||||||
|
offeringId String?
|
||||||
|
offering Offering? @relation(fields: [offeringId], references: [id], onDelete: SetNull)
|
||||||
requestedDate DateTime?
|
requestedDate DateTime?
|
||||||
requestedTime String?
|
requestedTime String?
|
||||||
deliveryAddress String?
|
deliveryAddress String?
|
||||||
@@ -254,6 +258,8 @@ model BookingItem {
|
|||||||
booking Booking @relation(fields: [bookingId], references: [id], onDelete: Cascade)
|
booking Booking @relation(fields: [bookingId], references: [id], onDelete: Cascade)
|
||||||
serviceId String?
|
serviceId String?
|
||||||
service Service? @relation(fields: [serviceId], references: [id], onDelete: SetNull)
|
service Service? @relation(fields: [serviceId], references: [id], onDelete: SetNull)
|
||||||
|
offeringId String?
|
||||||
|
offering Offering? @relation(fields: [offeringId], references: [id], onDelete: SetNull)
|
||||||
serviceNameSnapshot String
|
serviceNameSnapshot String
|
||||||
unitPriceSnapshot Int
|
unitPriceSnapshot Int
|
||||||
quantity Int
|
quantity Int
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ export class BookingService {
|
|||||||
throw new BadRequestException("套餐不存在或暂不可预订");
|
throw new BadRequestException("套餐不存在或暂不可预订");
|
||||||
return {
|
return {
|
||||||
serviceId: service.id,
|
serviceId: service.id,
|
||||||
|
offeringId: service.offeringId,
|
||||||
serviceNameSnapshot: service.name,
|
serviceNameSnapshot: service.name,
|
||||||
unitPriceSnapshot: service.priceAmount,
|
unitPriceSnapshot: service.priceAmount,
|
||||||
quantity: item.quantity,
|
quantity: item.quantity,
|
||||||
@@ -86,6 +87,7 @@ export class BookingService {
|
|||||||
contactPreference: input.contactPreference,
|
contactPreference: input.contactPreference,
|
||||||
fulfillmentType: input.fulfillmentType ?? null,
|
fulfillmentType: input.fulfillmentType ?? null,
|
||||||
serviceId: items[0]?.serviceId ?? input.serviceId ?? null,
|
serviceId: items[0]?.serviceId ?? input.serviceId ?? null,
|
||||||
|
offeringId: items[0]?.offeringId ?? null,
|
||||||
requestedDate: input.requestedDate
|
requestedDate: input.requestedDate
|
||||||
? new Date(`${input.requestedDate}T00:00:00.000Z`)
|
? new Date(`${input.requestedDate}T00:00:00.000Z`)
|
||||||
: null,
|
: null,
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ export class TemplateWorkspaceService {
|
|||||||
brandId,
|
brandId,
|
||||||
templateKey,
|
templateKey,
|
||||||
templateVersion: template.version,
|
templateVersion: template.version,
|
||||||
configSnapshot: template,
|
configSnapshot: template as unknown as Prisma.InputJsonValue,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
await tx.brandModule.createMany({
|
await tx.brandModule.createMany({
|
||||||
|
|||||||
Reference in new issue
Block a user