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