feat: 增加扩展配置校验器
This commit is contained in:
1 parent
29d14378a7
commit
8baa042255
7 files changed
+85
-32
No files matched your search
@@ -26,6 +26,7 @@ import {
|
||||
UpdateInquiryFormDto,
|
||||
} from "./admin.dto.js";
|
||||
import { TemplateWorkspaceService } from "./template-workspace.service.js";
|
||||
import { validateFieldSnapshot, validateOfferingConfig } from "@personal-brand/validation";
|
||||
|
||||
@Controller("admin/workspace")
|
||||
class AdminWorkspaceController {
|
||||
@@ -62,16 +63,19 @@ class AdminWorkspaceController {
|
||||
): Promise<unknown> {
|
||||
this.requireAdmin(request);
|
||||
const { config, sections, media, cta, ...fields } = body;
|
||||
const configValue = {
|
||||
...(config ?? {}),
|
||||
...(sections === undefined ? {} : { sections }),
|
||||
...(media === undefined ? {} : { media }),
|
||||
...(cta === undefined ? {} : { cta }),
|
||||
};
|
||||
const configIssues = validateOfferingConfig(configValue);
|
||||
if (configIssues.length) throw new BadRequestException("业务提供项配置无效");
|
||||
return this.prisma.offering.create({
|
||||
data: {
|
||||
...fields,
|
||||
brandId: this.brandId(),
|
||||
config: {
|
||||
...(config ?? {}),
|
||||
...(sections === undefined ? {} : { sections }),
|
||||
...(media === undefined ? {} : { media }),
|
||||
...(cta === undefined ? {} : { cta }),
|
||||
} as Prisma.InputJsonValue,
|
||||
config: configValue as Prisma.InputJsonValue,
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -86,6 +90,14 @@ class AdminWorkspaceController {
|
||||
const item = await this.prisma.offering.findFirst({ where: { id, brandId: this.brandId() } });
|
||||
if (!item) throw new BadRequestException("业务提供项不存在");
|
||||
const { config, sections, media, cta, ...fields } = body;
|
||||
const configValue = {
|
||||
...(config ?? {}),
|
||||
...(sections === undefined ? {} : { sections }),
|
||||
...(media === undefined ? {} : { media }),
|
||||
...(cta === undefined ? {} : { cta }),
|
||||
};
|
||||
if (validateOfferingConfig(configValue).length)
|
||||
throw new BadRequestException("业务提供项配置无效");
|
||||
return this.prisma.offering.update({
|
||||
where: { id },
|
||||
data: {
|
||||
@@ -96,12 +108,7 @@ class AdminWorkspaceController {
|
||||
cta === undefined
|
||||
? {}
|
||||
: {
|
||||
config: {
|
||||
...(config ?? {}),
|
||||
...(sections === undefined ? {} : { sections }),
|
||||
...(media === undefined ? {} : { media }),
|
||||
...(cta === undefined ? {} : { cta }),
|
||||
} as Prisma.InputJsonValue,
|
||||
config: configValue as Prisma.InputJsonValue,
|
||||
}),
|
||||
},
|
||||
});
|
||||
@@ -254,6 +261,8 @@ class AdminWorkspaceController {
|
||||
@Post("forms")
|
||||
createForm(@Req() request: FastifyRequest, @Body() body: CreateInquiryFormDto): Promise<unknown> {
|
||||
this.requireAdmin(request);
|
||||
if (validateFieldSnapshot(body.fieldsSnapshot).length)
|
||||
throw new BadRequestException("咨询表单字段定义无效");
|
||||
return this.prisma.inquiryForm.create({
|
||||
data: {
|
||||
...body,
|
||||
@@ -276,6 +285,8 @@ class AdminWorkspaceController {
|
||||
});
|
||||
if (!item) throw new BadRequestException("咨询表单不存在");
|
||||
const { fieldsSnapshot, ...fields } = body;
|
||||
if (fieldsSnapshot !== undefined && validateFieldSnapshot(fieldsSnapshot).length)
|
||||
throw new BadRequestException("咨询表单字段定义无效");
|
||||
return this.prisma.inquiryForm.update({
|
||||
where: { id },
|
||||
data: {
|
||||
|
||||
Reference in new issue
Block a user