feat: 完善业务提供项详情内容契约

This commit is contained in:
que01 committed 2026-09-20 09:04:10 +08:00
1 parent 0a96095e89
commit 8e46c2c293
3 files changed
+63 -5

No files matched your search

+16
View File
@@ -98,6 +98,14 @@ export class CreateOfferingDto {
@IsOptional() @IsInt() @Min(0) @Max(9999) sortOrder?: number; @IsOptional() @IsInt() @Min(0) @Max(9999) sortOrder?: number;
@IsOptional() @IsBoolean() isEnabled?: boolean; @IsOptional() @IsBoolean() isEnabled?: boolean;
@IsOptional() config?: Record<string, unknown>; @IsOptional() config?: Record<string, unknown>;
@IsOptional() sections?: Array<{
type: string;
title: string;
content?: string;
items?: unknown[];
}>;
@IsOptional() media?: Array<{ url: string; alt?: string; type?: string }>;
@IsOptional() cta?: { type: string; label: string; config?: Record<string, unknown> };
} }
export class UpdateOfferingDto { export class UpdateOfferingDto {
@@ -111,4 +119,12 @@ export class UpdateOfferingDto {
@IsOptional() @IsInt() @Min(0) @Max(9999) sortOrder?: number; @IsOptional() @IsInt() @Min(0) @Max(9999) sortOrder?: number;
@IsOptional() @IsBoolean() isEnabled?: boolean; @IsOptional() @IsBoolean() isEnabled?: boolean;
@IsOptional() config?: Record<string, unknown>; @IsOptional() config?: Record<string, unknown>;
@IsOptional() sections?: Array<{
type: string;
title: string;
content?: string;
items?: unknown[];
}>;
@IsOptional() media?: Array<{ url: string; alt?: string; type?: string }>;
@IsOptional() cta?: { type: string; label: string; config?: Record<string, unknown> };
} }
+28 -5
View File
@@ -161,7 +161,13 @@ export class PublicOfferingController {
}, },
}); });
if (!item) throw new BadRequestException("业务提供项不存在"); if (!item) throw new BadRequestException("业务提供项不存在");
return item; const config = (item.config ?? {}) as Record<string, unknown>;
return {
...item,
sections: config.sections ?? [],
media: config.media ?? [],
cta: config.cta ?? null,
};
} }
} }
@@ -187,12 +193,17 @@ export class AdminWorkspaceController {
@Body() body: CreateOfferingDto, @Body() body: CreateOfferingDto,
): Promise<unknown> { ): Promise<unknown> {
this.requireAdmin(request); this.requireAdmin(request);
const { config, ...fields } = body; const { config, sections, media, cta, ...fields } = body;
return this.prisma.offering.create({ return this.prisma.offering.create({
data: { data: {
...fields, ...fields,
brandId: this.brandId(), brandId: this.brandId(),
...(config === undefined ? {} : { config: config as Prisma.InputJsonValue }), config: {
...(config ?? {}),
...(sections === undefined ? {} : { sections }),
...(media === undefined ? {} : { media }),
...(cta === undefined ? {} : { cta }),
} as Prisma.InputJsonValue,
}, },
}); });
} }
@@ -206,12 +217,24 @@ export class AdminWorkspaceController {
this.requireAdmin(request); this.requireAdmin(request);
const item = await this.prisma.offering.findFirst({ where: { id, brandId: this.brandId() } }); const item = await this.prisma.offering.findFirst({ where: { id, brandId: this.brandId() } });
if (!item) throw new BadRequestException("业务提供项不存在"); if (!item) throw new BadRequestException("业务提供项不存在");
const { config, ...fields } = body; const { config, sections, media, cta, ...fields } = body;
return this.prisma.offering.update({ return this.prisma.offering.update({
where: { id }, where: { id },
data: { data: {
...fields, ...fields,
...(config === undefined ? {} : { config: config as Prisma.InputJsonValue }), ...(config === undefined &&
sections === undefined &&
media === undefined &&
cta === undefined
? {}
: {
config: {
...(config ?? {}),
...(sections === undefined ? {} : { sections }),
...(media === undefined ? {} : { media }),
...(cta === undefined ? {} : { cta }),
} as Prisma.InputJsonValue,
}),
}, },
}); });
} }
+19
View File
@@ -108,6 +108,22 @@ export interface BrandTemplateDefinition {
serviceCategories: string[]; serviceCategories: string[];
trustContentTypes: string[]; trustContentTypes: string[];
} }
export interface OfferingSection {
type: "text" | "image-list" | "timeline" | "faq";
title: string;
content?: string;
items?: unknown[];
}
export interface OfferingMedia {
url: string;
alt?: string;
type?: "image" | "video";
}
export interface OfferingCta {
type: "inquiry" | "booking" | "contact" | "external-link";
label: string;
config?: Record<string, unknown>;
}
export interface Offering { export interface Offering {
id: string; id: string;
brandId?: string; brandId?: string;
@@ -121,6 +137,9 @@ export interface Offering {
isEnabled: boolean; isEnabled: boolean;
sortOrder: number; sortOrder: number;
config?: Record<string, unknown> | null; config?: Record<string, unknown> | null;
sections?: OfferingSection[];
media?: OfferingMedia[];
cta?: OfferingCta;
} }
export class ApiClientError extends Error { export class ApiClientError extends Error {