feat: 增加动态咨询表单配置接口
This commit is contained in:
1 parent
46c3e5504e
commit
32d3db90de
4 files changed
+124
No files matched your search
@@ -162,3 +162,17 @@ export class UpdateFieldDefinitionDto {
|
||||
@IsOptional() options?: unknown;
|
||||
@IsOptional() visibleWhen?: unknown;
|
||||
}
|
||||
|
||||
export class CreateInquiryFormDto {
|
||||
@IsString() name!: string;
|
||||
@IsOptional() @IsString() offeringId?: string;
|
||||
@IsArray() fieldsSnapshot!: unknown[];
|
||||
@IsOptional() @IsBoolean() isEnabled?: boolean;
|
||||
}
|
||||
|
||||
export class UpdateInquiryFormDto {
|
||||
@IsOptional() @IsString() name?: string;
|
||||
@IsOptional() @IsString() offeringId?: string;
|
||||
@IsOptional() @IsArray() fieldsSnapshot?: unknown[];
|
||||
@IsOptional() @IsBoolean() isEnabled?: boolean;
|
||||
}
|
||||
@@ -38,6 +38,8 @@ import {
|
||||
UpdateModuleDto,
|
||||
CreateFieldDefinitionDto,
|
||||
UpdateFieldDefinitionDto,
|
||||
CreateInquiryFormDto,
|
||||
UpdateInquiryFormDto,
|
||||
} from "./admin.dto.js";
|
||||
import { AdminAuthService } from "./admin-auth.service.js";
|
||||
import { AdminLoginDto } from "./admin-auth.dto.js";
|
||||
@@ -393,6 +395,52 @@ export class AdminWorkspaceController {
|
||||
await this.prisma.brandFieldDefinition.delete({ where: { id } });
|
||||
return { deleted: true };
|
||||
}
|
||||
|
||||
@Get("forms")
|
||||
listForms(@Req() request: FastifyRequest): Promise<unknown> {
|
||||
this.requireAdmin(request);
|
||||
return this.prisma.inquiryForm.findMany({
|
||||
where: { brandId: this.brandId() },
|
||||
orderBy: { updatedAt: "desc" },
|
||||
});
|
||||
}
|
||||
|
||||
@Post("forms")
|
||||
createForm(@Req() request: FastifyRequest, @Body() body: CreateInquiryFormDto): Promise<unknown> {
|
||||
this.requireAdmin(request);
|
||||
return this.prisma.inquiryForm.create({
|
||||
data: {
|
||||
...body,
|
||||
brandId: this.brandId(),
|
||||
version: 1,
|
||||
fieldsSnapshot: body.fieldsSnapshot as Prisma.InputJsonValue,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@Patch("forms/:id")
|
||||
async updateForm(
|
||||
@Req() request: FastifyRequest,
|
||||
@Param("id") id: string,
|
||||
@Body() body: UpdateInquiryFormDto,
|
||||
): Promise<unknown> {
|
||||
this.requireAdmin(request);
|
||||
const item = await this.prisma.inquiryForm.findFirst({
|
||||
where: { id, brandId: this.brandId() },
|
||||
});
|
||||
if (!item) throw new BadRequestException("咨询表单不存在");
|
||||
const { fieldsSnapshot, ...fields } = body;
|
||||
return this.prisma.inquiryForm.update({
|
||||
where: { id },
|
||||
data: {
|
||||
...fields,
|
||||
...(fieldsSnapshot === undefined
|
||||
? {}
|
||||
: { fieldsSnapshot: fieldsSnapshot as Prisma.InputJsonValue }),
|
||||
...(fieldsSnapshot === undefined ? {} : { version: { increment: 1 } }),
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Controller("customer/session")
|
||||
|
||||
Reference in new issue
Block a user