feat(core): make permission and invoice offline available (#8123)

This commit is contained in:
EYHN
2024-09-05 15:11:27 +00:00
parent 8be67dce82
commit f4db4058f8
17 changed files with 236 additions and 186 deletions

View File

@@ -75,6 +75,14 @@ export class PermissionService {
return owner.user;
}
async getWorkspaceMemberCount(workspaceId: string) {
return this.prisma.workspaceUserPermission.count({
where: {
workspaceId,
},
});
}
async tryGetWorkspaceOwner(workspaceId: string) {
return this.prisma.workspaceUserPermission.findFirst({
where: {

View File

@@ -113,6 +113,8 @@ export class QuotaManagementService {
// quota was apply to owner's account
async getWorkspaceUsage(workspaceId: string): Promise<QuotaBusinessType> {
const owner = await this.permissions.getWorkspaceOwner(workspaceId);
const memberCount =
await this.permissions.getWorkspaceMemberCount(workspaceId);
const {
feature: {
name,
@@ -145,6 +147,7 @@ export class QuotaManagementService {
humanReadable,
usedSize,
unlimited,
memberCount,
};
if (quota.unlimited) {

View File

@@ -87,6 +87,9 @@ export class QuotaQueryType {
@Field(() => SafeIntResolver)
memberLimit!: number;
@Field(() => SafeIntResolver)
memberCount!: number;
@Field(() => SafeIntResolver)
storageQuota!: number;

View File

@@ -115,11 +115,7 @@ export class WorkspaceResolver {
complexity: 2,
})
memberCount(@Parent() workspace: WorkspaceType) {
return this.prisma.workspaceUserPermission.count({
where: {
workspaceId: workspace.id,
},
});
return this.permissions.getWorkspaceMemberCount(workspace.id);
}
@ResolveField(() => Boolean, {
@@ -388,13 +384,8 @@ export class WorkspaceResolver {
}
// member limit check
const [memberCount, quota] = await Promise.all([
this.prisma.workspaceUserPermission.count({
where: { workspaceId },
}),
this.quota.getWorkspaceUsage(workspaceId),
]);
if (memberCount >= quota.memberLimit) {
const quota = await this.quota.getWorkspaceUsage(workspaceId);
if (quota.memberCount >= quota.memberLimit) {
return new MemberQuotaExceeded();
}

View File

@@ -603,6 +603,7 @@ type QuotaQueryType {
copilotActionLimit: SafeInt
historyPeriod: SafeInt!
humanReadable: HumanReadableQuotaType!
memberCount: SafeInt!
memberLimit: SafeInt!
name: String!
storageQuota: SafeInt!