feat: Introduce agent profile verification history tracking and status notifications for agents.

This commit is contained in:
pradeepkumar
2026-03-21 08:55:57 +05:30
parent 31439c3b06
commit 3e7e3683ed
4 changed files with 120 additions and 1 deletions

View File

@@ -1,6 +1,7 @@
import { Injectable, BadRequestException, NotFoundException, ForbiddenException } from '@nestjs/common';
import { UserStatus, UserRole, Prisma, VerificationStatus } from '@prisma/client';
import { PrismaService } from '../prisma/prisma.service';
import { EventEmitter2 } from '@nestjs/event-emitter';
import * as argon2 from 'argon2';
type UserWithProfiles = Prisma.UserGetPayload<{
@@ -9,7 +10,10 @@ type UserWithProfiles = Prisma.UserGetPayload<{
@Injectable()
export class UsersService {
constructor(private readonly prisma: PrismaService) {}
constructor(
private readonly prisma: PrismaService,
private readonly eventEmitter: EventEmitter2,
) {}
// =============================================
// USER PROFILE METHODS (for regular users)
@@ -390,6 +394,24 @@ export class UsersService {
},
});
// Save verification history
await this.prisma.verificationHistory.create({
data: {
agentProfileId: user.agentProfile.id,
status: data.status,
note: data.note || null,
adminId,
},
});
// Emit notification to the agent
this.eventEmitter.emit('notification.verification', {
recipientUserId: userId,
status: data.status,
note: data.note,
agentName: `${updatedProfile.firstName || ''} ${updatedProfile.lastName || ''}`.trim(),
});
return {
id: user.id,
agentProfileId: updatedProfile.id,
@@ -402,6 +424,17 @@ export class UsersService {
};
}
// Get verification history for an agent
async getVerificationHistory(agentProfileId: string) {
return this.prisma.verificationHistory.findMany({
where: { agentProfileId },
include: {
admin: { select: { id: true, email: true } },
},
orderBy: { createdAt: 'desc' },
});
}
// =============================================
// NOTIFICATION PREFERENCES
// =============================================