feat: 完善业务提供项详情内容契约
This commit is contained in:
1 parent
0a96095e89
commit
8e46c2c293
3 files changed
+63
-5
No files matched your search
@@ -98,6 +98,14 @@ export class CreateOfferingDto {
|
||||
@IsOptional() @IsInt() @Min(0) @Max(9999) sortOrder?: number;
|
||||
@IsOptional() @IsBoolean() isEnabled?: boolean;
|
||||
@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 {
|
||||
@@ -111,4 +119,12 @@ export class UpdateOfferingDto {
|
||||
@IsOptional() @IsInt() @Min(0) @Max(9999) sortOrder?: number;
|
||||
@IsOptional() @IsBoolean() isEnabled?: boolean;
|
||||
@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
@@ -161,7 +161,13 @@ export class PublicOfferingController {
|
||||
},
|
||||
});
|
||||
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,
|
||||
): Promise<unknown> {
|
||||
this.requireAdmin(request);
|
||||
const { config, ...fields } = body;
|
||||
const { config, sections, media, cta, ...fields } = body;
|
||||
return this.prisma.offering.create({
|
||||
data: {
|
||||
...fields,
|
||||
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);
|
||||
const item = await this.prisma.offering.findFirst({ where: { id, brandId: this.brandId() } });
|
||||
if (!item) throw new BadRequestException("业务提供项不存在");
|
||||
const { config, ...fields } = body;
|
||||
const { config, sections, media, cta, ...fields } = body;
|
||||
return this.prisma.offering.update({
|
||||
where: { id },
|
||||
data: {
|
||||
...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,
|
||||
}),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user