diff --git a/apps/api/src/admin.dto.ts b/apps/api/src/admin.dto.ts index ae4398c..7c78ff6 100644 --- a/apps/api/src/admin.dto.ts +++ b/apps/api/src/admin.dto.ts @@ -26,32 +26,6 @@ export class UpdateBrandDto { @IsOptional() @IsObject() config?: Record; } -export class UpdateServiceDto { - @IsOptional() @IsString() name?: string; - @IsOptional() @IsString() description?: string; - @IsOptional() @IsString() coverUrl?: string; - @IsOptional() @IsString() priceText?: string; - @IsOptional() @IsInt() @Min(0) priceAmount?: number; - @IsOptional() @IsInt() @Min(0) @Max(9999) sortOrder?: number; - @IsOptional() @IsBoolean() bookingEnabled?: boolean; - @IsOptional() @IsBoolean() isEnabled?: boolean; - @IsOptional() @IsString() categoryKey?: string; - @IsOptional() config?: Record; -} - -export class CreateServiceDto { - @IsString() name!: string; - @IsString() description!: string; - @IsOptional() @IsString() categoryKey?: string; - @IsOptional() @IsString() coverUrl?: string; - @IsOptional() @IsString() priceText?: string; - @IsOptional() @IsInt() @Min(0) priceAmount?: number; - @IsOptional() @IsInt() @Min(0) @Max(9999) sortOrder?: number; - @IsOptional() @IsBoolean() bookingEnabled?: boolean; - @IsOptional() @IsBoolean() isEnabled?: boolean; - @IsOptional() config?: Record; -} - export class CreateTrustContentDto { @IsIn(["profile", "experience", "credential", "portfolio", "process", "testimonial"]) type!: string; diff --git a/apps/api/src/main.ts b/apps/api/src/main.ts index eae2f88..02bd94b 100644 --- a/apps/api/src/main.ts +++ b/apps/api/src/main.ts @@ -24,13 +24,11 @@ import { WechatAuthService } from "./wechat-auth.js"; import { BookingService } from "./booking.service.js"; import { CreateBookingDto, CreateInquirySubmissionDto } from "./booking.dto.js"; import { - CreateServiceDto, CreateTagDto, CreateTrustContentDto, UpdateBookingStatusDto, UpdateBookingTagsDto, UpdateBrandDto, - UpdateServiceDto, UpdateTrustContentDto, } from "./admin.dto.js"; import { AdminAuthService } from "./admin-auth.service.js"; @@ -76,19 +74,6 @@ export class PublicController { }, }); } - - @Get("services") - async services(): Promise { - const offerings = await this.prisma.offering.findMany({ - where: { isEnabled: true }, - orderBy: { sortOrder: "asc" }, - }); - return offerings.map((offering) => ({ - ...offering, - bookingEnabled: true, - categoryKey: offering.kind, - })); - } } @Controller("public/trust-content") @@ -555,50 +540,6 @@ export class AdminConfigController { await this.prisma.trustContent.delete({ where: { id } }); return { deleted: true }; } - @Get("services") - listServices(@Req() request: FastifyRequest): Promise { - this.requireAdmin(request); - return this.prisma.offering.findMany({ - where: { brandId: this.brandId() }, - orderBy: { sortOrder: "asc" }, - }); - } - @Post("services") - async createService( - @Req() request: FastifyRequest, - @Body() body: CreateServiceDto, - ): Promise { - this.requireAdmin(request); - const { config, categoryKey, ...fields } = body; - const brandId = this.brandId(); - return this.prisma.offering.create({ - data: { - ...fields, - brandId, - kind: categoryKey ?? "service", - ...(config === undefined ? {} : { config: config as Prisma.InputJsonValue }), - }, - }); - } - @Patch("services/:id") - async updateService( - @Req() request: FastifyRequest, - @Param("id") id: string, - @Body() body: UpdateServiceDto, - ): Promise { - this.requireAdmin(request); - const item = await this.prisma.offering.findFirst({ where: { id, brandId: this.brandId() } }); - if (!item) throw new BadRequestException("业务提供项不存在"); - const { config, categoryKey, ...fields } = body; - return this.prisma.offering.update({ - where: { id }, - data: { - ...fields, - ...(categoryKey === undefined ? {} : { kind: categoryKey }), - ...(config === undefined ? {} : { config: config as Prisma.InputJsonValue }), - }, - }); - } } @Module({ diff --git a/apps/api/test/http.integration.test.js b/apps/api/test/http.integration.test.js index 0067809..26e75f3 100644 --- a/apps/api/test/http.integration.test.js +++ b/apps/api/test/http.integration.test.js @@ -41,7 +41,7 @@ test("health and public content are available without authentication", async () assert.equal(brand.statusCode, 200); assert.equal(JSON.parse(brand.body).name, "阿成家常菜"); - const services = await request("/public/services"); + const services = await request("/public/offerings"); assert.equal(services.statusCode, 200); assert.ok(JSON.parse(services.body).length >= 3); }); @@ -370,7 +370,7 @@ test("admin can read and update brand and service configuration", async () => { assert.equal(JSON.parse(updatedBrand.body).description, "集成测试品牌简介"); assert.equal(JSON.parse(updatedBrand.body).templateKey, "personal"); - const updatedService = await request(`/admin/config/services/${serviceBefore.id}`, { + const updatedService = await request(`/admin/workspace/offerings/${serviceBefore.id}`, { method: "PATCH", headers: { authorization: `Bearer ${adminToken}` }, payload: { priceText: "集成测试价格", sortOrder: 99 }, @@ -378,33 +378,33 @@ test("admin can read and update brand and service configuration", async () => { assert.equal(updatedService.statusCode, 200); assert.equal(JSON.parse(updatedService.body).priceText, "集成测试价格"); assert.equal(JSON.parse(updatedService.body).sortOrder, 99); - const publicServices = await request("/public/services"); + const publicServices = await request("/public/offerings"); assert.equal(publicServices.statusCode, 200); const projectedService = JSON.parse(publicServices.body).find( (item) => item.id === serviceBefore.id, ); assert.equal(projectedService.priceText, "集成测试价格"); - const listedServices = await request("/admin/config/services", { + const listedServices = await request("/admin/workspace/offerings", { headers: { authorization: `Bearer ${adminToken}` }, }); assert.equal(listedServices.statusCode, 200); assert.ok(JSON.parse(listedServices.body).some((item) => item.id === serviceBefore.id)); - const createdService = await request("/admin/config/services", { + const createdService = await request("/admin/workspace/offerings", { method: "POST", headers: { authorization: `Bearer ${adminToken}` }, payload: { name: "集成测试通用服务", description: "通用品牌服务", - categoryKey: "consulting", + kind: "service", config: { duration: 60 }, }, }); assert.equal(createdService.statusCode, 201); const createdServiceBody = JSON.parse(createdService.body); createdServiceId = createdServiceBody.id; - assert.equal(createdServiceBody.kind, "consulting"); + assert.equal(createdServiceBody.kind, "service"); const createdOffering = await prisma.offering.findUnique({ where: { id: createdServiceBody.id }, });