improvement: newly created organization's subscriptions flow improved.
This commit is contained in:
@@ -59,7 +59,7 @@ export class StaffService {
|
||||
}),
|
||||
]);
|
||||
|
||||
const maxUsers = org.plan.maxUsers;
|
||||
const maxUsers = org.plan?.maxUsers ?? 0;
|
||||
const unlimited = isUnlimitedSeats(maxUsers);
|
||||
|
||||
return {
|
||||
@@ -119,6 +119,12 @@ export class StaffService {
|
||||
throw new NotFoundException('Organization not found');
|
||||
}
|
||||
|
||||
if (!org.plan) {
|
||||
throw new BadRequestException(
|
||||
'This organization has no active subscription. Please choose a plan before inviting staff.',
|
||||
);
|
||||
}
|
||||
|
||||
const maxUsers = org.plan.maxUsers;
|
||||
const seatsUsed = await tx.membership.count({
|
||||
where: {
|
||||
@@ -362,7 +368,10 @@ export class StaffService {
|
||||
private async getActorMembership(userId: string, organizationId: string) {
|
||||
return this.prisma.membership.findFirst({
|
||||
where: { userId, organizationId },
|
||||
include: { permissions: { include: { permission: true } } },
|
||||
include: {
|
||||
permissions: { include: { permission: true } },
|
||||
organization: { select: { planId: true } },
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -424,6 +433,7 @@ export class StaffService {
|
||||
|
||||
private canViewStaff(m: {
|
||||
isOwner: boolean;
|
||||
organization?: { planId: string | null };
|
||||
permissions: { permission: { name: string } }[];
|
||||
}): boolean {
|
||||
if (m.isOwner) return true;
|
||||
@@ -435,9 +445,10 @@ export class StaffService {
|
||||
|
||||
private canEditStaff(m: {
|
||||
isOwner: boolean;
|
||||
organization?: { planId: string | null };
|
||||
permissions: { permission: { name: string } }[];
|
||||
}): boolean {
|
||||
if (m.isOwner) return true;
|
||||
if (m.isOwner) return Boolean(m.organization?.planId);
|
||||
return m.permissions.some((p) => p.permission.name === 'TAB_STAFF_EDIT');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user