refactor: 移除旧服务模型统一使用业务提供项
This commit is contained in:
1 parent
ca85a583ce
commit
844a3bd715
13 files changed
+82
-136
No files matched your search
@@ -0,0 +1,9 @@
|
|||||||
|
-- Service data was backfilled into Offering before this migration.
|
||||||
|
ALTER TABLE "BookingItem" DROP CONSTRAINT IF EXISTS "BookingItem_serviceId_fkey";
|
||||||
|
ALTER TABLE "Booking" DROP CONSTRAINT IF EXISTS "Booking_serviceId_fkey";
|
||||||
|
ALTER TABLE "Offering" DROP CONSTRAINT IF EXISTS "Service_offeringId_fkey";
|
||||||
|
ALTER TABLE "BookingItem" DROP COLUMN IF EXISTS "serviceId";
|
||||||
|
ALTER TABLE "Booking" DROP COLUMN IF EXISTS "serviceId";
|
||||||
|
DROP INDEX IF EXISTS "Service_brandId_isEnabled_sortOrder_idx";
|
||||||
|
DROP INDEX IF EXISTS "Service_brandId_name_key";
|
||||||
|
DROP TABLE IF EXISTS "Service";
|
||||||
@@ -48,7 +48,6 @@ model BrandProfile {
|
|||||||
config Json?
|
config Json?
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
updatedAt DateTime @updatedAt
|
updatedAt DateTime @updatedAt
|
||||||
services Service[]
|
|
||||||
bookings Booking[]
|
bookings Booking[]
|
||||||
customerUsers CustomerUser[]
|
customerUsers CustomerUser[]
|
||||||
tags Tag[]
|
tags Tag[]
|
||||||
@@ -61,30 +60,6 @@ model BrandProfile {
|
|||||||
inquirySubmissions InquirySubmission[]
|
inquirySubmissions InquirySubmission[]
|
||||||
}
|
}
|
||||||
|
|
||||||
model Service {
|
|
||||||
id String @id @default(uuid())
|
|
||||||
brandId String
|
|
||||||
brand BrandProfile @relation(fields: [brandId], references: [id])
|
|
||||||
name String
|
|
||||||
description String
|
|
||||||
categoryKey String @default("standard")
|
|
||||||
config Json?
|
|
||||||
coverUrl String?
|
|
||||||
priceText String?
|
|
||||||
priceAmount Int?
|
|
||||||
bookingEnabled Boolean @default(true)
|
|
||||||
isEnabled Boolean @default(true)
|
|
||||||
sortOrder Int @default(0)
|
|
||||||
createdAt DateTime @default(now())
|
|
||||||
updatedAt DateTime @updatedAt
|
|
||||||
bookings Booking[]
|
|
||||||
bookingItems BookingItem[]
|
|
||||||
offeringId String?
|
|
||||||
offering Offering? @relation(fields: [offeringId], references: [id], onDelete: SetNull)
|
|
||||||
@@unique([brandId, name])
|
|
||||||
@@index([brandId, isEnabled, sortOrder])
|
|
||||||
}
|
|
||||||
|
|
||||||
model BrandTemplateInstallation {
|
model BrandTemplateInstallation {
|
||||||
id String @id @default(uuid())
|
id String @id @default(uuid())
|
||||||
brandId String
|
brandId String
|
||||||
@@ -151,7 +126,6 @@ model Offering {
|
|||||||
config Json?
|
config Json?
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
updatedAt DateTime @updatedAt
|
updatedAt DateTime @updatedAt
|
||||||
services Service[]
|
|
||||||
inquiryForms InquiryForm[]
|
inquiryForms InquiryForm[]
|
||||||
bookings Booking[]
|
bookings Booking[]
|
||||||
bookingItems BookingItem[]
|
bookingItems BookingItem[]
|
||||||
@@ -235,8 +209,6 @@ model Booking {
|
|||||||
wechatId String?
|
wechatId String?
|
||||||
contactPreference ContactPreference
|
contactPreference ContactPreference
|
||||||
fulfillmentType FulfillmentType?
|
fulfillmentType FulfillmentType?
|
||||||
serviceId String?
|
|
||||||
service Service? @relation(fields: [serviceId], references: [id], onDelete: SetNull)
|
|
||||||
offeringId String?
|
offeringId String?
|
||||||
offering Offering? @relation(fields: [offeringId], references: [id], onDelete: SetNull)
|
offering Offering? @relation(fields: [offeringId], references: [id], onDelete: SetNull)
|
||||||
requestedDate DateTime?
|
requestedDate DateTime?
|
||||||
@@ -277,8 +249,6 @@ model BookingItem {
|
|||||||
id String @id @default(uuid())
|
id String @id @default(uuid())
|
||||||
bookingId String
|
bookingId String
|
||||||
booking Booking @relation(fields: [bookingId], references: [id], onDelete: Cascade)
|
booking Booking @relation(fields: [bookingId], references: [id], onDelete: Cascade)
|
||||||
serviceId String?
|
|
||||||
service Service? @relation(fields: [serviceId], references: [id], onDelete: SetNull)
|
|
||||||
offeringId String?
|
offeringId String?
|
||||||
offering Offering? @relation(fields: [offeringId], references: [id], onDelete: SetNull)
|
offering Offering? @relation(fields: [offeringId], references: [id], onDelete: SetNull)
|
||||||
serviceNameSnapshot String
|
serviceNameSnapshot String
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ async function main(): Promise<void> {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const services = [
|
const offerings = [
|
||||||
{
|
{
|
||||||
brandId: brand.id,
|
brandId: brand.id,
|
||||||
name: "红烧肉双拼套餐",
|
name: "红烧肉双拼套餐",
|
||||||
@@ -41,16 +41,15 @@ async function main(): Promise<void> {
|
|||||||
name: "家庭聚餐私厨",
|
name: "家庭聚餐私厨",
|
||||||
description: "根据人数、地点和口味人工沟通报价",
|
description: "根据人数、地点和口味人工沟通报价",
|
||||||
priceText: "面议",
|
priceText: "面议",
|
||||||
bookingEnabled: true,
|
|
||||||
sortOrder: 3,
|
sortOrder: 3,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
for (const service of services) {
|
for (const offering of offerings) {
|
||||||
const existing = await prisma.service.findFirst({
|
const existing = await prisma.offering.findFirst({
|
||||||
where: { brandId: brand.id, name: service.name },
|
where: { brandId: brand.id, name: offering.name },
|
||||||
});
|
});
|
||||||
if (existing) await prisma.service.update({ where: { id: existing.id }, data: service });
|
if (existing) await prisma.offering.update({ where: { id: existing.id }, data: offering });
|
||||||
else await prisma.service.create({ data: service });
|
else await prisma.offering.create({ data: { ...offering, kind: "service" } });
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const name of ["普通套餐", "私厨", "配送", "自取", "熟客", "重点跟进"]) {
|
for (const name of ["普通套餐", "私厨", "配送", "自取", "熟客", "重点跟进"]) {
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import {
|
|||||||
} from "class-validator";
|
} from "class-validator";
|
||||||
|
|
||||||
export class BookingItemDto {
|
export class BookingItemDto {
|
||||||
@IsString() serviceId!: string;
|
@IsString() offeringId!: string;
|
||||||
@IsInt() @Min(1) @Max(50) quantity!: number;
|
@IsInt() @Min(1) @Max(50) quantity!: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,7 +25,7 @@ export class CreateBookingDto {
|
|||||||
@IsOptional() @IsString() wechatId?: string;
|
@IsOptional() @IsString() wechatId?: string;
|
||||||
@IsIn(["wechat", "phone", "none"]) contactPreference!: "wechat" | "phone" | "none";
|
@IsIn(["wechat", "phone", "none"]) contactPreference!: "wechat" | "phone" | "none";
|
||||||
@IsOptional() @IsIn(["pickup", "delivery"]) fulfillmentType?: "pickup" | "delivery";
|
@IsOptional() @IsIn(["pickup", "delivery"]) fulfillmentType?: "pickup" | "delivery";
|
||||||
@IsOptional() @IsString() serviceId?: string;
|
@IsOptional() @IsString() offeringId?: string;
|
||||||
@IsOptional() @IsISO8601() requestedDate?: string;
|
@IsOptional() @IsISO8601() requestedDate?: string;
|
||||||
@IsOptional() @IsString() requestedTime?: string;
|
@IsOptional() @IsString() requestedTime?: string;
|
||||||
@IsOptional() @IsString() deliveryAddress?: string;
|
@IsOptional() @IsString() deliveryAddress?: string;
|
||||||
|
|||||||
@@ -12,13 +12,13 @@ export interface CreateBookingInput {
|
|||||||
wechatId?: string;
|
wechatId?: string;
|
||||||
contactPreference: "wechat" | "phone" | "none";
|
contactPreference: "wechat" | "phone" | "none";
|
||||||
fulfillmentType?: "pickup" | "delivery";
|
fulfillmentType?: "pickup" | "delivery";
|
||||||
serviceId?: string;
|
offeringId?: string;
|
||||||
requestedDate?: string;
|
requestedDate?: string;
|
||||||
requestedTime?: string;
|
requestedTime?: string;
|
||||||
deliveryAddress?: string;
|
deliveryAddress?: string;
|
||||||
note?: string;
|
note?: string;
|
||||||
extraData?: Prisma.InputJsonObject;
|
extraData?: Prisma.InputJsonObject;
|
||||||
items?: Array<{ serviceId: string; quantity: number }>;
|
items?: Array<{ offeringId: string; quantity: number }>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@@ -52,27 +52,26 @@ export class BookingService {
|
|||||||
) {
|
) {
|
||||||
throw new BadRequestException("私厨需求必须填写日期、人数和地点");
|
throw new BadRequestException("私厨需求必须填写日期、人数和地点");
|
||||||
}
|
}
|
||||||
const services = input.items?.length
|
const offerings = input.items?.length
|
||||||
? await this.prisma.service.findMany({
|
? await this.prisma.offering.findMany({
|
||||||
where: {
|
where: {
|
||||||
id: { in: input.items.map((item) => item.serviceId) },
|
id: { in: input.items.map((item) => item.offeringId) },
|
||||||
brandId,
|
brandId,
|
||||||
isEnabled: true,
|
isEnabled: true,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
: [];
|
: [];
|
||||||
const serviceMap = new Map(services.map((service) => [service.id, service]));
|
const offeringMap = new Map(offerings.map((offering) => [offering.id, offering]));
|
||||||
const items = (input.items ?? []).map((item) => {
|
const items = (input.items ?? []).map((item) => {
|
||||||
const service = serviceMap.get(item.serviceId);
|
const offering = offeringMap.get(item.offeringId);
|
||||||
if (!service || !service.bookingEnabled || service.priceAmount === null)
|
if (!offering || offering.priceAmount === null)
|
||||||
throw new BadRequestException("套餐不存在或暂不可预订");
|
throw new BadRequestException("套餐不存在或暂不可预订");
|
||||||
return {
|
return {
|
||||||
serviceId: service.id,
|
offeringId: offering.id,
|
||||||
offeringId: service.offeringId,
|
serviceNameSnapshot: offering.name,
|
||||||
serviceNameSnapshot: service.name,
|
unitPriceSnapshot: offering.priceAmount,
|
||||||
unitPriceSnapshot: service.priceAmount,
|
|
||||||
quantity: item.quantity,
|
quantity: item.quantity,
|
||||||
subtotalSnapshot: service.priceAmount * item.quantity,
|
subtotalSnapshot: offering.priceAmount * item.quantity,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
const estimatedAmount = items.reduce((sum, item) => sum + item.subtotalSnapshot, 0) || null;
|
const estimatedAmount = items.reduce((sum, item) => sum + item.subtotalSnapshot, 0) || null;
|
||||||
@@ -89,8 +88,7 @@ export class BookingService {
|
|||||||
wechatId: input.wechatId?.trim() ?? null,
|
wechatId: input.wechatId?.trim() ?? null,
|
||||||
contactPreference: input.contactPreference,
|
contactPreference: input.contactPreference,
|
||||||
fulfillmentType: input.fulfillmentType ?? null,
|
fulfillmentType: input.fulfillmentType ?? null,
|
||||||
serviceId: items[0]?.serviceId ?? input.serviceId ?? null,
|
offeringId: items[0]?.offeringId ?? input.offeringId ?? 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,
|
||||||
@@ -118,7 +116,7 @@ export class BookingService {
|
|||||||
return this.prisma.booking.findMany({
|
return this.prisma.booking.findMany({
|
||||||
where: { brandId, customerUserId },
|
where: { brandId, customerUserId },
|
||||||
orderBy: { createdAt: "desc" },
|
orderBy: { createdAt: "desc" },
|
||||||
include: { items: true, service: { select: { name: true } } },
|
include: { items: true, offering: { select: { name: true } } },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,7 +163,7 @@ export class BookingService {
|
|||||||
async getForAdmin(brandId: string, id: string) {
|
async getForAdmin(brandId: string, id: string) {
|
||||||
const booking = await this.prisma.booking.findFirst({
|
const booking = await this.prisma.booking.findFirst({
|
||||||
where: { id, brandId },
|
where: { id, brandId },
|
||||||
include: { items: true, tags: { include: { tag: true } }, service: true },
|
include: { items: true, tags: { include: { tag: true } }, offering: true },
|
||||||
});
|
});
|
||||||
if (!booking) throw new NotFoundException("订单不存在");
|
if (!booking) throw new NotFoundException("订单不存在");
|
||||||
return booking;
|
return booking;
|
||||||
|
|||||||
+12
-47
@@ -82,12 +82,11 @@ export class PublicController {
|
|||||||
const offerings = await this.prisma.offering.findMany({
|
const offerings = await this.prisma.offering.findMany({
|
||||||
where: { isEnabled: true },
|
where: { isEnabled: true },
|
||||||
orderBy: { sortOrder: "asc" },
|
orderBy: { sortOrder: "asc" },
|
||||||
include: { services: { where: { isEnabled: true }, take: 1 } },
|
|
||||||
});
|
});
|
||||||
return offerings.map(({ services, ...offering }) => ({
|
return offerings.map((offering) => ({
|
||||||
...offering,
|
...offering,
|
||||||
bookingEnabled: services[0]?.bookingEnabled ?? false,
|
bookingEnabled: true,
|
||||||
categoryKey: services[0]?.categoryKey ?? offering.kind,
|
categoryKey: offering.kind,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -559,7 +558,7 @@ export class AdminConfigController {
|
|||||||
@Get("services")
|
@Get("services")
|
||||||
listServices(@Req() request: FastifyRequest): Promise<unknown> {
|
listServices(@Req() request: FastifyRequest): Promise<unknown> {
|
||||||
this.requireAdmin(request);
|
this.requireAdmin(request);
|
||||||
return this.prisma.service.findMany({
|
return this.prisma.offering.findMany({
|
||||||
where: { brandId: this.brandId() },
|
where: { brandId: this.brandId() },
|
||||||
orderBy: { sortOrder: "asc" },
|
orderBy: { sortOrder: "asc" },
|
||||||
});
|
});
|
||||||
@@ -570,33 +569,16 @@ export class AdminConfigController {
|
|||||||
@Body() body: CreateServiceDto,
|
@Body() body: CreateServiceDto,
|
||||||
): Promise<unknown> {
|
): Promise<unknown> {
|
||||||
this.requireAdmin(request);
|
this.requireAdmin(request);
|
||||||
const { config, ...fields } = body;
|
const { config, categoryKey, ...fields } = body;
|
||||||
const brandId = this.brandId();
|
const brandId = this.brandId();
|
||||||
return this.prisma.$transaction(async (tx) => {
|
return this.prisma.offering.create({
|
||||||
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: {
|
data: {
|
||||||
...fields,
|
...fields,
|
||||||
brandId,
|
brandId,
|
||||||
offeringId: offering.id,
|
kind: categoryKey ?? "service",
|
||||||
categoryKey: body.categoryKey ?? "standard",
|
|
||||||
...(config === undefined ? {} : { config: config as Prisma.InputJsonValue }),
|
...(config === undefined ? {} : { config: config as Prisma.InputJsonValue }),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
@Patch("services/:id")
|
@Patch("services/:id")
|
||||||
async updateService(
|
async updateService(
|
||||||
@@ -605,34 +587,17 @@ export class AdminConfigController {
|
|||||||
@Body() body: UpdateServiceDto,
|
@Body() body: UpdateServiceDto,
|
||||||
): Promise<unknown> {
|
): Promise<unknown> {
|
||||||
this.requireAdmin(request);
|
this.requireAdmin(request);
|
||||||
const service = await this.prisma.service.findFirst({ where: { id, brandId: this.brandId() } });
|
const item = await this.prisma.offering.findFirst({ where: { id, brandId: this.brandId() } });
|
||||||
if (!service) throw new BadRequestException("服务不存在");
|
if (!item) throw new BadRequestException("业务提供项不存在");
|
||||||
const { config, ...fields } = body;
|
const { config, categoryKey, ...fields } = body;
|
||||||
return this.prisma.$transaction(async (tx) => {
|
return this.prisma.offering.update({
|
||||||
const updated = await tx.service.update({
|
|
||||||
where: { id },
|
where: { id },
|
||||||
data: {
|
data: {
|
||||||
...fields,
|
...fields,
|
||||||
|
...(categoryKey === undefined ? {} : { kind: categoryKey }),
|
||||||
...(config === undefined ? {} : { config: config as Prisma.InputJsonValue }),
|
...(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;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,17 +5,16 @@ import { BookingService } from "../src/booking.service.js";
|
|||||||
|
|
||||||
const brandId = "brand-1";
|
const brandId = "brand-1";
|
||||||
const customerId = "customer-1";
|
const customerId = "customer-1";
|
||||||
const service = {
|
const offering = {
|
||||||
id: "service-1",
|
id: "service-1",
|
||||||
name: "套餐",
|
name: "套餐",
|
||||||
bookingEnabled: true,
|
|
||||||
priceAmount: 2800,
|
priceAmount: 2800,
|
||||||
};
|
};
|
||||||
|
|
||||||
function createPrisma(overrides: Record<string, unknown> = {}): any {
|
function createPrisma(overrides: Record<string, unknown> = {}): any {
|
||||||
return {
|
return {
|
||||||
service: {
|
offering: {
|
||||||
findMany: async () => [service],
|
findMany: async () => [offering],
|
||||||
},
|
},
|
||||||
booking: {
|
booking: {
|
||||||
create: async ({ data }: any) => ({
|
create: async ({ data }: any) => ({
|
||||||
@@ -31,7 +30,7 @@ function createPrisma(overrides: Record<string, unknown> = {}): any {
|
|||||||
},
|
},
|
||||||
tag: { findMany: async () => [] },
|
tag: { findMany: async () => [] },
|
||||||
bookingTag: { deleteMany: {}, createMany: {} },
|
bookingTag: { deleteMany: {}, createMany: {} },
|
||||||
$transaction: async () => undefined,
|
$transaction: async (callback: (tx: unknown) => unknown) => callback(undefined),
|
||||||
...overrides,
|
...overrides,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -43,7 +42,7 @@ test("创建普通套餐订单时保存价格快照和预计金额", async () =>
|
|||||||
customerName: "陈同学",
|
customerName: "陈同学",
|
||||||
wechatId: "wx-test",
|
wechatId: "wx-test",
|
||||||
contactPreference: "wechat",
|
contactPreference: "wechat",
|
||||||
items: [{ serviceId: service.id, quantity: 2 }],
|
items: [{ offeringId: offering.id, quantity: 2 }],
|
||||||
});
|
});
|
||||||
assert.equal(result.estimatedAmount, 5600);
|
assert.equal(result.estimatedAmount, 5600);
|
||||||
assert.equal(result.status, "received");
|
assert.equal(result.status, "received");
|
||||||
@@ -85,9 +84,20 @@ test("取消不存在或不属于当前客户的订单返回不存在", async ()
|
|||||||
test("订单状态只能按定义的状态机流转", async () => {
|
test("订单状态只能按定义的状态机流转", async () => {
|
||||||
const prisma = createPrisma({
|
const prisma = createPrisma({
|
||||||
booking: {
|
booking: {
|
||||||
findFirst: async () => ({ id: "booking-1", status: "received" }),
|
findFirst: async () => ({
|
||||||
|
id: "booking-1",
|
||||||
|
status: "received",
|
||||||
|
currentState: "received",
|
||||||
|
workflowKey: "booking.basic",
|
||||||
|
workflowVersion: "1.0.0",
|
||||||
|
}),
|
||||||
update: async ({ data }: any) => data,
|
update: async ({ data }: any) => data,
|
||||||
},
|
},
|
||||||
|
$transaction: async (callback: (tx: any) => unknown) =>
|
||||||
|
callback({
|
||||||
|
booking: { update: async ({ data }: any) => data },
|
||||||
|
bookingStateTransition: { create: async () => undefined },
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
const bookings = new BookingService(prisma);
|
const bookings = new BookingService(prisma);
|
||||||
assert.equal(
|
assert.equal(
|
||||||
|
|||||||
@@ -346,7 +346,7 @@ test("admin can read and update brand and service configuration", async () => {
|
|||||||
|
|
||||||
const brandBefore = await prisma.brandProfile.findUnique({ where: { id: brandId } });
|
const brandBefore = await prisma.brandProfile.findUnique({ where: { id: brandId } });
|
||||||
assert.ok(brandBefore);
|
assert.ok(brandBefore);
|
||||||
const serviceBefore = await prisma.service.findFirst({ where: { brandId, isEnabled: true } });
|
const serviceBefore = await prisma.offering.findFirst({ where: { brandId, isEnabled: true } });
|
||||||
assert.ok(serviceBefore);
|
assert.ok(serviceBefore);
|
||||||
let createdServiceId;
|
let createdServiceId;
|
||||||
|
|
||||||
@@ -381,7 +381,7 @@ test("admin can read and update brand and service configuration", async () => {
|
|||||||
const publicServices = await request("/public/services");
|
const publicServices = await request("/public/services");
|
||||||
assert.equal(publicServices.statusCode, 200);
|
assert.equal(publicServices.statusCode, 200);
|
||||||
const projectedService = JSON.parse(publicServices.body).find(
|
const projectedService = JSON.parse(publicServices.body).find(
|
||||||
(item) => item.id === serviceBefore.offeringId,
|
(item) => item.id === serviceBefore.id,
|
||||||
);
|
);
|
||||||
assert.equal(projectedService.priceText, "集成测试价格");
|
assert.equal(projectedService.priceText, "集成测试价格");
|
||||||
|
|
||||||
@@ -404,10 +404,9 @@ test("admin can read and update brand and service configuration", async () => {
|
|||||||
assert.equal(createdService.statusCode, 201);
|
assert.equal(createdService.statusCode, 201);
|
||||||
const createdServiceBody = JSON.parse(createdService.body);
|
const createdServiceBody = JSON.parse(createdService.body);
|
||||||
createdServiceId = createdServiceBody.id;
|
createdServiceId = createdServiceBody.id;
|
||||||
assert.equal(createdServiceBody.categoryKey, "consulting");
|
assert.equal(createdServiceBody.kind, "consulting");
|
||||||
assert.ok(createdServiceBody.offeringId);
|
|
||||||
const createdOffering = await prisma.offering.findUnique({
|
const createdOffering = await prisma.offering.findUnique({
|
||||||
where: { id: createdServiceBody.offeringId },
|
where: { id: createdServiceBody.id },
|
||||||
});
|
});
|
||||||
assert.equal(createdOffering?.name, "集成测试通用服务");
|
assert.equal(createdOffering?.name, "集成测试通用服务");
|
||||||
} finally {
|
} finally {
|
||||||
@@ -419,15 +418,12 @@ test("admin can read and update brand and service configuration", async () => {
|
|||||||
templateKey: brandBefore.templateKey,
|
templateKey: brandBefore.templateKey,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
await prisma.service.update({
|
await prisma.offering.update({
|
||||||
where: { id: serviceBefore.id },
|
where: { id: serviceBefore.id },
|
||||||
data: { priceText: serviceBefore.priceText, sortOrder: serviceBefore.sortOrder },
|
data: { priceText: serviceBefore.priceText, sortOrder: serviceBefore.sortOrder },
|
||||||
});
|
});
|
||||||
if (createdServiceId) {
|
if (createdServiceId) {
|
||||||
const deletedService = await prisma.service.delete({ where: { id: createdServiceId } });
|
await prisma.offering.delete({ where: { id: createdServiceId } });
|
||||||
if (deletedService.offeringId) {
|
|
||||||
await prisma.offering.delete({ where: { id: deletedService.offeringId } });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -534,11 +530,10 @@ test("customer can create a generic inquiry without food-specific fields", async
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("customer can create and cancel a package booking", async () => {
|
test("customer can create and cancel a package booking", async () => {
|
||||||
const service = await prisma.service.findFirst({
|
const service = await prisma.offering.findFirst({
|
||||||
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}` },
|
||||||
@@ -547,7 +542,7 @@ test("customer can create and cancel a package booking", async () => {
|
|||||||
customerName: "集成测试客户",
|
customerName: "集成测试客户",
|
||||||
wechatId: "integration-wechat",
|
wechatId: "integration-wechat",
|
||||||
contactPreference: "wechat",
|
contactPreference: "wechat",
|
||||||
items: [{ serviceId: service.id, quantity: 2 }],
|
items: [{ offeringId: service.id, quantity: 2 }],
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
assert.equal(created.statusCode, 201);
|
assert.equal(created.statusCode, 201);
|
||||||
@@ -557,7 +552,7 @@ test("customer can create and cancel a package booking", async () => {
|
|||||||
assert.ok(booking);
|
assert.ok(booking);
|
||||||
assert.equal(booking.workflowKey, "booking.basic");
|
assert.equal(booking.workflowKey, "booking.basic");
|
||||||
assert.equal(booking.currentState, "received");
|
assert.equal(booking.currentState, "received");
|
||||||
assert.equal(booking.offeringId, service.offeringId);
|
assert.equal(booking.offeringId, service.id);
|
||||||
const initialTransitions = await prisma.bookingStateTransition.findMany({
|
const initialTransitions = await prisma.bookingStateTransition.findMany({
|
||||||
where: { bookingId: booking.id },
|
where: { bookingId: booking.id },
|
||||||
});
|
});
|
||||||
@@ -582,7 +577,7 @@ test("customer can create and cancel a package booking", async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("admin can advance booking status but cannot skip the state machine", async () => {
|
test("admin can advance booking status but cannot skip the state machine", async () => {
|
||||||
const service = await prisma.service.findFirst({
|
const service = await prisma.offering.findFirst({
|
||||||
where: { brandId, isEnabled: true, priceAmount: { not: null } },
|
where: { brandId, isEnabled: true, priceAmount: { not: null } },
|
||||||
});
|
});
|
||||||
assert.ok(service);
|
assert.ok(service);
|
||||||
@@ -594,7 +589,7 @@ test("admin can advance booking status but cannot skip the state machine", async
|
|||||||
customerName: "状态测试客户",
|
customerName: "状态测试客户",
|
||||||
phone: "13800000000",
|
phone: "13800000000",
|
||||||
contactPreference: "phone",
|
contactPreference: "phone",
|
||||||
items: [{ serviceId: service.id, quantity: 1 }],
|
items: [{ offeringId: service.id, quantity: 1 }],
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const booking = await prisma.booking.findUnique({
|
const booking = await prisma.booking.findUnique({
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ Page({
|
|||||||
data: {
|
data: {
|
||||||
service: {},
|
service: {},
|
||||||
form: {},
|
form: {},
|
||||||
serviceId: "",
|
offeringId: "",
|
||||||
quantity: 1,
|
quantity: 1,
|
||||||
fulfillment: "pickup",
|
fulfillment: "pickup",
|
||||||
submitting: false,
|
submitting: false,
|
||||||
@@ -15,12 +15,12 @@ Page({
|
|||||||
.then(([services, brand]) => {
|
.then(([services, brand]) => {
|
||||||
const list = Array.isArray(services) ? services : [];
|
const list = Array.isArray(services) ? services : [];
|
||||||
const service =
|
const service =
|
||||||
list.find((item) => item.id === query.serviceId) ||
|
list.find((item) => item.id === query.offeringId || item.id === query.serviceId) ||
|
||||||
list.find((item) => item.priceAmount !== null) ||
|
list.find((item) => item.priceAmount !== null) ||
|
||||||
{};
|
{};
|
||||||
this.setData({
|
this.setData({
|
||||||
service,
|
service,
|
||||||
serviceId: service.id || "",
|
offeringId: service.id || "",
|
||||||
template: getTemplate(brand.templateKey),
|
template: getTemplate(brand.templateKey),
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
@@ -40,7 +40,7 @@ Page({
|
|||||||
},
|
},
|
||||||
submit() {
|
submit() {
|
||||||
const form = this.data.form;
|
const form = this.data.form;
|
||||||
if (!this.data.serviceId) return wx.showToast({ title: "请先选择服务", icon: "none" });
|
if (!this.data.offeringId) return wx.showToast({ title: "请先选择服务", icon: "none" });
|
||||||
if (!form.customerName || !form.wechatId)
|
if (!form.customerName || !form.wechatId)
|
||||||
return wx.showToast({ title: "请填写称呼和联系方式", icon: "none" });
|
return wx.showToast({ title: "请填写称呼和联系方式", icon: "none" });
|
||||||
if (this.data.fulfillment === "delivery" && !form.deliveryAddress)
|
if (this.data.fulfillment === "delivery" && !form.deliveryAddress)
|
||||||
@@ -58,7 +58,7 @@ Page({
|
|||||||
deliveryAddress: form.deliveryAddress,
|
deliveryAddress: form.deliveryAddress,
|
||||||
requestedTime: form.requestedTime,
|
requestedTime: form.requestedTime,
|
||||||
note: form.note,
|
note: form.note,
|
||||||
items: [{ serviceId: this.data.serviceId, quantity: this.data.quantity }],
|
items: [{ offeringId: this.data.offeringId, quantity: this.data.quantity }],
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ Page({
|
|||||||
},
|
},
|
||||||
selectService(event) {
|
selectService(event) {
|
||||||
wx.navigateTo({
|
wx.navigateTo({
|
||||||
url: "/pages/booking/index?serviceId=" + encodeURIComponent(event.currentTarget.dataset.id),
|
url: "/pages/booking/index?offeringId=" + encodeURIComponent(event.currentTarget.dataset.id),
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
goServices() {
|
goServices() {
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ Page({
|
|||||||
return wx.showToast({ title: "请从品牌主页查看联系方式", icon: "none" });
|
return wx.showToast({ title: "请从品牌主页查看联系方式", icon: "none" });
|
||||||
}
|
}
|
||||||
wx.navigateTo({
|
wx.navigateTo({
|
||||||
url: "/pages/booking/index?serviceId=" + encodeURIComponent(this.data.item?.id || ""),
|
url: "/pages/booking/index?offeringId=" + encodeURIComponent(this.data.item?.id || ""),
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -52,7 +52,7 @@ Page({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
wx.navigateTo({
|
wx.navigateTo({
|
||||||
url: "/pages/booking/index?serviceId=" + encodeURIComponent(e.currentTarget.dataset.id),
|
url: "/pages/booking/index?offeringId=" + encodeURIComponent(e.currentTarget.dataset.id),
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -60,7 +60,7 @@ export interface TrustContentInput {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface BookingItemInput {
|
export interface BookingItemInput {
|
||||||
serviceId: string;
|
offeringId: string;
|
||||||
quantity: number;
|
quantity: number;
|
||||||
}
|
}
|
||||||
export interface CreateBookingInput {
|
export interface CreateBookingInput {
|
||||||
@@ -70,7 +70,7 @@ export interface CreateBookingInput {
|
|||||||
wechatId?: string;
|
wechatId?: string;
|
||||||
contactPreference: ContactPreference;
|
contactPreference: ContactPreference;
|
||||||
fulfillmentType?: FulfillmentType;
|
fulfillmentType?: FulfillmentType;
|
||||||
serviceId?: string;
|
offeringId?: string;
|
||||||
requestedDate?: string;
|
requestedDate?: string;
|
||||||
requestedTime?: string;
|
requestedTime?: string;
|
||||||
deliveryAddress?: string;
|
deliveryAddress?: string;
|
||||||
|
|||||||
Reference in new issue
Block a user