feat: 增加品牌工作空间模块与字段配置接口

This commit is contained in:
que01 committed 2026-09-20 09:27:28 +08:00
1 parent 02aa698fb9
commit 6e1aca3e27
3 files changed
+162

No files matched your search

+34
View File
@@ -128,3 +128,37 @@ export class UpdateOfferingDto {
@IsOptional() media?: Array<{ url: string; alt?: string; type?: string }>;
@IsOptional() cta?: { type: string; label: string; config?: Record<string, unknown> };
}
export class UpdateModuleDto {
@IsOptional() @IsString() title?: string;
@IsOptional() @IsBoolean() isEnabled?: boolean;
@IsOptional() @IsInt() @Min(0) @Max(9999) sortOrder?: number;
@IsOptional() config?: Record<string, unknown>;
}
export class CreateFieldDefinitionDto {
@IsString() scope!: string;
@IsString() key!: string;
@IsString() label!: string;
@IsIn(["text", "textarea", "number", "date", "select", "multi-select", "image", "url", "phone"])
type!: string;
@IsOptional() @IsBoolean() required?: boolean;
@IsOptional() @IsBoolean() isVisible?: boolean;
@IsOptional() @IsInt() @Min(0) @Max(9999) sortOrder?: number;
@IsOptional() options?: unknown;
@IsOptional() visibleWhen?: unknown;
}
export class UpdateFieldDefinitionDto {
@IsOptional() @IsString() scope?: string;
@IsOptional() @IsString() key?: string;
@IsOptional() @IsString() label?: string;
@IsOptional()
@IsIn(["text", "textarea", "number", "date", "select", "multi-select", "image", "url", "phone"])
type?: string;
@IsOptional() @IsBoolean() required?: boolean;
@IsOptional() @IsBoolean() isVisible?: boolean;
@IsOptional() @IsInt() @Min(0) @Max(9999) sortOrder?: number;
@IsOptional() options?: unknown;
@IsOptional() visibleWhen?: unknown;
}
+74
View File
@@ -35,6 +35,9 @@ import {
InstallTemplateDto,
CreateOfferingDto,
UpdateOfferingDto,
UpdateModuleDto,
CreateFieldDefinitionDto,
UpdateFieldDefinitionDto,
} from "./admin.dto.js";
import { AdminAuthService } from "./admin-auth.service.js";
import { AdminLoginDto } from "./admin-auth.dto.js";
@@ -319,6 +322,77 @@ export class AdminWorkspaceController {
return { installation, template };
});
}
@Patch("modules/:id")
async updateModule(
@Req() request: FastifyRequest,
@Param("id") id: string,
@Body() body: UpdateModuleDto,
): Promise<unknown> {
this.requireAdmin(request);
const item = await this.prisma.brandModule.findFirst({
where: { id, brandId: this.brandId() },
});
if (!item) throw new BadRequestException("品牌模块不存在");
const { config, ...fields } = body;
return this.prisma.brandModule.update({
where: { id },
data: {
...fields,
...(config === undefined ? {} : { config: config as Prisma.InputJsonValue }),
},
});
}
@Post("fields")
createField(
@Req() request: FastifyRequest,
@Body() body: CreateFieldDefinitionDto,
): Promise<unknown> {
this.requireAdmin(request);
return this.prisma.brandFieldDefinition.create({
data: {
...body,
brandId: this.brandId(),
source: "custom",
options: body.options as Prisma.InputJsonValue,
visibleWhen: body.visibleWhen as Prisma.InputJsonValue,
},
});
}
@Patch("fields/:id")
async updateField(
@Req() request: FastifyRequest,
@Param("id") id: string,
@Body() body: UpdateFieldDefinitionDto,
): Promise<unknown> {
this.requireAdmin(request);
const item = await this.prisma.brandFieldDefinition.findFirst({
where: { id, brandId: this.brandId() },
});
if (!item) throw new BadRequestException("品牌字段不存在");
const { options, visibleWhen, ...fields } = body;
return this.prisma.brandFieldDefinition.update({
where: { id },
data: {
...fields,
...(options === undefined ? {} : { options: options as Prisma.InputJsonValue }),
...(visibleWhen === undefined ? {} : { visibleWhen: visibleWhen as Prisma.InputJsonValue }),
},
});
}
@Delete("fields/:id")
async deleteField(@Req() request: FastifyRequest, @Param("id") id: string): Promise<unknown> {
this.requireAdmin(request);
const item = await this.prisma.brandFieldDefinition.findFirst({
where: { id, brandId: this.brandId(), source: "custom" },
});
if (!item) throw new BadRequestException("自定义字段不存在或不可删除");
await this.prisma.brandFieldDefinition.delete({ where: { id } });
return { deleted: true };
}
}
@Controller("customer/session")