feat: 增加品牌工作空间模块与字段配置接口
This commit is contained in:
1 parent
02aa698fb9
commit
6e1aca3e27
3 files changed
+162
No files matched your search
@@ -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")
|
||||
|
||||
Reference in new issue
Block a user