feat: 完成动态咨询表单公开读取与提交
This commit is contained in:
1 parent
4470302b3f
commit
1503f042e0
3 files changed
+70
-1
No files matched your search
@@ -5,6 +5,7 @@ import {
|
||||
IsInt,
|
||||
IsISO8601,
|
||||
IsOptional,
|
||||
IsObject,
|
||||
IsString,
|
||||
Max,
|
||||
Min,
|
||||
@@ -33,3 +34,8 @@ export class CreateBookingDto {
|
||||
@IsArray() @ValidateNested({ each: true }) @Type(() => BookingItemDto) items: BookingItemDto[] =
|
||||
[];
|
||||
}
|
||||
|
||||
export class CreateInquirySubmissionDto {
|
||||
@IsString() formId!: string;
|
||||
@IsObject() values!: Record<string, unknown>;
|
||||
}
|
||||
+54
-1
@@ -22,7 +22,7 @@ import type { NestFastifyApplication } from "@nestjs/platform-fastify";
|
||||
import { PrismaService } from "./prisma.service.js";
|
||||
import { WechatAuthService } from "./wechat-auth.js";
|
||||
import { BookingService } from "./booking.service.js";
|
||||
import { CreateBookingDto } from "./booking.dto.js";
|
||||
import { CreateBookingDto, CreateInquirySubmissionDto } from "./booking.dto.js";
|
||||
import {
|
||||
CreateServiceDto,
|
||||
CreateTagDto,
|
||||
@@ -176,6 +176,57 @@ export class PublicOfferingController {
|
||||
}
|
||||
}
|
||||
|
||||
@Controller("public/inquiry-forms")
|
||||
export class PublicInquiryFormController {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
@Get(":id")
|
||||
async get(@Param("id") id: string): Promise<unknown> {
|
||||
const form = await this.prisma.inquiryForm.findFirst({
|
||||
where: {
|
||||
id,
|
||||
brandId: process.env.DEFAULT_BRAND_ID ?? "00000000-0000-0000-0000-000000000001",
|
||||
isEnabled: true,
|
||||
},
|
||||
});
|
||||
if (!form) throw new BadRequestException("咨询表单不存在");
|
||||
return form;
|
||||
}
|
||||
}
|
||||
|
||||
@Controller("customer/inquiry-submissions")
|
||||
export class CustomerInquirySubmissionController {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
@Post()
|
||||
async create(
|
||||
@Req() request: FastifyRequest,
|
||||
@Body() body: CreateInquirySubmissionDto,
|
||||
): Promise<unknown> {
|
||||
const token = request.headers.authorization?.replace(/^Bearer\s+/i, "");
|
||||
if (!token) throw new UnauthorizedException("缺少客户登录态");
|
||||
let identity;
|
||||
try {
|
||||
identity = readIdentity(token);
|
||||
} catch {
|
||||
throw new UnauthorizedException("客户登录态无效或已过期");
|
||||
}
|
||||
if (identity.role !== "customer") throw new ForbiddenException("无客户权限");
|
||||
const form = await this.prisma.inquiryForm.findFirst({
|
||||
where: { id: body.formId, brandId: identity.brandId, isEnabled: true },
|
||||
});
|
||||
if (!form) throw new BadRequestException("咨询表单不存在");
|
||||
return this.prisma.inquirySubmission.create({
|
||||
data: {
|
||||
brandId: identity.brandId,
|
||||
inquiryFormId: form.id,
|
||||
formVersion: form.version,
|
||||
fieldsSnapshot: form.fieldsSnapshot as Prisma.InputJsonValue,
|
||||
values: body.values as Prisma.InputJsonValue,
|
||||
activeFields: Object.fromEntries(Object.keys(body.values).map((key) => [key, true])),
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Controller("admin/workspace")
|
||||
export class AdminWorkspaceController {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
@@ -789,6 +840,8 @@ export class AdminConfigController {
|
||||
PublicTemplateController,
|
||||
PublicWorkspaceController,
|
||||
PublicOfferingController,
|
||||
PublicInquiryFormController,
|
||||
CustomerInquirySubmissionController,
|
||||
AdminWorkspaceController,
|
||||
CustomerSessionController,
|
||||
AdminSessionController,
|
||||
|
||||
Reference in new issue
Block a user