Optimize metadata queries (#7013)
In this PR: 1. Refactor guards to avoid duplicated queries: WorkspaceAuthGuard and UserAuthGuard only check for existence of workspace and user in the request without querying the database
This commit is contained in:
committed by
Charles Bochet
parent
cf8b1161cc
commit
523df5398a
@ -16,7 +16,8 @@ import { User } from 'src/engine/core-modules/user/user.entity';
|
||||
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
||||
import { AuthUser } from 'src/engine/decorators/auth/auth-user.decorator';
|
||||
import { AuthWorkspace } from 'src/engine/decorators/auth/auth-workspace.decorator';
|
||||
import { JwtAuthGuard } from 'src/engine/guards/jwt.auth.guard';
|
||||
import { UserAuthGuard } from 'src/engine/guards/user-auth.guard';
|
||||
import { WorkspaceAuthGuard } from 'src/engine/guards/workspace-auth.guard';
|
||||
|
||||
@Resolver()
|
||||
export class BillingResolver {
|
||||
@ -37,7 +38,7 @@ export class BillingResolver {
|
||||
}
|
||||
|
||||
@Query(() => SessionEntity)
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@UseGuards(WorkspaceAuthGuard, UserAuthGuard)
|
||||
async billingPortalSession(
|
||||
@AuthUser() user: User,
|
||||
@Args() { returnUrlPath }: BillingSessionInput,
|
||||
@ -51,7 +52,7 @@ export class BillingResolver {
|
||||
}
|
||||
|
||||
@Mutation(() => SessionEntity)
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@UseGuards(WorkspaceAuthGuard, UserAuthGuard)
|
||||
async checkoutSession(
|
||||
@AuthWorkspace() workspace: Workspace,
|
||||
@AuthUser() user: User,
|
||||
@ -79,7 +80,7 @@ export class BillingResolver {
|
||||
}
|
||||
|
||||
@Mutation(() => UpdateBillingEntity)
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@UseGuards(WorkspaceAuthGuard)
|
||||
async updateBillingSubscription(@AuthUser() user: User) {
|
||||
await this.billingSubscriptionService.applyBillingSubscription(user);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user