feat: Implement agent verification system with a new status enum, admin update functionality, and document retrieval.
This commit is contained in:
@@ -28,7 +28,7 @@ import { RolesGuard } from '../auth/guards/roles.guard';
|
||||
import { Roles } from '../auth/decorators/roles.decorator';
|
||||
import { Public } from '../auth/decorators/public.decorator';
|
||||
import { CurrentUser } from '../auth/decorators/current-user.decorator';
|
||||
import { UserRole } from '@prisma/client';
|
||||
import { UserRole, VerificationStatus } from '@prisma/client';
|
||||
|
||||
@ApiTags('agents')
|
||||
@Controller('agents')
|
||||
@@ -193,14 +193,19 @@ export class AgentsController {
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(UserRole.ADMIN)
|
||||
@ApiBearerAuth()
|
||||
@ApiOperation({ summary: 'Admin: Verify/unverify agent' })
|
||||
@ApiOperation({ summary: 'Admin: Update agent verification status' })
|
||||
@ApiResponse({ status: 200, description: 'Verification status updated' })
|
||||
@ApiResponse({ status: 404, description: 'Profile not found' })
|
||||
async adminVerifyAgent(
|
||||
@Param('id', ParseUUIDPipe) id: string,
|
||||
@Body('isVerified') isVerified: boolean,
|
||||
@Body() data: { status: VerificationStatus; note?: string },
|
||||
@CurrentUser() admin: { id: string },
|
||||
) {
|
||||
return this.agentsService.adminVerifyAgent(id, isVerified);
|
||||
return this.agentsService.adminVerifyAgent(id, {
|
||||
status: data.status,
|
||||
note: data.note,
|
||||
adminId: admin.id,
|
||||
});
|
||||
}
|
||||
|
||||
@Put('admin/:id/featured')
|
||||
|
||||
@@ -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 },
|
||||
|
||||
Reference in New Issue
Block a user