feat: 建立工作流与能力注册表

This commit is contained in:
que01 committed 2026-09-21 15:45:19 +08:00
1 parent c00e188392
commit 29d14378a7
5 files changed
+62 -5

No files matched your search

+5 -3
View File
@@ -1,7 +1,9 @@
import { BadRequestException, Injectable, NotFoundException } from "@nestjs/common";
import { BookingStatus, Prisma } from "@prisma/client";
import { PrismaService } from "./prisma.service.js";
import { BASIC_BOOKING_WORKFLOW, canTransitionBasicBooking } from "./workflows.js";
import { canTransitionWorkflow, workflowRegistry } from "@personal-brand/config";
const BASIC_BOOKING_WORKFLOW = workflowRegistry["booking.basic"];
export interface CreateBookingInput {
requestType: "package" | "private_chef" | "inquiry";
@@ -123,7 +125,7 @@ export class BookingService {
async cancelForCustomer(brandId: string, customerUserId: string, id: string) {
const booking = await this.prisma.booking.findFirst({ where: { id, brandId, customerUserId } });
if (!booking) throw new NotFoundException("订单不存在");
if (!canTransitionBasicBooking(booking.currentState, "cancelled"))
if (!canTransitionWorkflow(booking.workflowKey, booking.currentState, "cancelled"))
throw new BadRequestException("当前状态不可取消");
return this.prisma.$transaction(async (tx) => {
const updated = await tx.booking.update({
@@ -181,7 +183,7 @@ export class BookingService {
) {
const booking = await this.prisma.booking.findFirst({ where: { id, brandId } });
if (!booking) throw new NotFoundException("订单不存在");
if (!canTransitionBasicBooking(booking.currentState, status))
if (!canTransitionWorkflow(booking.workflowKey, booking.currentState, status))
throw new BadRequestException("不允许的订单状态流转");
return this.prisma.$transaction(async (tx) => {
const updated = await tx.booking.update({