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 d8287d7 commit 3f16f57
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 @@ -55,7 +55,7 @@ export class AuthResolver {
@Throttle({
default: {
limit: 10,
ttl: 60,
ttl: 60 * 1000,
},
})
@Public()
Expand All @@ -71,7 +71,7 @@ export class AuthResolver {
@Throttle({
default: {
limit: 20,
ttl: 60,
ttl: 60 * 1000,
},
})
@ResolveField(() => ClientTokenType, {
Expand Down Expand Up @@ -103,7 +103,7 @@ export class AuthResolver {
@Throttle({
default: {
limit: 10,
ttl: 60,
ttl: 60 * 1000,
},
})
@Mutation(() => UserType)
Expand All @@ -123,7 +123,7 @@ export class AuthResolver {
@Throttle({
default: {
limit: 10,
ttl: 60,
ttl: 60 * 1000,
},
})
@Mutation(() => UserType)
Expand All @@ -141,7 +141,7 @@ export class AuthResolver {
@Throttle({
default: {
limit: 5,
ttl: 60,
ttl: 60 * 1000,
},
})
@Mutation(() => UserType)
Expand Down Expand Up @@ -170,7 +170,7 @@ export class AuthResolver {
@Throttle({
default: {
limit: 5,
ttl: 60,
ttl: 60 * 1000,
},
})
@Mutation(() => UserType)
Expand Down Expand Up @@ -199,7 +199,7 @@ export class AuthResolver {
@Throttle({
default: {
limit: 5,
ttl: 60,
ttl: 60 * 1000,
},
})
@Mutation(() => Boolean)
Expand Down Expand Up @@ -232,7 +232,7 @@ export class AuthResolver {
@Throttle({
default: {
limit: 5,
ttl: 60,
ttl: 60 * 1000,
},
})
@Mutation(() => Boolean)
Expand Down Expand Up @@ -267,7 +267,7 @@ export class AuthResolver {
@Throttle({
default: {
limit: 5,
ttl: 60,
ttl: 60 * 1000,
},
})
@Mutation(() => Boolean)
Expand All @@ -293,7 +293,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 @@ -26,7 +26,7 @@ export class UserManagementResolver {
@Throttle({
default: {
limit: 10,
ttl: 60,
ttl: 60 * 1000,
},
})
@Mutation(() => Int)
Expand All @@ -49,7 +49,7 @@ export class UserManagementResolver {
@Throttle({
default: {
limit: 10,
ttl: 60,
ttl: 60 * 1000,
},
})
@Mutation(() => Int)
Expand All @@ -70,7 +70,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/users/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class UserResolver {
@Throttle({
default: {
limit: 10,
ttl: 60,
ttl: 60 * 1000,
},
})
@Query(() => UserOrLimitedUser, {
Expand Down Expand Up @@ -86,15 +86,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 @@ -108,7 +118,7 @@ export class UserResolver {
@Throttle({
default: {
limit: 10,
ttl: 60,
ttl: 60 * 1000,
},
})
@Mutation(() => UserType, {
Expand Down Expand Up @@ -143,7 +153,7 @@ export class UserResolver {
@Throttle({
default: {
limit: 10,
ttl: 60,
ttl: 60 * 1000,
},
})
@Mutation(() => UserType, {
Expand Down Expand Up @@ -191,7 +201,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 @@ -27,7 +27,7 @@ export class WorkspaceManagementResolver {
@Throttle({
default: {
limit: 10,
ttl: 60,
ttl: 60 * 1000,
},
})
@Mutation(() => Int)
Expand All @@ -46,7 +46,7 @@ export class WorkspaceManagementResolver {
@Throttle({
default: {
limit: 10,
ttl: 60,
ttl: 60 * 1000,
},
})
@Mutation(() => Int)
Expand All @@ -65,7 +65,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 @@ -191,7 +191,7 @@ export class WorkspaceResolver {
@Throttle({
default: {
limit: 10,
ttl: 30,
ttl: 30 * 1000,
},
})
@Public()
Expand Down Expand Up @@ -224,6 +224,12 @@ export class WorkspaceResolver {
return workspace;
}

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

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

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

@Throttle({
default: {
limit: 10,
ttl: 120 * 1000,
},
})
@Mutation(() => Boolean)
async revoke(
@CurrentUser() user: CurrentUser,
Expand Down Expand Up @@ -512,6 +536,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 3f16f57

Please sign in to comment.