refactor: 删除旧业务提供项路由
This commit is contained in:
1 parent
fe7005d4d0
commit
88cd8df40e
3 files changed
+7
-92
No files matched your search
@@ -26,32 +26,6 @@ export class UpdateBrandDto {
|
|||||||
@IsOptional() @IsObject() config?: Record<string, unknown>;
|
@IsOptional() @IsObject() config?: Record<string, unknown>;
|
||||||
}
|
}
|
||||||
|
|
||||||
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<string, unknown>;
|
|
||||||
}
|
|
||||||
|
|
||||||
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<string, unknown>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class CreateTrustContentDto {
|
export class CreateTrustContentDto {
|
||||||
@IsIn(["profile", "experience", "credential", "portfolio", "process", "testimonial"])
|
@IsIn(["profile", "experience", "credential", "portfolio", "process", "testimonial"])
|
||||||
type!: string;
|
type!: string;
|
||||||
|
|||||||
@@ -24,13 +24,11 @@ import { WechatAuthService } from "./wechat-auth.js";
|
|||||||
import { BookingService } from "./booking.service.js";
|
import { BookingService } from "./booking.service.js";
|
||||||
import { CreateBookingDto, CreateInquirySubmissionDto } from "./booking.dto.js";
|
import { CreateBookingDto, CreateInquirySubmissionDto } from "./booking.dto.js";
|
||||||
import {
|
import {
|
||||||
CreateServiceDto,
|
|
||||||
CreateTagDto,
|
CreateTagDto,
|
||||||
CreateTrustContentDto,
|
CreateTrustContentDto,
|
||||||
UpdateBookingStatusDto,
|
UpdateBookingStatusDto,
|
||||||
UpdateBookingTagsDto,
|
UpdateBookingTagsDto,
|
||||||
UpdateBrandDto,
|
UpdateBrandDto,
|
||||||
UpdateServiceDto,
|
|
||||||
UpdateTrustContentDto,
|
UpdateTrustContentDto,
|
||||||
} from "./admin.dto.js";
|
} from "./admin.dto.js";
|
||||||
import { AdminAuthService } from "./admin-auth.service.js";
|
import { AdminAuthService } from "./admin-auth.service.js";
|
||||||
@@ -76,19 +74,6 @@ export class PublicController {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get("services")
|
|
||||||
async services(): Promise<unknown> {
|
|
||||||
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")
|
@Controller("public/trust-content")
|
||||||
@@ -555,50 +540,6 @@ export class AdminConfigController {
|
|||||||
await this.prisma.trustContent.delete({ where: { id } });
|
await this.prisma.trustContent.delete({ where: { id } });
|
||||||
return { deleted: true };
|
return { deleted: true };
|
||||||
}
|
}
|
||||||
@Get("services")
|
|
||||||
listServices(@Req() request: FastifyRequest): Promise<unknown> {
|
|
||||||
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<unknown> {
|
|
||||||
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<unknown> {
|
|
||||||
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({
|
@Module({
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ test("health and public content are available without authentication", async ()
|
|||||||
assert.equal(brand.statusCode, 200);
|
assert.equal(brand.statusCode, 200);
|
||||||
assert.equal(JSON.parse(brand.body).name, "阿成家常菜");
|
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.equal(services.statusCode, 200);
|
||||||
assert.ok(JSON.parse(services.body).length >= 3);
|
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).description, "集成测试品牌简介");
|
||||||
assert.equal(JSON.parse(updatedBrand.body).templateKey, "personal");
|
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",
|
method: "PATCH",
|
||||||
headers: { authorization: `Bearer ${adminToken}` },
|
headers: { authorization: `Bearer ${adminToken}` },
|
||||||
payload: { priceText: "集成测试价格", sortOrder: 99 },
|
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(updatedService.statusCode, 200);
|
||||||
assert.equal(JSON.parse(updatedService.body).priceText, "集成测试价格");
|
assert.equal(JSON.parse(updatedService.body).priceText, "集成测试价格");
|
||||||
assert.equal(JSON.parse(updatedService.body).sortOrder, 99);
|
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);
|
assert.equal(publicServices.statusCode, 200);
|
||||||
const projectedService = JSON.parse(publicServices.body).find(
|
const projectedService = JSON.parse(publicServices.body).find(
|
||||||
(item) => item.id === serviceBefore.id,
|
(item) => item.id === serviceBefore.id,
|
||||||
);
|
);
|
||||||
assert.equal(projectedService.priceText, "集成测试价格");
|
assert.equal(projectedService.priceText, "集成测试价格");
|
||||||
|
|
||||||
const listedServices = await request("/admin/config/services", {
|
const listedServices = await request("/admin/workspace/offerings", {
|
||||||
headers: { authorization: `Bearer ${adminToken}` },
|
headers: { authorization: `Bearer ${adminToken}` },
|
||||||
});
|
});
|
||||||
assert.equal(listedServices.statusCode, 200);
|
assert.equal(listedServices.statusCode, 200);
|
||||||
assert.ok(JSON.parse(listedServices.body).some((item) => item.id === serviceBefore.id));
|
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",
|
method: "POST",
|
||||||
headers: { authorization: `Bearer ${adminToken}` },
|
headers: { authorization: `Bearer ${adminToken}` },
|
||||||
payload: {
|
payload: {
|
||||||
name: "集成测试通用服务",
|
name: "集成测试通用服务",
|
||||||
description: "通用品牌服务",
|
description: "通用品牌服务",
|
||||||
categoryKey: "consulting",
|
kind: "service",
|
||||||
config: { duration: 60 },
|
config: { duration: 60 },
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
assert.equal(createdService.statusCode, 201);
|
assert.equal(createdService.statusCode, 201);
|
||||||
const createdServiceBody = JSON.parse(createdService.body);
|
const createdServiceBody = JSON.parse(createdService.body);
|
||||||
createdServiceId = createdServiceBody.id;
|
createdServiceId = createdServiceBody.id;
|
||||||
assert.equal(createdServiceBody.kind, "consulting");
|
assert.equal(createdServiceBody.kind, "service");
|
||||||
const createdOffering = await prisma.offering.findUnique({
|
const createdOffering = await prisma.offering.findUnique({
|
||||||
where: { id: createdServiceBody.id },
|
where: { id: createdServiceBody.id },
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in new issue
Block a user