fix: 固定默认品牌解析避免多品牌串线
This commit is contained in:
1 parent
045472035b
commit
cbe9d26288
4 files changed
+58
-2
No files matched your search
@@ -74,6 +74,54 @@ async function main(): Promise<void> {
|
|||||||
update: { isEnabled: true, role: "owner" },
|
update: { isEnabled: true, role: "owner" },
|
||||||
create: { adminUserId: admin.id, brandId: brand.id, role: "owner" },
|
create: { adminUserId: admin.id, brandId: brand.id, role: "owner" },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const doorsBrand = await prisma.brandProfile.upsert({
|
||||||
|
where: { id: "00000000-0000-0000-0000-000000000002" },
|
||||||
|
update: {},
|
||||||
|
create: {
|
||||||
|
id: "00000000-0000-0000-0000-000000000002",
|
||||||
|
slug: "linjing-doors",
|
||||||
|
name: "林境门作",
|
||||||
|
templateKey: "doors",
|
||||||
|
tagline: "为别墅空间定制有秩序感的门系统",
|
||||||
|
description: "从入户大门到室内户内门,提供完整的门系统设计与落地服务。",
|
||||||
|
hours: "周一至周六 09:00-18:00",
|
||||||
|
address: "城市设计中心 3F",
|
||||||
|
contactPhone: "13800000000",
|
||||||
|
contactWechat: "linjing-doors",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
for (const offering of [
|
||||||
|
{
|
||||||
|
name: "别墅入户大门",
|
||||||
|
description: "结合建筑立面与入户动线定制门体、五金和安装方案。",
|
||||||
|
priceText: "预约沟通",
|
||||||
|
sortOrder: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "院门与围合系统",
|
||||||
|
description: "院门、围墙和庭院动线的一体化设计与施工配合。",
|
||||||
|
priceText: "预约沟通",
|
||||||
|
sortOrder: 2,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "室内户内门系统",
|
||||||
|
description: "根据空间风格定制户内门、隐形门和装饰门。",
|
||||||
|
priceText: "预约沟通",
|
||||||
|
sortOrder: 3,
|
||||||
|
},
|
||||||
|
]) {
|
||||||
|
await prisma.offering.upsert({
|
||||||
|
where: { brandId_name: { brandId: doorsBrand.id, name: offering.name } },
|
||||||
|
update: offering,
|
||||||
|
create: { ...offering, brandId: doorsBrand.id, kind: "service" },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
await prisma.brandMembership.upsert({
|
||||||
|
where: { adminUserId_brandId: { adminUserId: admin.id, brandId: doorsBrand.id } },
|
||||||
|
update: { isEnabled: true, role: "owner" },
|
||||||
|
create: { adminUserId: admin.id, brandId: doorsBrand.id, role: "owner" },
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
main().finally(() => prisma.$disconnect());
|
main().finally(() => prisma.$disconnect());
|
||||||
@@ -69,7 +69,10 @@ export class PublicController {
|
|||||||
|
|
||||||
@Get("brand")
|
@Get("brand")
|
||||||
async brand(): Promise<unknown> {
|
async brand(): Promise<unknown> {
|
||||||
return this.prisma.brandProfile.findFirst({
|
return this.prisma.brandProfile.findUnique({
|
||||||
|
where: {
|
||||||
|
id: process.env.DEFAULT_BRAND_ID ?? "00000000-0000-0000-0000-000000000001",
|
||||||
|
},
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
name: true,
|
name: true,
|
||||||
|
|||||||
@@ -15,7 +15,10 @@ export class CustomerSessionController {
|
|||||||
@Post("wechat")
|
@Post("wechat")
|
||||||
async wechatLogin(@Body() body: WechatLoginDto): Promise<{ token: string }> {
|
async wechatLogin(@Body() body: WechatLoginDto): Promise<{ token: string }> {
|
||||||
const session = await this.wechatAuth.exchangeCode(body.code);
|
const session = await this.wechatAuth.exchangeCode(body.code);
|
||||||
const brand = await this.prisma.brandProfile.findFirst({ select: { id: true } });
|
const brand = await this.prisma.brandProfile.findUnique({
|
||||||
|
where: { id: process.env.DEFAULT_BRAND_ID ?? "00000000-0000-0000-0000-000000000001" },
|
||||||
|
select: { id: true },
|
||||||
|
});
|
||||||
if (!brand) throw new BadRequestException("品牌尚未初始化");
|
if (!brand) throw new BadRequestException("品牌尚未初始化");
|
||||||
await this.prisma.customerUser.upsert({
|
await this.prisma.customerUser.upsert({
|
||||||
where: { brandId_openid: { brandId: brand.id, openid: session.openid } },
|
where: { brandId_openid: { brandId: brand.id, openid: session.openid } },
|
||||||
|
|||||||
@@ -781,6 +781,8 @@ test("admin can list and switch only enabled brand memberships", async () => {
|
|||||||
assert.equal(brands.statusCode, 200);
|
assert.equal(brands.statusCode, 200);
|
||||||
const memberships = JSON.parse(brands.body);
|
const memberships = JSON.parse(brands.body);
|
||||||
assert.ok(memberships.some((item) => item.brand.id === brandId));
|
assert.ok(memberships.some((item) => item.brand.id === brandId));
|
||||||
|
assert.ok(memberships.some((item) => item.brand.slug === "linjing-doors"));
|
||||||
|
assert.ok(memberships.length >= 2);
|
||||||
const denied = await request("/admin/brands/00000000-0000-0000-0000-000000000000/switch", {
|
const denied = await request("/admin/brands/00000000-0000-0000-0000-000000000000/switch", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { authorization: `Bearer ${token}` },
|
headers: { authorization: `Bearer ${token}` },
|
||||||
|
|||||||
Reference in new issue
Block a user