refactor: 让开发初始化消费模板示例内容
This commit is contained in:
1 parent
6218ed395b
commit
17bd700c2b
1 file changed
+25
-3
+25
-3
@@ -646,13 +646,36 @@ const runtimeSeedTemplates: Record<"personal" | "food" | "doors", RuntimeSeedTem
|
|||||||
};
|
};
|
||||||
|
|
||||||
async function ensureRuntimeContent(brandId: string, template: RuntimeSeedTemplate): Promise<void> {
|
async function ensureRuntimeContent(brandId: string, template: RuntimeSeedTemplate): Promise<void> {
|
||||||
|
const packageSample = getTemplateSampleContent(template.templateKey);
|
||||||
|
const sampleOfferings = packageSample?.offerings ?? [];
|
||||||
|
const offerings = template.offerings.map((item, index) => ({
|
||||||
|
...item,
|
||||||
|
...(sampleOfferings[index]
|
||||||
|
? {
|
||||||
|
name: sampleOfferings[index].name,
|
||||||
|
summary: sampleOfferings[index].summary,
|
||||||
|
config: {
|
||||||
|
...item.config,
|
||||||
|
categoryKey: sampleOfferings[index].categoryKey,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
: {}),
|
||||||
|
}));
|
||||||
|
const trustContent = packageSample?.trustContent?.length
|
||||||
|
? packageSample.trustContent.map((item, index) => ({
|
||||||
|
...template.trustContent[index],
|
||||||
|
type: item.type,
|
||||||
|
title: item.title,
|
||||||
|
content: item.content,
|
||||||
|
}))
|
||||||
|
: template.trustContent;
|
||||||
await prisma.brandProfile.update({
|
await prisma.brandProfile.update({
|
||||||
where: { id: brandId },
|
where: { id: brandId },
|
||||||
data: {
|
data: {
|
||||||
config: template.brandConfig,
|
config: template.brandConfig,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
for (const [sortOrder, item] of template.offerings.entries()) {
|
for (const [sortOrder, item] of offerings.entries()) {
|
||||||
const offering = await prisma.offering.findUnique({
|
const offering = await prisma.offering.findUnique({
|
||||||
where: { brandId_name: { brandId, name: item.name } },
|
where: { brandId_name: { brandId, name: item.name } },
|
||||||
});
|
});
|
||||||
@@ -719,7 +742,7 @@ async function ensureRuntimeContent(brandId: string, template: RuntimeSeedTempla
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
for (const [sortOrder, item] of template.trustContent.entries()) {
|
for (const [sortOrder, item] of trustContent.entries()) {
|
||||||
const existing = await prisma.trustContent.findFirst({
|
const existing = await prisma.trustContent.findFirst({
|
||||||
where: { brandId, type: item.type, title: item.title },
|
where: { brandId, type: item.type, title: item.title },
|
||||||
});
|
});
|
||||||
@@ -731,7 +754,6 @@ async function ensureRuntimeContent(brandId: string, template: RuntimeSeedTempla
|
|||||||
where: { brandId, targetType: "brand" },
|
where: { brandId, targetType: "brand" },
|
||||||
orderBy: { createdAt: "asc" },
|
orderBy: { createdAt: "asc" },
|
||||||
});
|
});
|
||||||
const packageSample = getTemplateSampleContent(template.templateKey);
|
|
||||||
const formData = {
|
const formData = {
|
||||||
name: template.inquiryForm.name,
|
name: template.inquiryForm.name,
|
||||||
purpose: "inquiry",
|
purpose: "inquiry",
|
||||||
|
|||||||
Reference in new issue
Block a user