Skip to content

Commit

Permalink
feat: migrate throttler config for new throttler version
Browse files Browse the repository at this point in the history
  • Loading branch information
darkskygit committed Mar 5, 2024
1 parent f0c3aed commit f3ac634
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 26 deletions.
4 changes: 2 additions & 2 deletions packages/backend/server/src/core/auth/next-auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class NextAuthController {
@Throttle({
default: {
limit: 60,
ttl: 60,
ttl: 60 * 1000,
},
})
@Get('/challenge')
Expand All @@ -73,7 +73,7 @@ export class NextAuthController {
@Throttle({
default: {
limit: 60,
ttl: 60,
ttl: 60 * 1000,
},
})
@All('*')
Expand Down
18 changes: 9 additions & 9 deletions packages/backend/server/src/core/auth/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class AuthResolver {
@Throttle({
default: {
limit: 20,
ttl: 60,
ttl: 60 * 1000,
},
})
@ResolveField(() => TokenType)
Expand Down Expand Up @@ -93,7 +93,7 @@ export class AuthResolver {
@Throttle({
default: {
limit: 10,
ttl: 60,
ttl: 60 * 1000,
},
})
@Mutation(() => UserType)
Expand All @@ -111,7 +111,7 @@ export class AuthResolver {
@Throttle({
default: {
limit: 10,
ttl: 60,
ttl: 60 * 1000,
},
})
@Mutation(() => UserType)
Expand All @@ -128,7 +128,7 @@ export class AuthResolver {
@Throttle({
default: {
limit: 5,
ttl: 60,
ttl: 60 * 1000,
},
})
@Mutation(() => UserType)
Expand Down Expand Up @@ -161,7 +161,7 @@ export class AuthResolver {
@Throttle({
default: {
limit: 5,
ttl: 60,
ttl: 60 * 1000,
},
})
@Mutation(() => UserType)
Expand Down Expand Up @@ -192,7 +192,7 @@ export class AuthResolver {
@Throttle({
default: {
limit: 5,
ttl: 60,
ttl: 60 * 1000,
},
})
@Mutation(() => Boolean)
Expand All @@ -215,7 +215,7 @@ export class AuthResolver {
@Throttle({
default: {
limit: 5,
ttl: 60,
ttl: 60 * 1000,
},
})
@Mutation(() => Boolean)
Expand Down Expand Up @@ -245,7 +245,7 @@ export class AuthResolver {
@Throttle({
default: {
limit: 5,
ttl: 60,
ttl: 60 * 1000,
},
})
@Mutation(() => Boolean)
Expand All @@ -268,7 +268,7 @@ export class AuthResolver {
@Throttle({
default: {
limit: 5,
ttl: 60,
ttl: 60 * 1000,
},
})
@Mutation(() => Boolean)
Expand Down
6 changes: 3 additions & 3 deletions packages/backend/server/src/core/users/management.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class UserManagementResolver {
@Throttle({
default: {
limit: 10,
ttl: 60,
ttl: 60 * 1000,
},
})
@Mutation(() => Int)
Expand All @@ -52,7 +52,7 @@ export class UserManagementResolver {
@Throttle({
default: {
limit: 10,
ttl: 60,
ttl: 60 * 1000,
},
})
@Mutation(() => Int)
Expand All @@ -73,7 +73,7 @@ export class UserManagementResolver {
@Throttle({
default: {
limit: 10,
ttl: 60,
ttl: 60 * 1000,
},
})
@Query(() => [UserType])
Expand Down
24 changes: 17 additions & 7 deletions packages/backend/server/src/core/users/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class UserResolver {
@Throttle({
default: {
limit: 10,
ttl: 60,
ttl: 60 * 1000,
},
})
@Publicable()
Expand Down Expand Up @@ -82,7 +82,7 @@ export class UserResolver {
@Throttle({
default: {
limit: 10,
ttl: 60,
ttl: 60 * 1000,
},
})
@Query(() => UserOrLimitedUser, {
Expand Down Expand Up @@ -115,15 +115,25 @@ export class UserResolver {
};
}

@Throttle({ default: { limit: 10, ttl: 60 } })
@Throttle({
default: {
limit: 10,
ttl: 60 * 1000,
},
})
@ResolveField(() => UserQuotaType, { name: 'quota', nullable: true })
async getQuota(@CurrentUser() me: User) {
const quota = await this.quota.getUserQuota(me.id);

return quota.feature;
}

@Throttle({ default: { limit: 10, ttl: 60 } })
@Throttle({
default: {
limit: 10,
ttl: 60 * 1000,
},
})
@ResolveField(() => Int, {
name: 'invoiceCount',
description: 'Get user invoice count',
Expand All @@ -137,7 +147,7 @@ export class UserResolver {
@Throttle({
default: {
limit: 10,
ttl: 60,
ttl: 60 * 1000,
},
})
@Mutation(() => UserType, {
Expand Down Expand Up @@ -172,7 +182,7 @@ export class UserResolver {
@Throttle({
default: {
limit: 10,
ttl: 60,
ttl: 60 * 1000,
},
})
@Mutation(() => RemoveAvatar, {
Expand All @@ -193,7 +203,7 @@ export class UserResolver {
@Throttle({
default: {
limit: 10,
ttl: 60,
ttl: 60 * 1000,
},
})
@Mutation(() => DeleteAccount)
Expand Down
6 changes: 3 additions & 3 deletions packages/backend/server/src/core/workspaces/management.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class WorkspaceManagementResolver {
@Throttle({
default: {
limit: 10,
ttl: 60,
ttl: 60 * 1000,
},
})
@Mutation(() => Int)
Expand All @@ -47,7 +47,7 @@ export class WorkspaceManagementResolver {
@Throttle({
default: {
limit: 10,
ttl: 60,
ttl: 60 * 1000,
},
})
@Mutation(() => Int)
Expand All @@ -66,7 +66,7 @@ export class WorkspaceManagementResolver {
@Throttle({
default: {
limit: 10,
ttl: 60,
ttl: 60 * 1000,
},
})
@Query(() => [WorkspaceType])
Expand Down
34 changes: 32 additions & 2 deletions packages/backend/server/src/core/workspaces/resolvers/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export class WorkspaceResolver {
@Throttle({
default: {
limit: 10,
ttl: 30,
ttl: 30 * 1000,
},
})
@Public()
Expand Down Expand Up @@ -229,6 +229,12 @@ export class WorkspaceResolver {
return workspace;
}

@Throttle({
default: {
limit: 10,
ttl: 120 * 1000,
},
})
@Mutation(() => WorkspaceType, {
description: 'Create a new workspace',
})
Expand Down Expand Up @@ -305,6 +311,12 @@ export class WorkspaceResolver {
});
}

@Throttle({
default: {
limit: 10,
ttl: 120 * 1000,
},
})
@Mutation(() => Boolean)
async deleteWorkspace(@CurrentUser() user: UserType, @Args('id') id: string) {
await this.permissions.checkWorkspace(id, user.id, Permission.Owner);
Expand All @@ -320,6 +332,12 @@ export class WorkspaceResolver {
return true;
}

@Throttle({
default: {
limit: 10,
ttl: 120 * 1000,
},
})
@Mutation(() => String)
async invite(
@CurrentUser() user: UserType,
Expand Down Expand Up @@ -415,7 +433,7 @@ export class WorkspaceResolver {
@Throttle({
default: {
limit: 10,
ttl: 30,
ttl: 30 * 1000,
},
})
@Public()
Expand Down Expand Up @@ -476,6 +494,12 @@ export class WorkspaceResolver {
};
}

@Throttle({
default: {
limit: 10,
ttl: 120 * 1000,
},
})
@Mutation(() => Boolean)
async revoke(
@CurrentUser() user: UserType,
Expand Down Expand Up @@ -520,6 +544,12 @@ export class WorkspaceResolver {
return this.permissions.acceptWorkspaceInvitation(inviteId, workspaceId);
}

@Throttle({
default: {
limit: 10,
ttl: 120 * 1000,
},
})
@Mutation(() => Boolean)
async leaveWorkspace(
@CurrentUser() user: UserType,
Expand Down

0 comments on commit f3ac634

Please sign in to comment.