feat: 增加业务提供项管理与详情接口

This commit is contained in:
que01 committed 2026-09-20 08:55:38 +08:00
1 parent a73e377f91
commit 066f6595e4
4 files changed
+152

No files matched your search

+18
View File
@@ -86,3 +86,21 @@ export class InstallTemplateDto {
@IsIn(["personal", "food"])
templateKey!: "personal" | "food";
}
export class CreateOfferingDto {
@IsIn(["service", "product", "package", "subscription"]) kind!: string;
@IsString() name!: string;
@IsOptional() @IsString() summary?: 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() isEnabled?: boolean;
@IsOptional() config?: Record<string, unknown>;
}
export class UpdateOfferingDto extends CreateOfferingDto {
@IsOptional() @IsIn(["service", "product", "package", "subscription"]) kind?: string;
@IsOptional() @IsString() name?: string;
}
+63
View File
@@ -33,6 +33,8 @@ import {
UpdateServiceDto,
UpdateTrustContentDto,
InstallTemplateDto,
CreateOfferingDto,
UpdateOfferingDto,
} from "./admin.dto.js";
import { AdminAuthService } from "./admin-auth.service.js";
import { AdminLoginDto } from "./admin-auth.dto.js";
@@ -146,12 +148,73 @@ export class PublicWorkspaceController {
}
}
@Controller("public/offerings")
export class PublicOfferingController {
constructor(private readonly prisma: PrismaService) {}
@Get(":id")
async get(@Param("id") id: string): Promise<unknown> {
const item = await this.prisma.offering.findFirst({
where: {
id,
brandId: process.env.DEFAULT_BRAND_ID ?? "00000000-0000-0000-0000-000000000001",
isEnabled: true,
},
});
if (!item) throw new BadRequestException("业务提供项不存在");
return item;
}
}
@Controller("admin/workspace")
export class AdminWorkspaceController {
constructor(private readonly prisma: PrismaService) {}
private brandId(): string {
return process.env.DEFAULT_BRAND_ID ?? "00000000-0000-0000-0000-000000000001";
}
@Get("offerings")
listOfferings(@Req() request: FastifyRequest): Promise<unknown> {
this.requireAdmin(request);
return this.prisma.offering.findMany({
where: { brandId: this.brandId() },
orderBy: { sortOrder: "asc" },
});
}
@Post("offerings")
createOffering(
@Req() request: FastifyRequest,
@Body() body: CreateOfferingDto,
): Promise<unknown> {
this.requireAdmin(request);
const { config, ...fields } = body;
return this.prisma.offering.create({
data: {
...fields,
brandId: this.brandId(),
...(config === undefined ? {} : { config: config as Prisma.InputJsonValue }),
},
});
}
@Patch("offerings/:id")
async updateOffering(
@Req() request: FastifyRequest,
@Param("id") id: string,
@Body() body: UpdateOfferingDto,
): Promise<unknown> {
this.requireAdmin(request);
const item = await this.prisma.offering.findFirst({ where: { id, brandId: this.brandId() } });
if (!item) throw new BadRequestException("业务提供项不存在");
const { config, ...fields } = body;
return this.prisma.offering.update({
where: { id },
data: {
...fields,
...(config === undefined ? {} : { config: config as Prisma.InputJsonValue }),
},
});
}
private requireAdmin(request: FastifyRequest): void {
const token = request.headers.authorization?.replace(/^Bearer\s+/i, "");
if (!token) throw new UnauthorizedException("缺少管理员登录态");