backend api service for Count incoming pending connection requests for sidebar badge.
This commit is contained in:
@@ -64,6 +64,14 @@ export class OrganizationController {
|
|||||||
return this.organizationService.searchCounterpartOrganizations(req.user.id, organizationId, q);
|
return this.organizationService.searchCounterpartOrganizations(req.user.id, organizationId, q);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Get('connections/pending-count')
|
||||||
|
@UseGuards(JwtAuthGuard)
|
||||||
|
@ApiOperation({ summary: 'Count incoming pending connection requests for sidebar badge' })
|
||||||
|
countPendingConnections(@Req() req: { user: { id: string; organizationId?: string } }) {
|
||||||
|
const organizationId = this.organizationService.getOrganizationIdFromUser(req.user);
|
||||||
|
return this.organizationService.countIncomingPendingConnections(req.user.id, organizationId);
|
||||||
|
}
|
||||||
|
|
||||||
@Get('connections')
|
@Get('connections')
|
||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard)
|
||||||
@ApiOperation({ summary: 'List counterpart connections for current organization' })
|
@ApiOperation({ summary: 'List counterpart connections for current organization' })
|
||||||
|
|||||||
@@ -160,6 +160,29 @@ export class OrganizationService {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Lightweight count for sidebar badge — incoming PENDING requests only. */
|
||||||
|
async countIncomingPendingConnections(userId: string, organizationId: string) {
|
||||||
|
const actor = await this.getActorMembership(userId, organizationId);
|
||||||
|
if (!actor || !this.canEditOrganizations(actor)) {
|
||||||
|
throw new ForbiddenException('You do not have permission to manage organizations');
|
||||||
|
}
|
||||||
|
|
||||||
|
const links = await this.prisma.organizationLink.findMany({
|
||||||
|
where: {
|
||||||
|
status: LinkStatus.PENDING,
|
||||||
|
OR: [{ organizationAId: organizationId }, { organizationBId: organizationId }],
|
||||||
|
},
|
||||||
|
select: { sharedDataTypes: true },
|
||||||
|
});
|
||||||
|
|
||||||
|
const count = links.filter((link) => {
|
||||||
|
const requesterOrgId = this.getRequesterOrganizationId(link.sharedDataTypes);
|
||||||
|
return requesterOrgId !== null && requesterOrgId !== organizationId;
|
||||||
|
}).length;
|
||||||
|
|
||||||
|
return { success: true, data: { count } };
|
||||||
|
}
|
||||||
|
|
||||||
async listInvitationHistory(userId: string, organizationId: string) {
|
async listInvitationHistory(userId: string, organizationId: string) {
|
||||||
const actor = await this.getActorMembership(userId, organizationId);
|
const actor = await this.getActorMembership(userId, organizationId);
|
||||||
if (!actor || !this.canEditOrganizations(actor)) {
|
if (!actor || !this.canEditOrganizations(actor)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user