fix: 收口模板主模板策略与提供项响应契约
This commit is contained in:
1 parent
7e83d16cc9
commit
4470302b3f
2 files changed
+23
-6
No files matched your search
+17
-6
@@ -184,12 +184,21 @@ export class AdminWorkspaceController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Get("offerings")
|
@Get("offerings")
|
||||||
listOfferings(@Req() request: FastifyRequest): Promise<unknown> {
|
async listOfferings(@Req() request: FastifyRequest): Promise<unknown> {
|
||||||
this.requireAdmin(request);
|
this.requireAdmin(request);
|
||||||
return this.prisma.offering.findMany({
|
const items = await this.prisma.offering.findMany({
|
||||||
where: { brandId: this.brandId() },
|
where: { brandId: this.brandId() },
|
||||||
orderBy: { sortOrder: "asc" },
|
orderBy: { sortOrder: "asc" },
|
||||||
});
|
});
|
||||||
|
return items.map((item) => {
|
||||||
|
const config = (item.config ?? {}) as Record<string, unknown>;
|
||||||
|
return {
|
||||||
|
...item,
|
||||||
|
sections: config.sections ?? [],
|
||||||
|
media: config.media ?? [],
|
||||||
|
cta: config.cta ?? null,
|
||||||
|
};
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("offerings")
|
@Post("offerings")
|
||||||
@@ -279,10 +288,12 @@ export class AdminWorkspaceController {
|
|||||||
this.requireAdmin(request);
|
this.requireAdmin(request);
|
||||||
const brandId = this.brandId();
|
const brandId = this.brandId();
|
||||||
const template = brandTemplates[body.templateKey];
|
const template = brandTemplates[body.templateKey];
|
||||||
const existing = await this.prisma.brandTemplateInstallation.findUnique({
|
const existing = await this.prisma.brandTemplateInstallation.findFirst({ where: { brandId } });
|
||||||
where: { brandId_templateKey: { brandId, templateKey: body.templateKey } },
|
if (existing) {
|
||||||
});
|
if (existing.templateKey === body.templateKey)
|
||||||
if (existing) throw new BadRequestException("该模板已经安装");
|
throw new BadRequestException("该模板已经安装");
|
||||||
|
throw new BadRequestException("品牌已经安装主模板,请先完成模板切换流程");
|
||||||
|
}
|
||||||
const modules = [
|
const modules = [
|
||||||
["text", "品牌介绍"],
|
["text", "品牌介绍"],
|
||||||
["trust-content", "信任证明"],
|
["trust-content", "信任证明"],
|
||||||
|
|||||||
@@ -71,6 +71,12 @@ test("admin can install a template and public workspace exposes enabled configur
|
|||||||
const publicWorkspace = await request("/public/workspace");
|
const publicWorkspace = await request("/public/workspace");
|
||||||
assert.equal(publicWorkspace.statusCode, 200);
|
assert.equal(publicWorkspace.statusCode, 200);
|
||||||
assert.equal(JSON.parse(publicWorkspace.body).modules.length, 4);
|
assert.equal(JSON.parse(publicWorkspace.body).modules.length, 4);
|
||||||
|
const conflict = await request("/admin/workspace/install", {
|
||||||
|
method: "POST",
|
||||||
|
headers: { authorization: `Bearer ${token}` },
|
||||||
|
payload: { templateKey: "food" },
|
||||||
|
});
|
||||||
|
assert.equal(conflict.statusCode, 400);
|
||||||
} finally {
|
} finally {
|
||||||
await prisma.brandFieldDefinition.deleteMany({ where: { brandId } });
|
await prisma.brandFieldDefinition.deleteMany({ where: { brandId } });
|
||||||
await prisma.brandModule.deleteMany({ where: { brandId } });
|
await prisma.brandModule.deleteMany({ where: { brandId } });
|
||||||
|
|||||||
Reference in new issue
Block a user