fix: 隔离模板与业务提供项品牌上下文
This commit is contained in:
1 parent
7451268e59
commit
f790e7d707
1 file changed
+11
-11
@@ -43,9 +43,9 @@ class AdminWorkspaceController {
|
|||||||
|
|
||||||
@Get("offerings")
|
@Get("offerings")
|
||||||
async listOfferings(@Req() request: FastifyRequest): Promise<unknown> {
|
async listOfferings(@Req() request: FastifyRequest): Promise<unknown> {
|
||||||
this.requireAdmin(request);
|
const brandId = this.requireAdmin(request).brandId;
|
||||||
const items = await this.prisma.offering.findMany({
|
const items = await this.prisma.offering.findMany({
|
||||||
where: { brandId: this.brandId() },
|
where: { brandId },
|
||||||
orderBy: { sortOrder: "asc" },
|
orderBy: { sortOrder: "asc" },
|
||||||
});
|
});
|
||||||
return items.map((item) => {
|
return items.map((item) => {
|
||||||
@@ -64,7 +64,7 @@ class AdminWorkspaceController {
|
|||||||
@Req() request: FastifyRequest,
|
@Req() request: FastifyRequest,
|
||||||
@Body() body: CreateOfferingDto,
|
@Body() body: CreateOfferingDto,
|
||||||
): Promise<unknown> {
|
): Promise<unknown> {
|
||||||
this.requireAdmin(request);
|
const brandId = this.requireAdmin(request).brandId;
|
||||||
const { config, sections, media, cta, ...fields } = body;
|
const { config, sections, media, cta, ...fields } = body;
|
||||||
const configValue = {
|
const configValue = {
|
||||||
...(config ?? {}),
|
...(config ?? {}),
|
||||||
@@ -77,7 +77,7 @@ class AdminWorkspaceController {
|
|||||||
return this.prisma.offering.create({
|
return this.prisma.offering.create({
|
||||||
data: {
|
data: {
|
||||||
...fields,
|
...fields,
|
||||||
brandId: this.brandId(),
|
brandId,
|
||||||
config: configValue as Prisma.InputJsonValue,
|
config: configValue as Prisma.InputJsonValue,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -89,8 +89,8 @@ class AdminWorkspaceController {
|
|||||||
@Param("id") id: string,
|
@Param("id") id: string,
|
||||||
@Body() body: UpdateOfferingDto,
|
@Body() body: UpdateOfferingDto,
|
||||||
): Promise<unknown> {
|
): Promise<unknown> {
|
||||||
this.requireAdmin(request);
|
const brandId = this.requireAdmin(request).brandId;
|
||||||
const item = await this.prisma.offering.findFirst({ where: { id, brandId: this.brandId() } });
|
const item = await this.prisma.offering.findFirst({ where: { id, brandId } });
|
||||||
if (!item) throw new BadRequestException("业务提供项不存在");
|
if (!item) throw new BadRequestException("业务提供项不存在");
|
||||||
const { config, sections, media, cta, ...fields } = body;
|
const { config, sections, media, cta, ...fields } = body;
|
||||||
const configValue = {
|
const configValue = {
|
||||||
@@ -119,8 +119,8 @@ class AdminWorkspaceController {
|
|||||||
|
|
||||||
@Delete("offerings/:id")
|
@Delete("offerings/:id")
|
||||||
async deleteOffering(@Req() request: FastifyRequest, @Param("id") id: string): Promise<unknown> {
|
async deleteOffering(@Req() request: FastifyRequest, @Param("id") id: string): Promise<unknown> {
|
||||||
this.requireAdmin(request);
|
const brandId = this.requireAdmin(request).brandId;
|
||||||
const item = await this.prisma.offering.findFirst({ where: { id, brandId: this.brandId() } });
|
const item = await this.prisma.offering.findFirst({ where: { id, brandId } });
|
||||||
if (!item) throw new BadRequestException("业务提供项不存在");
|
if (!item) throw new BadRequestException("业务提供项不存在");
|
||||||
const [forms, bookings, items] = await Promise.all([
|
const [forms, bookings, items] = await Promise.all([
|
||||||
this.prisma.inquiryForm.count({ where: { offeringId: id } }),
|
this.prisma.inquiryForm.count({ where: { offeringId: id } }),
|
||||||
@@ -336,19 +336,19 @@ class AdminWorkspaceController {
|
|||||||
@Get("template/preview")
|
@Get("template/preview")
|
||||||
async previewTemplate(@Req() request: FastifyRequest): Promise<unknown> {
|
async previewTemplate(@Req() request: FastifyRequest): Promise<unknown> {
|
||||||
this.requireAdmin(request);
|
this.requireAdmin(request);
|
||||||
return this.templateWorkspace.preview(this.brandId());
|
return this.templateWorkspace.preview(this.requireAdmin(request).brandId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("template/upgrade")
|
@Post("template/upgrade")
|
||||||
async upgradeTemplate(@Req() request: FastifyRequest): Promise<unknown> {
|
async upgradeTemplate(@Req() request: FastifyRequest): Promise<unknown> {
|
||||||
this.requireAdmin(request);
|
this.requireAdmin(request);
|
||||||
return this.templateWorkspace.upgrade(this.brandId());
|
return this.templateWorkspace.upgrade(this.requireAdmin(request).brandId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("template/rollback")
|
@Post("template/rollback")
|
||||||
async rollbackTemplate(@Req() request: FastifyRequest): Promise<unknown> {
|
async rollbackTemplate(@Req() request: FastifyRequest): Promise<unknown> {
|
||||||
this.requireAdmin(request);
|
this.requireAdmin(request);
|
||||||
return this.templateWorkspace.rollback(this.brandId());
|
return this.templateWorkspace.rollback(this.requireAdmin(request).brandId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Patch("modules/:id")
|
@Patch("modules/:id")
|
||||||
|
|||||||
Reference in new issue
Block a user