feat: 增加个人品牌信任内容管理接口
This commit is contained in:
1 parent
60db0a85db
commit
b7fbfa1646
5 files changed
+60
-1
No files matched your search
@@ -0,0 +1,2 @@
|
||||
CREATE TABLE "TrustContent" ("id" TEXT NOT NULL,"brandId" TEXT NOT NULL,"type" TEXT NOT NULL,"title" TEXT NOT NULL,"summary" TEXT,"content" TEXT NOT NULL,"coverUrl" TEXT,"sortOrder" INTEGER NOT NULL DEFAULT 0,"isPublished" BOOLEAN NOT NULL DEFAULT true,"config" JSONB,"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,"updatedAt" TIMESTAMP(3) NOT NULL,CONSTRAINT "TrustContent_pkey" PRIMARY KEY ("id"),CONSTRAINT "TrustContent_brandId_fkey" FOREIGN KEY ("brandId") REFERENCES "BrandProfile"("id") ON DELETE CASCADE ON UPDATE CASCADE);
|
||||
CREATE INDEX "TrustContent_brandId_type_sortOrder_idx" ON "TrustContent"("brandId","type","sortOrder");
|
||||
@@ -51,6 +51,7 @@ model BrandProfile {
|
||||
bookings Booking[]
|
||||
customerUsers CustomerUser[]
|
||||
tags Tag[]
|
||||
trustContents TrustContent[]
|
||||
}
|
||||
|
||||
model Service {
|
||||
@@ -75,6 +76,23 @@ model Service {
|
||||
@@index([brandId, isEnabled, sortOrder])
|
||||
}
|
||||
|
||||
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
|
||||
@@index([brandId, type, sortOrder])
|
||||
}
|
||||
|
||||
model CustomerUser {
|
||||
id String @id @default(uuid())
|
||||
brandId String
|
||||
|
||||
@@ -40,6 +40,17 @@ export class CreateServiceDto {
|
||||
@IsOptional() config?: Record<string, unknown>;
|
||||
}
|
||||
|
||||
export class CreateTrustContentDto {
|
||||
@IsIn(["profile", "experience", "credential", "portfolio", "process", "testimonial"]) type!: string;
|
||||
@IsString() title!: string;
|
||||
@IsOptional() @IsString() summary?: string;
|
||||
@IsString() content!: string;
|
||||
@IsOptional() @IsString() coverUrl?: string;
|
||||
@IsOptional() @IsInt() @Min(0) @Max(9999) sortOrder?: number;
|
||||
@IsOptional() @IsBoolean() isPublished?: boolean;
|
||||
@IsOptional() config?: Record<string, unknown>;
|
||||
}
|
||||
|
||||
export class UpdateBookingStatusDto {
|
||||
@IsIn(["received", "contacting", "confirmed", "completed", "cancelled"])
|
||||
status!: "received" | "contacting" | "confirmed" | "completed" | "cancelled";
|
||||
|
||||
+10
-1
@@ -3,6 +3,7 @@ import {
|
||||
BadRequestException,
|
||||
Body,
|
||||
Controller,
|
||||
Delete,
|
||||
Get,
|
||||
Module,
|
||||
Param,
|
||||
@@ -20,7 +21,7 @@ import { PrismaService } from "./prisma.service.js";
|
||||
import { WechatAuthService } from "./wechat-auth.js";
|
||||
import { BookingService } from "./booking.service.js";
|
||||
import { CreateBookingDto } from "./booking.dto.js";
|
||||
import { CreateServiceDto, CreateTagDto, UpdateBookingStatusDto, UpdateBookingTagsDto, UpdateBrandDto, UpdateServiceDto } from "./admin.dto.js";
|
||||
import { CreateServiceDto, CreateTagDto, CreateTrustContentDto, UpdateBookingStatusDto, UpdateBookingTagsDto, UpdateBrandDto, UpdateServiceDto } from "./admin.dto.js";
|
||||
import { AdminAuthService } from "./admin-auth.service.js";
|
||||
import { AdminLoginDto } from "./admin-auth.dto.js";
|
||||
import type { FastifyRequest } from "fastify";
|
||||
@@ -296,6 +297,14 @@ export class AdminConfigController {
|
||||
getBrand(@Req() request: FastifyRequest): Promise<unknown> { this.requireAdmin(request); return this.prisma.brandProfile.findUnique({ where: { id: this.brandId() } }); }
|
||||
@Patch("brand")
|
||||
updateBrand(@Req() request: FastifyRequest, @Body() body: UpdateBrandDto): Promise<unknown> { this.requireAdmin(request); return this.prisma.brandProfile.update({ where: { id: this.brandId() }, data: body }); }
|
||||
@Get("trust-content")
|
||||
listTrustContent(@Req() request: FastifyRequest): Promise<unknown> { this.requireAdmin(request); return this.prisma.trustContent.findMany({ where: { brandId: this.brandId() }, orderBy: [{ type: "asc" }, { sortOrder: "asc" }] }); }
|
||||
@Post("trust-content")
|
||||
createTrustContent(@Req() request: FastifyRequest, @Body() body: CreateTrustContentDto): Promise<unknown> { this.requireAdmin(request); const { config, ...fields } = body; return this.prisma.trustContent.create({ data: { ...fields, brandId: this.brandId(), ...(config === undefined ? {} : { config: config as Prisma.InputJsonValue }) } }); }
|
||||
@Patch("trust-content/:id")
|
||||
async updateTrustContent(@Req() request: FastifyRequest, @Param("id") id: string, @Body() body: Partial<CreateTrustContentDto>): Promise<unknown> { this.requireAdmin(request); const item = await this.prisma.trustContent.findFirst({ where: { id, brandId: this.brandId() } }); if (!item) throw new BadRequestException("信任内容不存在"); const { config, ...fields } = body; return this.prisma.trustContent.update({ where: { id }, data: { ...fields, ...(config === undefined ? {} : { config: config as Prisma.InputJsonValue }) } }); }
|
||||
@Delete("trust-content/:id")
|
||||
async deleteTrustContent(@Req() request: FastifyRequest, @Param("id") id: string): Promise<unknown> { this.requireAdmin(request); const item = await this.prisma.trustContent.findFirst({ where: { id, brandId: this.brandId() } }); if (!item) throw new BadRequestException("信任内容不存在"); await this.prisma.trustContent.delete({ where: { id } }); return { deleted: true }; }
|
||||
@Get("services")
|
||||
listServices(@Req() request: FastifyRequest): Promise<unknown> { this.requireAdmin(request); return this.prisma.service.findMany({ where: { brandId: this.brandId() }, orderBy: { sortOrder: "asc" } }); }
|
||||
@Post("services")
|
||||
|
||||
@@ -142,6 +142,25 @@ test("admin can read and update brand and service configuration", async () => {
|
||||
}
|
||||
});
|
||||
|
||||
test("admin can manage trust content", async () => {
|
||||
const login = await request("/admin/session/login", { method: "POST", payload: { username: "admin", password: process.env.SEED_ADMIN_PASSWORD } });
|
||||
const token = JSON.parse(login.body).token;
|
||||
assert.equal((await request("/admin/config/trust-content")).statusCode, 400);
|
||||
const created = await request("/admin/config/trust-content", { method: "POST", headers: { authorization: `Bearer ${token}` }, payload: { type: "profile", title: "关于我", content: "集成测试内容", summary: "测试摘要" } });
|
||||
assert.equal(created.statusCode, 201);
|
||||
const id = JSON.parse(created.body).id;
|
||||
try {
|
||||
const list = await request("/admin/config/trust-content", { headers: { authorization: `Bearer ${token}` } });
|
||||
assert.equal(list.statusCode, 200);
|
||||
const updated = await request(`/admin/config/trust-content/${id}`, { method: "PATCH", headers: { authorization: `Bearer ${token}` }, payload: { content: "更新后的内容" } });
|
||||
assert.equal(updated.statusCode, 200);
|
||||
assert.equal(JSON.parse(updated.body).content, "更新后的内容");
|
||||
} finally {
|
||||
const deleted = await request(`/admin/config/trust-content/${id}`, { method: "DELETE", headers: { authorization: `Bearer ${token}` } });
|
||||
assert.equal(deleted.statusCode, 200);
|
||||
}
|
||||
});
|
||||
|
||||
test("customer booking endpoints require a valid customer session", async () => {
|
||||
const missing = await request("/customer/bookings");
|
||||
assert.equal(missing.statusCode, 400);
|
||||
|
||||
Reference in new issue
Block a user