feat: Implement agent verification system with a new status enum, admin update functionality, and document retrieval.

This commit is contained in:
pradeepkumar
2026-01-28 13:48:14 +05:30
parent dfd8bc38a5
commit eece0f7401
5 changed files with 208 additions and 12 deletions

View File

@@ -10,7 +10,7 @@ import {
SearchAgentsDto,
SaveFieldValuesDto,
} from './dto';
import { Prisma, Prisma as PrismaTypes } from '@prisma/client';
import { Prisma, Prisma as PrismaTypes, VerificationStatus } from '@prisma/client';
function generateSlug(firstName: string, lastName: string): string {
const base = `${firstName}-${lastName}`
@@ -312,7 +312,14 @@ export class AgentsService {
return { message: 'Agent profile deleted successfully' };
}
async adminVerifyAgent(profileId: string, isVerified: boolean) {
async adminVerifyAgent(
profileId: string,
data: {
status: VerificationStatus;
note?: string;
adminId: string;
},
) {
const profile = await this.prisma.agentProfile.findUnique({
where: { id: profileId },
});
@@ -321,9 +328,24 @@ export class AgentsService {
throw new NotFoundException('Agent profile not found');
}
const updateData: Prisma.AgentProfileUpdateInput = {
verificationStatus: data.status,
verificationNote: data.note || null,
};
if (data.status === VerificationStatus.APPROVED) {
updateData.isVerified = true;
updateData.verifiedAt = new Date();
updateData.verifiedBy = data.adminId;
} else if (data.status === VerificationStatus.REJECTED) {
updateData.isVerified = false;
updateData.verifiedAt = null;
updateData.verifiedBy = null;
}
const updatedProfile = await this.prisma.agentProfile.update({
where: { id: profileId },
data: { isVerified },
data: updateData,
include: {
user: {
select: {
@@ -338,6 +360,26 @@ export class AgentsService {
return updatedProfile;
}
async getVerificationDocuments(agentProfileId: string) {
// Find the upload-documents section field
const field = await this.prisma.profileField.findFirst({
where: {
section: { slug: 'upload-documents' },
slug: 'documents',
},
});
if (!field) return [];
const fieldValue = await this.prisma.agentProfileFieldValue.findUnique({
where: {
agentProfileId_fieldId: { agentProfileId, fieldId: field.id },
},
});
return fieldValue?.jsonValue || [];
}
async adminSetFeatured(profileId: string, isFeatured: boolean) {
const profile = await this.prisma.agentProfile.findUnique({
where: { id: profileId },