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 29, 2024
1 parent db49ad9 commit 1a96495
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 24 deletions.
20 changes: 10 additions & 10 deletions packages/backend/server/src/core/auth/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class AuthResolver {
@Throttle({
default: {
limit: 10,
ttl: 60,
ttl: 60 * 1000,
},
})
@Public()
Expand All @@ -75,7 +75,7 @@ export class AuthResolver {
@Throttle({
default: {
limit: 20,
ttl: 60,
ttl: 60 * 1000,
},
})
@ResolveField(() => ClientTokenType, {
Expand Down Expand Up @@ -107,7 +107,7 @@ export class AuthResolver {
@Throttle({
default: {
limit: 10,
ttl: 60,
ttl: 60 * 1000,
},
})
@Mutation(() => UserType)
Expand Down Expand Up @@ -137,7 +137,7 @@ export class AuthResolver {
@Throttle({
default: {
limit: 10,
ttl: 60,
ttl: 60 * 1000,
},
})
@Mutation(() => UserType)
Expand Down Expand Up @@ -165,7 +165,7 @@ export class AuthResolver {
@Throttle({
default: {
limit: 5,
ttl: 60,
ttl: 60 * 1000,
},
})
@Mutation(() => UserType)
Expand Down Expand Up @@ -196,7 +196,7 @@ export class AuthResolver {
@Throttle({
default: {
limit: 5,
ttl: 60,
ttl: 60 * 1000,
},
})
@Mutation(() => UserType)
Expand Down Expand Up @@ -226,7 +226,7 @@ export class AuthResolver {
@Throttle({
default: {
limit: 5,
ttl: 60,
ttl: 60 * 1000,
},
})
@Mutation(() => Boolean)
Expand Down Expand Up @@ -259,7 +259,7 @@ export class AuthResolver {
@Throttle({
default: {
limit: 5,
ttl: 60,
ttl: 60 * 1000,
},
})
@Mutation(() => Boolean)
Expand Down Expand Up @@ -297,7 +297,7 @@ export class AuthResolver {
@Throttle({
default: {
limit: 5,
ttl: 60,
ttl: 60 * 1000,
},
})
@Mutation(() => Boolean)
Expand All @@ -323,7 +323,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/user/management.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,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
22 changes: 16 additions & 6 deletions packages/backend/server/src/core/user/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class UserResolver {
@Throttle({
default: {
limit: 10,
ttl: 60,
ttl: 60 * 1000,
},
})
@Query(() => UserOrLimitedUser, {
Expand Down Expand Up @@ -90,15 +90,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 @@ -121,7 +131,7 @@ export class UserResolver {
@Throttle({
default: {
limit: 10,
ttl: 60,
ttl: 60 * 1000,
},
})
@Mutation(() => UserType, {
Expand Down Expand Up @@ -156,7 +166,7 @@ export class UserResolver {
@Throttle({
default: {
limit: 10,
ttl: 60,
ttl: 60 * 1000,
},
})
@Mutation(() => UserType, {
Expand Down Expand Up @@ -204,7 +214,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 @@ -26,7 +26,7 @@ export class WorkspaceManagementResolver {
@Throttle({
default: {
limit: 10,
ttl: 60,
ttl: 60 * 1000,
},
})
@Mutation(() => Int)
Expand All @@ -45,7 +45,7 @@ export class WorkspaceManagementResolver {
@Throttle({
default: {
limit: 10,
ttl: 60,
ttl: 60 * 1000,
},
})
@Mutation(() => Int)
Expand All @@ -64,7 +64,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 @@ -194,7 +194,7 @@ export class WorkspaceResolver {
@Throttle({
default: {
limit: 10,
ttl: 30,
ttl: 30 * 1000,
},
})
@Public()
Expand Down Expand Up @@ -227,6 +227,12 @@ export class WorkspaceResolver {
return workspace;
}

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

@Throttle({
default: {
limit: 10,
ttl: 120 * 1000,
},
})
@Mutation(() => Boolean)
async deleteWorkspace(
@CurrentUser() user: CurrentUser,
Expand All @@ -321,6 +333,12 @@ export class WorkspaceResolver {
return true;
}

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

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

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

0 comments on commit 1a96495

Please sign in to comment.