feat: 实现小程序代码发布任务闭环
This commit is contained in:
1 parent
9b35b8e7a7
commit
526a9db789
14 files changed
+7242
-249
No files matched your search
@@ -32,6 +32,7 @@
|
||||
"class-transformer": "^0.5.1",
|
||||
"class-validator": "^0.14.1",
|
||||
"fastify": "^5.11.3",
|
||||
"miniprogram-ci": "^2.1.31",
|
||||
"prisma": "^6.2.1",
|
||||
"reflect-metadata": "^0.2.2",
|
||||
"rxjs": "^7.8.1"
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
CREATE TYPE "MiniAppReleaseStatus" AS ENUM ('built', 'uploaded', 'under_review', 'rejected', 'approved', 'published', 'failed');
|
||||
CREATE TABLE "MiniAppReleaseTask" (
|
||||
"id" TEXT NOT NULL,
|
||||
"brandId" TEXT NOT NULL,
|
||||
"releaseId" TEXT,
|
||||
"version" INTEGER NOT NULL,
|
||||
"status" "MiniAppReleaseStatus" NOT NULL DEFAULT 'built',
|
||||
"artifactPath" TEXT,
|
||||
"actorId" TEXT NOT NULL,
|
||||
"error" TEXT,
|
||||
"weappUploadId" TEXT,
|
||||
"audit" JSONB,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "MiniAppReleaseTask_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
CREATE INDEX "MiniAppReleaseTask_brandId_createdAt_idx" ON "MiniAppReleaseTask"("brandId", "createdAt" DESC);
|
||||
CREATE UNIQUE INDEX "MiniAppReleaseTask_brandId_version_key" ON "MiniAppReleaseTask"("brandId", "version");
|
||||
ALTER TABLE "MiniAppReleaseTask" ADD CONSTRAINT "MiniAppReleaseTask_brandId_fkey" FOREIGN KEY ("brandId") REFERENCES "BrandProfile"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
ALTER TABLE "MiniAppReleaseTask" ADD CONSTRAINT "MiniAppReleaseTask_releaseId_fkey" FOREIGN KEY ("releaseId") REFERENCES "BrandRelease"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
+268
-220
@@ -1,5 +1,5 @@
|
||||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
provider = "prisma-client-js"
|
||||
binaryTargets = ["linux-musl-openssl-3.0.x", "debian-openssl-3.0.x"]
|
||||
}
|
||||
|
||||
@@ -34,254 +34,298 @@ enum FulfillmentType {
|
||||
}
|
||||
|
||||
model BrandProfile {
|
||||
id String @id @default(uuid())
|
||||
slug String @unique @default("default-brand")
|
||||
name String
|
||||
templateKey String @default("food")
|
||||
tagline String?
|
||||
description String?
|
||||
avatarUrl String?
|
||||
coverUrl String?
|
||||
hours String?
|
||||
address String?
|
||||
deliveryNote String?
|
||||
contactPhone String?
|
||||
contactWechat String?
|
||||
config Json?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
bookings Booking[]
|
||||
customerUsers CustomerUser[]
|
||||
tags Tag[]
|
||||
trustContents TrustContent[]
|
||||
templateInstallations BrandTemplateInstallation[]
|
||||
fieldDefinitions BrandFieldDefinition[]
|
||||
offerings Offering[]
|
||||
inquiryForms InquiryForm[]
|
||||
inquirySubmissions InquirySubmission[]
|
||||
id String @id @default(uuid())
|
||||
slug String @unique @default("default-brand")
|
||||
name String
|
||||
templateKey String @default("food")
|
||||
tagline String?
|
||||
description String?
|
||||
avatarUrl String?
|
||||
coverUrl String?
|
||||
hours String?
|
||||
address String?
|
||||
deliveryNote String?
|
||||
contactPhone String?
|
||||
contactWechat String?
|
||||
config Json?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
bookings Booking[]
|
||||
customerUsers CustomerUser[]
|
||||
tags Tag[]
|
||||
trustContents TrustContent[]
|
||||
templateInstallations BrandTemplateInstallation[]
|
||||
fieldDefinitions BrandFieldDefinition[]
|
||||
offerings Offering[]
|
||||
inquiryForms InquiryForm[]
|
||||
inquirySubmissions InquirySubmission[]
|
||||
capabilityInstallations CapabilityInstallation[]
|
||||
capabilityAuditLogs CapabilityAuditLog[]
|
||||
adminMemberships BrandMembership[]
|
||||
releases BrandRelease[]
|
||||
capabilityAuditLogs CapabilityAuditLog[]
|
||||
adminMemberships BrandMembership[]
|
||||
releases BrandRelease[]
|
||||
miniAppReleases MiniAppReleaseTask[]
|
||||
}
|
||||
|
||||
model BrandRelease {
|
||||
id String @id @default(uuid())
|
||||
brandId String
|
||||
brand BrandProfile @relation(fields: [brandId], references: [id], onDelete: Cascade)
|
||||
version Int
|
||||
status String @default("published")
|
||||
snapshot Json
|
||||
actorId String
|
||||
note String?
|
||||
createdAt DateTime @default(now())
|
||||
revokedAt DateTime?
|
||||
revokedBy String?
|
||||
id String @id @default(uuid())
|
||||
brandId String
|
||||
brand BrandProfile @relation(fields: [brandId], references: [id], onDelete: Cascade)
|
||||
version Int
|
||||
status String @default("published")
|
||||
snapshot Json
|
||||
actorId String
|
||||
note String?
|
||||
createdAt DateTime @default(now())
|
||||
revokedAt DateTime?
|
||||
revokedBy String?
|
||||
miniAppReleases MiniAppReleaseTask[]
|
||||
|
||||
@@unique([brandId, version])
|
||||
@@index([brandId, status, createdAt])
|
||||
}
|
||||
|
||||
model CapabilityInstallation {
|
||||
id String @id @default(uuid())
|
||||
brandId String
|
||||
brand BrandProfile @relation(fields: [brandId], references: [id], onDelete: Cascade)
|
||||
capabilityKey String
|
||||
id String @id @default(uuid())
|
||||
brandId String
|
||||
brand BrandProfile @relation(fields: [brandId], references: [id], onDelete: Cascade)
|
||||
capabilityKey String
|
||||
capabilityVersion String
|
||||
status String @default("enabled")
|
||||
config Json?
|
||||
installedAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
status String @default("enabled")
|
||||
config Json?
|
||||
installedAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
@@unique([brandId, capabilityKey])
|
||||
@@index([brandId, status])
|
||||
}
|
||||
|
||||
enum MiniAppReleaseStatus {
|
||||
built
|
||||
uploaded
|
||||
under_review
|
||||
rejected
|
||||
approved
|
||||
published
|
||||
failed
|
||||
}
|
||||
|
||||
model MiniAppReleaseTask {
|
||||
id String @id @default(uuid())
|
||||
brandId String
|
||||
brand BrandProfile @relation(fields: [brandId], references: [id], onDelete: Cascade)
|
||||
releaseId String?
|
||||
release BrandRelease? @relation(fields: [releaseId], references: [id], onDelete: SetNull)
|
||||
version Int
|
||||
status MiniAppReleaseStatus @default(built)
|
||||
artifactPath String?
|
||||
actorId String
|
||||
error String?
|
||||
weappUploadId String?
|
||||
audit Json?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
@@unique([brandId, version])
|
||||
@@index([brandId, createdAt])
|
||||
}
|
||||
|
||||
model CapabilityAuditLog {
|
||||
id String @id @default(uuid())
|
||||
brandId String
|
||||
brand BrandProfile @relation(fields: [brandId], references: [id], onDelete: Cascade)
|
||||
id String @id @default(uuid())
|
||||
brandId String
|
||||
brand BrandProfile @relation(fields: [brandId], references: [id], onDelete: Cascade)
|
||||
capabilityKey String
|
||||
actorId String
|
||||
action String
|
||||
fromStatus String?
|
||||
toStatus String
|
||||
config Json?
|
||||
createdAt DateTime @default(now())
|
||||
actorId String
|
||||
action String
|
||||
fromStatus String?
|
||||
toStatus String
|
||||
config Json?
|
||||
createdAt DateTime @default(now())
|
||||
|
||||
@@index([brandId, capabilityKey, createdAt])
|
||||
}
|
||||
|
||||
model BrandTemplateInstallation {
|
||||
id String @id @default(uuid())
|
||||
brandId String
|
||||
brand BrandProfile @relation(fields: [brandId], references: [id], onDelete: Cascade)
|
||||
templateKey String
|
||||
templateVersion String @default("1.0.0")
|
||||
configSnapshot Json
|
||||
previousSnapshots Json @default("[]")
|
||||
installedAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
id String @id @default(uuid())
|
||||
brandId String
|
||||
brand BrandProfile @relation(fields: [brandId], references: [id], onDelete: Cascade)
|
||||
templateKey String
|
||||
templateVersion String @default("1.0.0")
|
||||
configSnapshot Json
|
||||
previousSnapshots Json @default("[]")
|
||||
installedAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
@@unique([brandId, templateKey])
|
||||
@@index([brandId])
|
||||
}
|
||||
|
||||
model BrandFieldDefinition {
|
||||
id String @id @default(uuid())
|
||||
brandId String
|
||||
brand BrandProfile @relation(fields: [brandId], references: [id], onDelete: Cascade)
|
||||
scope String
|
||||
key String
|
||||
label String
|
||||
type String
|
||||
required Boolean @default(false)
|
||||
isVisible Boolean @default(true)
|
||||
sortOrder Int @default(0)
|
||||
source String @default("custom")
|
||||
isOverridden Boolean @default(false)
|
||||
options Json?
|
||||
visibleWhen Json?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
id String @id @default(uuid())
|
||||
brandId String
|
||||
brand BrandProfile @relation(fields: [brandId], references: [id], onDelete: Cascade)
|
||||
scope String
|
||||
key String
|
||||
label String
|
||||
type String
|
||||
required Boolean @default(false)
|
||||
isVisible Boolean @default(true)
|
||||
sortOrder Int @default(0)
|
||||
source String @default("custom")
|
||||
isOverridden Boolean @default(false)
|
||||
options Json?
|
||||
visibleWhen Json?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
@@unique([brandId, scope, key])
|
||||
@@index([brandId, scope, sortOrder])
|
||||
}
|
||||
|
||||
model Offering {
|
||||
id String @id @default(uuid())
|
||||
brandId String
|
||||
brand BrandProfile @relation(fields: [brandId], references: [id], onDelete: Cascade)
|
||||
kind String @default("service")
|
||||
name String
|
||||
summary String?
|
||||
description String?
|
||||
coverUrl String?
|
||||
priceText String?
|
||||
priceAmount Int?
|
||||
isEnabled Boolean @default(true)
|
||||
sortOrder Int @default(0)
|
||||
config Json?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
inquiryForms InquiryForm[]
|
||||
id String @id @default(uuid())
|
||||
brandId String
|
||||
brand BrandProfile @relation(fields: [brandId], references: [id], onDelete: Cascade)
|
||||
kind String @default("service")
|
||||
name String
|
||||
summary String?
|
||||
description String?
|
||||
coverUrl String?
|
||||
priceText String?
|
||||
priceAmount Int?
|
||||
isEnabled Boolean @default(true)
|
||||
sortOrder Int @default(0)
|
||||
config Json?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
inquiryForms InquiryForm[]
|
||||
inquirySubmissions InquirySubmission[]
|
||||
bookings Booking[]
|
||||
bookingItems BookingItem[]
|
||||
bookings Booking[]
|
||||
bookingItems BookingItem[]
|
||||
|
||||
@@unique([brandId, name])
|
||||
@@index([brandId, isEnabled, sortOrder])
|
||||
}
|
||||
|
||||
model InquiryForm {
|
||||
id String @id @default(uuid())
|
||||
brandId String
|
||||
brand BrandProfile @relation(fields: [brandId], references: [id], onDelete: Cascade)
|
||||
offeringId String?
|
||||
offering Offering? @relation(fields: [offeringId], references: [id], onDelete: SetNull)
|
||||
name String
|
||||
purpose String @default("inquiry")
|
||||
targetType String @default("brand")
|
||||
submissionAction String @default("create-inquiry")
|
||||
version Int @default(1)
|
||||
isEnabled Boolean @default(true)
|
||||
fieldsSnapshot Json
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
submissions InquirySubmission[]
|
||||
id String @id @default(uuid())
|
||||
brandId String
|
||||
brand BrandProfile @relation(fields: [brandId], references: [id], onDelete: Cascade)
|
||||
offeringId String?
|
||||
offering Offering? @relation(fields: [offeringId], references: [id], onDelete: SetNull)
|
||||
name String
|
||||
purpose String @default("inquiry")
|
||||
targetType String @default("brand")
|
||||
submissionAction String @default("create-inquiry")
|
||||
version Int @default(1)
|
||||
isEnabled Boolean @default(true)
|
||||
fieldsSnapshot Json
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
submissions InquirySubmission[]
|
||||
|
||||
@@index([brandId, isEnabled])
|
||||
}
|
||||
|
||||
model InquirySubmission {
|
||||
id String @id @default(uuid())
|
||||
brandId String
|
||||
inquiryFormId String
|
||||
offeringId String?
|
||||
id String @id @default(uuid())
|
||||
brandId String
|
||||
inquiryFormId String
|
||||
offeringId String?
|
||||
customerSubject String
|
||||
brand BrandProfile @relation(fields: [brandId], references: [id], onDelete: Cascade)
|
||||
inquiryForm InquiryForm @relation(fields: [inquiryFormId], references: [id], onDelete: Restrict)
|
||||
offering Offering? @relation(fields: [offeringId], references: [id], onDelete: SetNull)
|
||||
formVersion Int
|
||||
fieldsSnapshot Json
|
||||
values Json
|
||||
activeFields Json
|
||||
status String @default("new")
|
||||
adminNote String?
|
||||
updatedAt DateTime @updatedAt
|
||||
statusHistory InquirySubmissionStatusHistory[]
|
||||
createdAt DateTime @default(now())
|
||||
brand BrandProfile @relation(fields: [brandId], references: [id], onDelete: Cascade)
|
||||
inquiryForm InquiryForm @relation(fields: [inquiryFormId], references: [id], onDelete: Restrict)
|
||||
offering Offering? @relation(fields: [offeringId], references: [id], onDelete: SetNull)
|
||||
formVersion Int
|
||||
fieldsSnapshot Json
|
||||
values Json
|
||||
activeFields Json
|
||||
status String @default("new")
|
||||
adminNote String?
|
||||
updatedAt DateTime @updatedAt
|
||||
statusHistory InquirySubmissionStatusHistory[]
|
||||
createdAt DateTime @default(now())
|
||||
|
||||
@@index([brandId, createdAt])
|
||||
@@index([brandId, customerSubject, createdAt])
|
||||
@@index([inquiryFormId, formVersion])
|
||||
}
|
||||
|
||||
model InquirySubmissionStatusHistory {
|
||||
id String @id @default(uuid())
|
||||
id String @id @default(uuid())
|
||||
submissionId String
|
||||
submission InquirySubmission @relation(fields: [submissionId], references: [id], onDelete: Cascade)
|
||||
fromStatus String?
|
||||
toStatus String
|
||||
adminNote String?
|
||||
createdAt DateTime @default(now())
|
||||
createdAt DateTime @default(now())
|
||||
|
||||
@@index([submissionId, createdAt])
|
||||
}
|
||||
|
||||
model TrustContent {
|
||||
id String @id @default(uuid())
|
||||
brandId String
|
||||
brand BrandProfile @relation(fields: [brandId], references: [id], onDelete: Cascade)
|
||||
type String
|
||||
title String
|
||||
summary String?
|
||||
content String
|
||||
coverUrl String?
|
||||
sortOrder Int @default(0)
|
||||
isPublished Boolean @default(true)
|
||||
config Json?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
id String @id @default(uuid())
|
||||
brandId String
|
||||
brand BrandProfile @relation(fields: [brandId], references: [id], onDelete: Cascade)
|
||||
type String
|
||||
title String
|
||||
summary String?
|
||||
content String
|
||||
coverUrl String?
|
||||
sortOrder Int @default(0)
|
||||
isPublished Boolean @default(true)
|
||||
config Json?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
@@index([brandId, type, sortOrder])
|
||||
}
|
||||
|
||||
model CustomerUser {
|
||||
id String @id @default(uuid())
|
||||
brandId String
|
||||
brand BrandProfile @relation(fields: [brandId], references: [id])
|
||||
openid String
|
||||
lastLoginAt DateTime @default(now())
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
bookings Booking[]
|
||||
id String @id @default(uuid())
|
||||
brandId String
|
||||
brand BrandProfile @relation(fields: [brandId], references: [id])
|
||||
openid String
|
||||
lastLoginAt DateTime @default(now())
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
bookings Booking[]
|
||||
|
||||
@@unique([brandId, openid])
|
||||
}
|
||||
|
||||
model Booking {
|
||||
id String @id @default(uuid())
|
||||
bookingNo String @unique
|
||||
brandId String
|
||||
brand BrandProfile @relation(fields: [brandId], references: [id])
|
||||
customerUserId String
|
||||
customerUser CustomerUser @relation(fields: [customerUserId], references: [id])
|
||||
requestType BookingRequestType
|
||||
customerName String
|
||||
phone String?
|
||||
wechatId String?
|
||||
contactPreference ContactPreference
|
||||
fulfillmentType FulfillmentType?
|
||||
offeringId String?
|
||||
offering Offering? @relation(fields: [offeringId], references: [id], onDelete: SetNull)
|
||||
requestedDate DateTime?
|
||||
requestedTime String?
|
||||
deliveryAddress String?
|
||||
estimatedAmount Int?
|
||||
extraData Json?
|
||||
note String?
|
||||
adminNote String?
|
||||
status BookingStatus @default(received)
|
||||
workflowKey String @default("booking.basic")
|
||||
workflowVersion String @default("1.0.0")
|
||||
currentState String @default("received")
|
||||
isRead Boolean @default(false)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
items BookingItem[]
|
||||
tags BookingTag[]
|
||||
stateTransitions BookingStateTransition[]
|
||||
id String @id @default(uuid())
|
||||
bookingNo String @unique
|
||||
brandId String
|
||||
brand BrandProfile @relation(fields: [brandId], references: [id])
|
||||
customerUserId String
|
||||
customerUser CustomerUser @relation(fields: [customerUserId], references: [id])
|
||||
requestType BookingRequestType
|
||||
customerName String
|
||||
phone String?
|
||||
wechatId String?
|
||||
contactPreference ContactPreference
|
||||
fulfillmentType FulfillmentType?
|
||||
offeringId String?
|
||||
offering Offering? @relation(fields: [offeringId], references: [id], onDelete: SetNull)
|
||||
requestedDate DateTime?
|
||||
requestedTime String?
|
||||
deliveryAddress String?
|
||||
estimatedAmount Int?
|
||||
extraData Json?
|
||||
note String?
|
||||
adminNote String?
|
||||
status BookingStatus @default(received)
|
||||
workflowKey String @default("booking.basic")
|
||||
workflowVersion String @default("1.0.0")
|
||||
currentState String @default("received")
|
||||
isRead Boolean @default(false)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
items BookingItem[]
|
||||
tags BookingTag[]
|
||||
stateTransitions BookingStateTransition[]
|
||||
|
||||
@@index([brandId, status, createdAt])
|
||||
@@index([customerUserId, createdAt])
|
||||
}
|
||||
@@ -296,57 +340,60 @@ model BookingStateTransition {
|
||||
toState String
|
||||
actorRole String
|
||||
createdAt DateTime @default(now())
|
||||
|
||||
@@index([bookingId, createdAt])
|
||||
}
|
||||
|
||||
model BookingItem {
|
||||
id String @id @default(uuid())
|
||||
bookingId String
|
||||
booking Booking @relation(fields: [bookingId], references: [id], onDelete: Cascade)
|
||||
offeringId String?
|
||||
offering Offering? @relation(fields: [offeringId], references: [id], onDelete: SetNull)
|
||||
id String @id @default(uuid())
|
||||
bookingId String
|
||||
booking Booking @relation(fields: [bookingId], references: [id], onDelete: Cascade)
|
||||
offeringId String?
|
||||
offering Offering? @relation(fields: [offeringId], references: [id], onDelete: SetNull)
|
||||
serviceNameSnapshot String
|
||||
unitPriceSnapshot Int
|
||||
quantity Int
|
||||
subtotalSnapshot Int
|
||||
unitPriceSnapshot Int
|
||||
quantity Int
|
||||
subtotalSnapshot Int
|
||||
}
|
||||
|
||||
model Tag {
|
||||
id String @id @default(uuid())
|
||||
brandId String
|
||||
brand BrandProfile @relation(fields: [brandId], references: [id])
|
||||
name String
|
||||
isPreset Boolean @default(false)
|
||||
isEnabled Boolean @default(true)
|
||||
createdAt DateTime @default(now())
|
||||
bookings BookingTag[]
|
||||
id String @id @default(uuid())
|
||||
brandId String
|
||||
brand BrandProfile @relation(fields: [brandId], references: [id])
|
||||
name String
|
||||
isPreset Boolean @default(false)
|
||||
isEnabled Boolean @default(true)
|
||||
createdAt DateTime @default(now())
|
||||
bookings BookingTag[]
|
||||
|
||||
@@unique([brandId, name])
|
||||
}
|
||||
|
||||
model AdminUser {
|
||||
id String @id @default(uuid())
|
||||
username String @unique
|
||||
passwordHash String
|
||||
displayName String
|
||||
role String @default("admin")
|
||||
isEnabled Boolean @default(true)
|
||||
mustChangePassword Boolean @default(false)
|
||||
lastLoginAt DateTime?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
memberships BrandMembership[]
|
||||
id String @id @default(uuid())
|
||||
username String @unique
|
||||
passwordHash String
|
||||
displayName String
|
||||
role String @default("admin")
|
||||
isEnabled Boolean @default(true)
|
||||
mustChangePassword Boolean @default(false)
|
||||
lastLoginAt DateTime?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
memberships BrandMembership[]
|
||||
}
|
||||
|
||||
model BrandMembership {
|
||||
id String @id @default(uuid())
|
||||
id String @id @default(uuid())
|
||||
adminUserId String
|
||||
brandId String
|
||||
role String @default("admin")
|
||||
isEnabled Boolean @default(true)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
adminUser AdminUser @relation(fields: [adminUserId], references: [id], onDelete: Cascade)
|
||||
brand BrandProfile @relation(fields: [brandId], references: [id], onDelete: Cascade)
|
||||
brandId String
|
||||
role String @default("admin")
|
||||
isEnabled Boolean @default(true)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
adminUser AdminUser @relation(fields: [adminUserId], references: [id], onDelete: Cascade)
|
||||
brand BrandProfile @relation(fields: [brandId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@unique([adminUserId, brandId])
|
||||
@@index([brandId, isEnabled])
|
||||
}
|
||||
@@ -356,5 +403,6 @@ model BookingTag {
|
||||
tagId String
|
||||
booking Booking @relation(fields: [bookingId], references: [id], onDelete: Cascade)
|
||||
tag Tag @relation(fields: [tagId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@id([bookingId, tagId])
|
||||
}
|
||||
@@ -26,6 +26,8 @@ import { AdminMembershipGuard } from "./admin-membership.guard.js";
|
||||
import { BrandReleaseService } from "./brand-release.service.js";
|
||||
import { BrandReleaseApiService } from "./brand-release-api.service.js";
|
||||
import { AdminReleaseController } from "./modules/admin/admin-release.controller.js";
|
||||
import { AdminMiniAppReleaseController } from "./modules/admin/admin-miniapp-release.controller.js";
|
||||
import { AdminMiniAppReleaseService } from "./modules/admin/admin-miniapp-release.service.js";
|
||||
import {
|
||||
CustomerSessionController,
|
||||
AdminSessionController,
|
||||
@@ -65,6 +67,7 @@ export class HealthController {
|
||||
AdminBookingController,
|
||||
AdminConfigController,
|
||||
AdminReleaseController,
|
||||
AdminMiniAppReleaseController,
|
||||
AdminUploadController,
|
||||
AdminLocalUploadController,
|
||||
],
|
||||
@@ -78,6 +81,7 @@ export class HealthController {
|
||||
AdminMembershipGuard,
|
||||
BrandReleaseService,
|
||||
BrandReleaseApiService,
|
||||
AdminMiniAppReleaseService,
|
||||
PublicBrandContextService,
|
||||
PublicWorkspaceService,
|
||||
AdminOfferingService,
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
import {
|
||||
BadRequestException,
|
||||
Body,
|
||||
Controller,
|
||||
Get,
|
||||
Param,
|
||||
Patch,
|
||||
Post,
|
||||
Req,
|
||||
} from "@nestjs/common";
|
||||
import type { FastifyRequest } from "fastify";
|
||||
import { existsSync } from "node:fs";
|
||||
import { resolve } from "node:path";
|
||||
import { AdminAccessService } from "../../admin-access.service.js";
|
||||
import { PrismaService } from "../../prisma.service.js";
|
||||
import { AdminMiniAppReleaseService } from "./admin-miniapp-release.service.js";
|
||||
import {
|
||||
CreateMiniAppReleaseDto,
|
||||
UpdateMiniAppReleaseStatusDto,
|
||||
UploadMiniAppReleaseDto,
|
||||
} from "./admin-miniapp-release.dto.js";
|
||||
|
||||
interface MiniprogramCi {
|
||||
Project: new (options: {
|
||||
projectPath: string;
|
||||
type: "miniProgram";
|
||||
appid: string;
|
||||
privateKey: string;
|
||||
}) => unknown;
|
||||
upload: (options: {
|
||||
project: unknown;
|
||||
version: string;
|
||||
desc: string;
|
||||
robot: number;
|
||||
setting: { es6: boolean; minified: boolean };
|
||||
}) => Promise<Record<string, unknown>>;
|
||||
}
|
||||
|
||||
@Controller("admin/miniapp-releases")
|
||||
export class AdminMiniAppReleaseController {
|
||||
constructor(
|
||||
private readonly access: AdminAccessService,
|
||||
private readonly releases: AdminMiniAppReleaseService,
|
||||
private readonly prisma: PrismaService,
|
||||
) {}
|
||||
|
||||
@Get()
|
||||
list(@Req() request: FastifyRequest): Promise<unknown[]> {
|
||||
return this.identity(request).then(({ brandId }) => this.releases.list(brandId));
|
||||
}
|
||||
|
||||
@Post()
|
||||
create(@Req() request: FastifyRequest, @Body() body: CreateMiniAppReleaseDto): Promise<unknown> {
|
||||
return this.identity(request).then(({ brandId, subject }) =>
|
||||
this.releases.create(brandId, subject, body),
|
||||
);
|
||||
}
|
||||
|
||||
@Post(":id/upload")
|
||||
async upload(
|
||||
@Req() request: FastifyRequest,
|
||||
@Param("id") taskId: string,
|
||||
@Body() body: UploadMiniAppReleaseDto,
|
||||
): Promise<unknown> {
|
||||
const identity = await this.identity(request);
|
||||
const task = await this.prisma.miniAppReleaseTask.findFirst({
|
||||
where: { id: taskId, brandId: identity.brandId },
|
||||
});
|
||||
if (!task) throw new BadRequestException("小程序发布任务不存在");
|
||||
if (task.status !== "built") throw new BadRequestException("当前小程序发布任务不能重复上传");
|
||||
const appid = this.requiredEnv("WECHAT_APP_ID");
|
||||
const privateKey = this.requiredEnv("WECHAT_UPLOAD_PRIVATE_KEY");
|
||||
const artifactPath = process.env.WEAPP_ARTIFACT_PATH;
|
||||
if (!artifactPath) throw new BadRequestException("WEAPP_ARTIFACT_PATH 未配置");
|
||||
const projectPath = resolve(artifactPath);
|
||||
if (!existsSync(projectPath) || !existsSync(resolve(projectPath, "app.json")))
|
||||
throw new BadRequestException("小程序构建产物不存在");
|
||||
const ci = (await import("miniprogram-ci")) as unknown as MiniprogramCi;
|
||||
const project = new ci.Project({
|
||||
projectPath,
|
||||
type: "miniProgram",
|
||||
appid,
|
||||
privateKey,
|
||||
});
|
||||
try {
|
||||
const result = await ci.upload({
|
||||
project,
|
||||
version: body.version ?? String(task.version),
|
||||
desc: body.desc ?? `brand content v${task.version}`,
|
||||
robot: body.robot ?? 1,
|
||||
setting: { es6: false, minified: true },
|
||||
});
|
||||
return this.releases.updateStatus(identity.brandId, identity.subject, taskId, {
|
||||
status: "uploaded",
|
||||
weappUploadId:
|
||||
typeof result.strUint64Version === "string"
|
||||
? result.strUint64Version
|
||||
: String(task.version),
|
||||
});
|
||||
} catch (error) {
|
||||
await this.releases.updateStatus(identity.brandId, identity.subject, taskId, {
|
||||
status: "failed",
|
||||
error: error instanceof Error ? error.message : "微信代码上传失败",
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
@Patch(":id/status")
|
||||
async updateStatus(
|
||||
@Req() request: FastifyRequest,
|
||||
@Param("id") taskId: string,
|
||||
@Body() body: UpdateMiniAppReleaseStatusDto,
|
||||
): Promise<unknown> {
|
||||
const identity = await this.identity(request);
|
||||
return this.releases.updateStatus(identity.brandId, identity.subject, taskId, body);
|
||||
}
|
||||
|
||||
private async identity(request: FastifyRequest): Promise<{ subject: string; brandId: string }> {
|
||||
const { subject, brandId } = await this.access.requireBrand(request);
|
||||
return { subject, brandId };
|
||||
}
|
||||
|
||||
private requiredEnv(name: string): string {
|
||||
const value = process.env[name];
|
||||
if (!value) throw new BadRequestException(`${name} 未配置`);
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import { Type } from "class-transformer";
|
||||
import { IsIn, IsOptional, IsString, IsUUID, MaxLength } from "class-validator";
|
||||
|
||||
export class CreateMiniAppReleaseDto {
|
||||
@IsOptional()
|
||||
@IsUUID()
|
||||
releaseId?: string;
|
||||
}
|
||||
|
||||
export class UpdateMiniAppReleaseStatusDto {
|
||||
@IsIn(["uploaded", "under_review", "approved", "rejected", "failed", "built", "published"])
|
||||
status!: "uploaded" | "under_review" | "approved" | "rejected" | "failed" | "built" | "published";
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@MaxLength(2000)
|
||||
error?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@MaxLength(200)
|
||||
weappUploadId?: string;
|
||||
}
|
||||
|
||||
export class UploadMiniAppReleaseDto {
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@MaxLength(100)
|
||||
version?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@MaxLength(500)
|
||||
desc?: string;
|
||||
|
||||
@IsOptional()
|
||||
@Type(() => Number)
|
||||
@IsIn([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
|
||||
robot?: number;
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
import {
|
||||
BadRequestException,
|
||||
ConflictException,
|
||||
Injectable,
|
||||
NotFoundException,
|
||||
} from "@nestjs/common";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { PrismaService } from "../../prisma.service.js";
|
||||
|
||||
const transitions: Record<string, string[]> = {
|
||||
built: ["uploaded", "under_review", "failed"],
|
||||
uploaded: ["under_review", "failed"],
|
||||
under_review: ["approved", "rejected", "failed"],
|
||||
approved: ["published", "failed"],
|
||||
rejected: [],
|
||||
failed: ["built"],
|
||||
published: [],
|
||||
};
|
||||
|
||||
@Injectable()
|
||||
export class AdminMiniAppReleaseService {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
|
||||
async list(brandId: string): Promise<unknown[]> {
|
||||
return this.prisma.miniAppReleaseTask.findMany({
|
||||
where: { brandId },
|
||||
orderBy: { createdAt: "desc" },
|
||||
take: 50,
|
||||
});
|
||||
}
|
||||
|
||||
async create(brandId: string, actorId: string, input: { releaseId?: string }): Promise<unknown> {
|
||||
return this.prisma.$transaction(
|
||||
async (tx) => {
|
||||
const release = input.releaseId
|
||||
? await tx.brandRelease.findFirst({ where: { id: input.releaseId, brandId } })
|
||||
: await tx.brandRelease.findFirst({
|
||||
where: { brandId, status: "published" },
|
||||
orderBy: { version: "desc" },
|
||||
});
|
||||
if (!release) throw new BadRequestException("请先发布品牌内容版本");
|
||||
const existing = await tx.miniAppReleaseTask.findUnique({
|
||||
where: { brandId_version: { brandId, version: release.version } },
|
||||
});
|
||||
if (existing) return existing;
|
||||
return tx.miniAppReleaseTask.create({
|
||||
data: {
|
||||
brandId,
|
||||
releaseId: release.id,
|
||||
version: release.version,
|
||||
actorId,
|
||||
status: "built",
|
||||
audit: { action: "created", actorId, at: new Date().toISOString() },
|
||||
},
|
||||
});
|
||||
},
|
||||
{ isolationLevel: Prisma.TransactionIsolationLevel.Serializable },
|
||||
);
|
||||
}
|
||||
|
||||
async updateStatus(
|
||||
brandId: string,
|
||||
actorId: string,
|
||||
taskId: string,
|
||||
input: {
|
||||
status:
|
||||
"uploaded" | "under_review" | "approved" | "rejected" | "failed" | "built" | "published";
|
||||
error?: string;
|
||||
weappUploadId?: string;
|
||||
},
|
||||
): Promise<unknown> {
|
||||
return this.prisma.$transaction(
|
||||
async (tx) => {
|
||||
const task = await tx.miniAppReleaseTask.findFirst({ where: { id: taskId, brandId } });
|
||||
if (!task) throw new NotFoundException("小程序发布任务不存在");
|
||||
if (!transitions[task.status]?.includes(input.status))
|
||||
throw new ConflictException("小程序发布状态不能按此顺序变更");
|
||||
const audit = this.audit(task.audit, {
|
||||
action: "status-updated",
|
||||
actorId,
|
||||
from: task.status,
|
||||
to: input.status,
|
||||
at: new Date().toISOString(),
|
||||
...(input.error ? { error: input.error } : {}),
|
||||
});
|
||||
const updated = await tx.miniAppReleaseTask.update({
|
||||
where: { id: task.id },
|
||||
data: {
|
||||
status: input.status,
|
||||
error: input.error ?? null,
|
||||
...(input.weappUploadId ? { weappUploadId: input.weappUploadId } : {}),
|
||||
audit,
|
||||
},
|
||||
});
|
||||
return {
|
||||
...updated,
|
||||
status: input.status,
|
||||
};
|
||||
},
|
||||
{ isolationLevel: Prisma.TransactionIsolationLevel.Serializable },
|
||||
);
|
||||
}
|
||||
|
||||
private audit(value: Prisma.JsonValue | null, entry: Record<string, unknown>) {
|
||||
return [...(Array.isArray(value) ? value : []), entry] as Prisma.InputJsonValue[];
|
||||
}
|
||||
}
|
||||
@@ -23,11 +23,79 @@ before(async () => {
|
||||
after(async () => {
|
||||
await app.close();
|
||||
await prisma.brandRelease.deleteMany({ where: { brandId } });
|
||||
await prisma.miniAppReleaseTask.deleteMany({ where: { brandId } });
|
||||
await prisma.booking.deleteMany({ where: { id: { in: createdBookingIds } } });
|
||||
await prisma.customerUser.deleteMany({ where: { openid } });
|
||||
await prisma.$disconnect();
|
||||
});
|
||||
|
||||
test("miniapp release tasks are authorized, idempotent, and state checked", async () => {
|
||||
const missing = await request("/admin/miniapp-releases");
|
||||
assert.equal(missing.statusCode, 401);
|
||||
assert.equal(
|
||||
(
|
||||
await request("/admin/miniapp-releases", {
|
||||
headers: { authorization: `Bearer ${customerToken}` },
|
||||
})
|
||||
).statusCode,
|
||||
403,
|
||||
);
|
||||
const login = await request("/admin/session/login", {
|
||||
method: "POST",
|
||||
payload: { username: "admin", password: process.env.SEED_ADMIN_PASSWORD },
|
||||
});
|
||||
const headers = { authorization: `Bearer ${JSON.parse(login.body).token}` };
|
||||
const current = JSON.parse((await request("/admin/releases", { headers })).body).find(
|
||||
(item) => item.status === "published",
|
||||
);
|
||||
assert.ok(current);
|
||||
const created = await request("/admin/miniapp-releases", {
|
||||
method: "POST",
|
||||
headers,
|
||||
payload: {},
|
||||
});
|
||||
assert.equal(created.statusCode, 201);
|
||||
assert.equal(JSON.parse(created.body).version, current.version);
|
||||
const repeated = await request("/admin/miniapp-releases", {
|
||||
method: "POST",
|
||||
headers,
|
||||
payload: {},
|
||||
});
|
||||
assert.equal(JSON.parse(repeated.body).id, JSON.parse(created.body).id);
|
||||
const taskId = JSON.parse(created.body).id;
|
||||
const skipped = await request(`/admin/miniapp-releases/${taskId}/status`, {
|
||||
method: "PATCH",
|
||||
headers,
|
||||
payload: { status: "published" },
|
||||
});
|
||||
assert.equal(skipped.statusCode, 409);
|
||||
const uploaded = await request(`/admin/miniapp-releases/${taskId}/status`, {
|
||||
method: "PATCH",
|
||||
headers,
|
||||
payload: { status: "uploaded", weappUploadId: "test-upload" },
|
||||
});
|
||||
assert.equal(uploaded.statusCode, 200);
|
||||
assert.equal(JSON.parse(uploaded.body).status, "uploaded");
|
||||
const underReview = await request(`/admin/miniapp-releases/${taskId}/status`, {
|
||||
method: "PATCH",
|
||||
headers,
|
||||
payload: { status: "under_review" },
|
||||
});
|
||||
assert.equal(JSON.parse(underReview.body).status, "under_review");
|
||||
const approved = await request(`/admin/miniapp-releases/${taskId}/status`, {
|
||||
method: "PATCH",
|
||||
headers,
|
||||
payload: { status: "approved" },
|
||||
});
|
||||
assert.equal(JSON.parse(approved.body).status, "approved");
|
||||
const published = await request(`/admin/miniapp-releases/${taskId}/status`, {
|
||||
method: "PATCH",
|
||||
headers,
|
||||
payload: { status: "published" },
|
||||
});
|
||||
assert.equal(JSON.parse(published.body).status, "published");
|
||||
});
|
||||
|
||||
test("real template declarations persist brand offering and trust bindings through draft and publication", async (context) => {
|
||||
const user = await prisma.adminUser.findUniqueOrThrow({ where: { username: "admin" } });
|
||||
const { runtimeContractForBinding } = await import("@personal-brand/types");
|
||||
|
||||
Reference in new issue
Block a user