fix: 保证示例内容导入幂等

This commit is contained in:
que01 committed 2026-09-23 02:04:32 +08:00
1 parent 3f42388fb3
commit fef0a890ad
2 files changed
+5 -2

No files matched your search

+4 -1
View File
@@ -224,7 +224,10 @@ class AdminWorkspaceController {
const existing = await this.prisma.brandFieldDefinition.count({ const existing = await this.prisma.brandFieldDefinition.count({
where: { brandId, source: "sample" }, where: { brandId, source: "sample" },
}); });
if (existing) throw new BadRequestException("示例内容已经导入"); const existingOffering = await this.prisma.offering.count({
where: { brandId, name: "序章·入户门" },
});
if (existing || existingOffering) throw new BadRequestException("示例内容已经导入");
const result = await this.prisma.$transaction(async (tx) => { const result = await this.prisma.$transaction(async (tx) => {
const offerings = await tx.offering.createMany({ const offerings = await tx.offering.createMany({
data: [ data: [
+1 -1
View File
@@ -213,7 +213,7 @@ test("admin can preview and import sample content idempotently", async () => {
await prisma.offering.deleteMany({ await prisma.offering.deleteMany({
where: { where: {
brandId, brandId,
categoryKey: { in: ["entrance-door", "garden-door", "interior-door", "custom"] }, name: { in: ["序章·入户门", "庭院·边界门", "室内·静谧门", "一对一门系统设计咨询"] },
}, },
}); });
await prisma.trustContent.deleteMany({ await prisma.trustContent.deleteMany({