feat: implement privacy-aware profile visibility and activity status filtering using optional authentication guard

This commit is contained in:
pradeepkumar
2026-03-28 18:46:49 +05:30
parent ba931c350b
commit a71145f6a6
8 changed files with 235 additions and 38 deletions

View File

@@ -17,6 +17,50 @@ export class ConnectionRequestsService {
private eventEmitter: EventEmitter2,
) {}
/**
* Check if a user is connected to an agent (ACCEPTED connection exists)
*/
async isConnected(userId: string, agentUserId: string): Promise<boolean> {
const connection = await this.prisma.connectionRequest.findFirst({
where: {
status: ConnectionStatus.ACCEPTED,
OR: [
// User → Agent connection
{ userId, agentProfile: { userId: agentUserId } },
// Agent → User connection (if agent has a userId match)
{ userId: agentUserId, agentProfile: { userId } },
],
},
});
return !!connection;
}
/**
* Get all user IDs connected to a given user (ACCEPTED connections)
*/
async getConnectedUserIds(userId: string): Promise<string[]> {
const connections = await this.prisma.connectionRequest.findMany({
where: {
status: ConnectionStatus.ACCEPTED,
OR: [
{ userId },
{ agentProfile: { userId } },
],
},
select: {
userId: true,
agentProfile: { select: { userId: true } },
},
});
const connectedIds = new Set<string>();
for (const conn of connections) {
if (conn.userId !== userId) connectedIds.add(conn.userId);
if (conn.agentProfile.userId !== userId) connectedIds.add(conn.agentProfile.userId);
}
return Array.from(connectedIds);
}
/**
* Create a new connection request from user to agent
*/