feature: sending invitation link for newly created staff implemented.
This commit is contained in:
@@ -135,7 +135,7 @@ export class AuthService {
|
||||
});
|
||||
|
||||
// Transform memberships to include organization info and permissions
|
||||
const organizations = user.memberships?.map(membership => ({
|
||||
const organizations = this.toActiveOrganizations(user.memberships).map(membership => ({
|
||||
id: membership.organization.id,
|
||||
name: membership.organization.name,
|
||||
type: membership.organization.type.name, // 'CLINIC' or 'LAB'
|
||||
@@ -149,7 +149,7 @@ export class AuthService {
|
||||
maxUsers: membership.organization.plan.maxUsers,
|
||||
}
|
||||
: undefined,
|
||||
})) || [];
|
||||
}));
|
||||
|
||||
return {
|
||||
success: true,
|
||||
@@ -342,7 +342,7 @@ export class AuthService {
|
||||
const { passwordHash, ...result } = user;
|
||||
|
||||
// Transform memberships for frontend consumption
|
||||
const organizations = user.memberships?.map(membership => ({
|
||||
const organizations = this.toActiveOrganizations(user.memberships).map(membership => ({
|
||||
id: membership.organization.id,
|
||||
name: membership.organization.name,
|
||||
type: membership.organization.type.name,
|
||||
@@ -356,7 +356,7 @@ export class AuthService {
|
||||
maxUsers: membership.organization.plan.maxUsers,
|
||||
}
|
||||
: undefined,
|
||||
})) || [];
|
||||
}));
|
||||
|
||||
return {
|
||||
success: true,
|
||||
@@ -462,7 +462,7 @@ export class AuthService {
|
||||
});
|
||||
|
||||
// Transform memberships for response
|
||||
const organizations = session.user.memberships?.map(membership => ({
|
||||
const organizations = this.toActiveOrganizations(session.user.memberships).map(membership => ({
|
||||
id: membership.organization.id,
|
||||
name: membership.organization.name,
|
||||
type: membership.organization.type.name,
|
||||
@@ -476,7 +476,7 @@ export class AuthService {
|
||||
maxUsers: membership.organization.plan.maxUsers,
|
||||
}
|
||||
: undefined,
|
||||
})) || [];
|
||||
}));
|
||||
|
||||
return {
|
||||
success: true,
|
||||
@@ -668,7 +668,7 @@ export class AuthService {
|
||||
|
||||
const { passwordHash, ...user } = session.user;
|
||||
|
||||
const organizations = session.user.memberships?.map(membership => ({
|
||||
const organizations = this.toActiveOrganizations(session.user.memberships).map(membership => ({
|
||||
id: membership.organization.id,
|
||||
name: membership.organization.name,
|
||||
type: membership.organization.type.name,
|
||||
@@ -682,7 +682,7 @@ export class AuthService {
|
||||
maxUsers: membership.organization.plan.maxUsers,
|
||||
}
|
||||
: undefined,
|
||||
})) || [];
|
||||
}));
|
||||
|
||||
return {
|
||||
success: true,
|
||||
@@ -722,6 +722,9 @@ export class AuthService {
|
||||
if (!membership) {
|
||||
throw new UnauthorizedException('Access denied to this organization');
|
||||
}
|
||||
if (!membership.isOwner && !membership.isActive) {
|
||||
throw new UnauthorizedException('Your invitation is still pending activation');
|
||||
}
|
||||
|
||||
// 2. Build payload WITH org context
|
||||
const payload = {
|
||||
@@ -763,6 +766,17 @@ export class AuthService {
|
||||
};
|
||||
}
|
||||
|
||||
private toActiveOrganizations(
|
||||
memberships: Array<{
|
||||
isOwner: boolean;
|
||||
isActive: boolean;
|
||||
organization: { id: string; name: string; type: { name: string }; plan?: { name: string; maxUsers: number } | null };
|
||||
permissions?: Array<{ permission: { name: string } }>;
|
||||
}> = [],
|
||||
) {
|
||||
return memberships.filter((m) => m.isOwner || m.isActive);
|
||||
}
|
||||
|
||||
/**
|
||||
* Owner-only subscription / seat alerts for the current org (from JWT).
|
||||
* Used for a subtle warning indicator in the app shell (not staff-facing banners).
|
||||
@@ -805,7 +819,10 @@ export class AuthService {
|
||||
const plan = org.plan;
|
||||
const maxUsers = plan.maxUsers;
|
||||
const seatsUsed = await this.prisma.membership.count({
|
||||
where: { organizationId: org.id },
|
||||
where: {
|
||||
organizationId: org.id,
|
||||
OR: [{ isOwner: true }, { isActive: true }],
|
||||
},
|
||||
});
|
||||
|
||||
const unlimited = maxUsers >= 999999;
|
||||
|
||||
Reference in New Issue
Block a user