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 19, 2024
1 parent dc1984e commit 98cd5e6
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 @@ -56,7 +56,7 @@ export class AuthResolver {
@Throttle({
default: {
limit: 10,
ttl: 60,
ttl: 60 * 1000,
},
})
@Public()
Expand All @@ -72,7 +72,7 @@ export class AuthResolver {
@Throttle({
default: {
limit: 20,
ttl: 60,
ttl: 60 * 1000,
},
})
@ResolveField(() => ClientTokenType, {
Expand Down Expand Up @@ -104,7 +104,7 @@ export class AuthResolver {
@Throttle({
default: {
limit: 10,
ttl: 60,
ttl: 60 * 1000,
},
})
@Mutation(() => UserType)
Expand Down Expand Up @@ -134,7 +134,7 @@ export class AuthResolver {
@Throttle({
default: {
limit: 10,
ttl: 60,
ttl: 60 * 1000,
},
})
@Mutation(() => UserType)
Expand Down Expand Up @@ -162,7 +162,7 @@ export class AuthResolver {
@Throttle({
default: {
limit: 5,
ttl: 60,
ttl: 60 * 1000,
},
})
@Mutation(() => UserType)
Expand Down Expand Up @@ -193,7 +193,7 @@ export class AuthResolver {
@Throttle({
default: {
limit: 5,
ttl: 60,
ttl: 60 * 1000,
},
})
@Mutation(() => UserType)
Expand Down Expand Up @@ -223,7 +223,7 @@ export class AuthResolver {
@Throttle({
default: {
limit: 5,
ttl: 60,
ttl: 60 * 1000,
},
})
@Mutation(() => Boolean)
Expand Down Expand Up @@ -256,7 +256,7 @@ export class AuthResolver {
@Throttle({
default: {
limit: 5,
ttl: 60,
ttl: 60 * 1000,
},
})
@Mutation(() => Boolean)
Expand Down Expand Up @@ -294,7 +294,7 @@ export class AuthResolver {
@Throttle({
default: {
limit: 5,
ttl: 60,
ttl: 60 * 1000,
},
})
@Mutation(() => Boolean)
Expand All @@ -320,7 +320,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 @@ -53,7 +53,7 @@ export class UserResolver {
@Throttle({
default: {
limit: 10,
ttl: 60,
ttl: 60 * 1000,
},
})
@Query(() => UserOrLimitedUser, {
Expand Down Expand Up @@ -89,15 +89,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 @@ -120,7 +130,7 @@ export class UserResolver {
@Throttle({
default: {
limit: 10,
ttl: 60,
ttl: 60 * 1000,
},
})
@Mutation(() => UserType, {
Expand Down Expand Up @@ -155,7 +165,7 @@ export class UserResolver {
@Throttle({
default: {
limit: 10,
ttl: 60,
ttl: 60 * 1000,
},
})
@Mutation(() => UserType, {
Expand Down Expand Up @@ -203,7 +213,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 98cd5e6

Please sign in to comment.