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 14, 2024
1 parent 122a1a7 commit 687b240
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 @@ -54,7 +54,7 @@ export class AuthResolver {
@Throttle({
default: {
limit: 10,
ttl: 60,
ttl: 60 * 1000,
},
})
@Public()
Expand All @@ -70,7 +70,7 @@ export class AuthResolver {
@Throttle({
default: {
limit: 20,
ttl: 60,
ttl: 60 * 1000,
},
})
@ResolveField(() => ClientTokenType, {
Expand Down Expand Up @@ -102,7 +102,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 @@ -142,7 +142,7 @@ export class AuthResolver {
@Throttle({
default: {
limit: 5,
ttl: 60,
ttl: 60 * 1000,
},
})
@Mutation(() => UserType)
Expand Down Expand Up @@ -173,7 +173,7 @@ export class AuthResolver {
@Throttle({
default: {
limit: 5,
ttl: 60,
ttl: 60 * 1000,
},
})
@Mutation(() => UserType)
Expand Down Expand Up @@ -203,7 +203,7 @@ export class AuthResolver {
@Throttle({
default: {
limit: 5,
ttl: 60,
ttl: 60 * 1000,
},
})
@Mutation(() => Boolean)
Expand Down Expand Up @@ -236,7 +236,7 @@ export class AuthResolver {
@Throttle({
default: {
limit: 5,
ttl: 60,
ttl: 60 * 1000,
},
})
@Mutation(() => Boolean)
Expand Down Expand Up @@ -274,7 +274,7 @@ export class AuthResolver {
@Throttle({
default: {
limit: 5,
ttl: 60,
ttl: 60 * 1000,
},
})
@Mutation(() => Boolean)
Expand All @@ -300,7 +300,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 @@ -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 @@ -409,7 +427,7 @@ export class WorkspaceResolver {
@Throttle({
default: {
limit: 10,
ttl: 30,
ttl: 30 * 1000,
},
})
@Public()
Expand Down Expand Up @@ -470,6 +488,12 @@ export class WorkspaceResolver {
};
}

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

Please sign in to comment.