feat: 建立工作流与能力注册表
This commit is contained in:
1 parent
c00e188392
commit
29d14378a7
5 files changed
+62
-5
No files matched your search
@@ -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({
|
||||
|
||||
@@ -41,7 +41,7 @@ import type { TransformFnParams } from "class-transformer";
|
||||
import { IsBoolean, IsEnum, IsOptional, IsString } from "class-validator";
|
||||
import { readIdentity, signIdentity } from "./auth.js";
|
||||
import { ApiExceptionFilter, RequestIdMiddleware } from "./http.js";
|
||||
import { getBrandTemplate } from "@personal-brand/config";
|
||||
import { getBrandTemplate, resolveCapabilities } from "@personal-brand/config";
|
||||
import { AdminWorkspaceController } from "./admin-workspace.controller.js";
|
||||
import { TemplateWorkspaceService } from "./template-workspace.service.js";
|
||||
|
||||
@@ -172,6 +172,7 @@ export class PublicWorkspaceController {
|
||||
}
|
||||
: null,
|
||||
capabilities: template?.capabilities ?? [],
|
||||
runtimeCapabilities: template ? resolveCapabilities(template.capabilities) : [],
|
||||
modules,
|
||||
runtimeModules,
|
||||
fields,
|
||||
|
||||
Reference in new issue
Block a user