feat: Introduce agent types module, replacing categories and verification modules, and updating agent-related DTOs, services, and Prisma schema.

This commit is contained in:
pradeepkumar
2026-01-20 12:16:01 +05:30
parent c04ca2bcef
commit 3df8ea067a
30 changed files with 345 additions and 1559 deletions

View File

@@ -1,7 +1,6 @@
import {
Injectable,
NotFoundException,
ForbiddenException,
ConflictException,
} from '@nestjs/common';
import { PrismaService } from '../prisma/prisma.service';
@@ -35,21 +34,13 @@ export class AgentsService {
throw new ConflictException('User already has an agent profile');
}
const { specializationIds, ...profileData } = dto;
const slug = generateSlug(dto.firstName, dto.lastName);
const profile = await this.prisma.agentProfile.create({
data: {
...profileData,
...dto,
userId,
slug,
specializations: specializationIds?.length
? {
create: specializationIds.map((specId) => ({
specializationId: specId,
})),
}
: undefined,
},
include: {
user: {
@@ -59,15 +50,7 @@ export class AgentsService {
avatar: true,
},
},
specializations: {
include: {
specialization: {
include: {
category: true,
},
},
},
},
agentType: true,
},
});
@@ -85,19 +68,7 @@ export class AgentsService {
avatar: true,
},
},
specializations: {
include: {
specialization: {
include: {
category: true,
},
},
},
},
verificationRequests: {
orderBy: { createdAt: 'desc' },
take: 5,
},
agentType: true,
},
});
@@ -119,15 +90,7 @@ export class AgentsService {
avatar: true,
},
},
specializations: {
include: {
specialization: {
include: {
category: true,
},
},
},
},
agentType: true,
},
});
@@ -147,29 +110,9 @@ export class AgentsService {
throw new NotFoundException('Agent profile not found');
}
const { specializationIds, ...profileData } = dto;
// If specializationIds is provided, update the specializations
if (specializationIds !== undefined) {
// Delete existing specializations
await this.prisma.agentSpecialization.deleteMany({
where: { agentProfileId: profile.id },
});
// Create new specializations
if (specializationIds.length > 0) {
await this.prisma.agentSpecialization.createMany({
data: specializationIds.map((specId) => ({
agentProfileId: profile.id,
specializationId: specId,
})),
});
}
}
const updatedProfile = await this.prisma.agentProfile.update({
where: { userId },
data: profileData,
data: dto,
include: {
user: {
select: {
@@ -178,15 +121,7 @@ export class AgentsService {
avatar: true,
},
},
specializations: {
include: {
specialization: {
include: {
category: true,
},
},
},
},
agentType: true,
},
});
@@ -199,8 +134,7 @@ export class AgentsService {
city,
state,
country,
categoryId,
specializationIds,
agentTypeId,
isVerified,
page = 1,
limit = 10,
@@ -239,24 +173,9 @@ export class AgentsService {
where.isVerified = isVerified;
}
// Filter by category
if (categoryId) {
where.specializations = {
some: {
specialization: {
categoryId,
},
},
};
}
// Filter by specializations
if (specializationIds?.length) {
where.specializations = {
some: {
specializationId: { in: specializationIds },
},
};
// Filter by agent type
if (agentTypeId) {
where.agentTypeId = agentTypeId;
}
// Build orderBy
@@ -285,15 +204,7 @@ export class AgentsService {
avatar: true,
},
},
specializations: {
include: {
specialization: {
include: {
category: true,
},
},
},
},
agentType: true,
},
}),
this.prisma.agentProfile.count({ where }),
@@ -326,15 +237,7 @@ export class AgentsService {
avatar: true,
},
},
specializations: {
include: {
specialization: {
include: {
category: true,
},
},
},
},
agentType: true,
},
});
@@ -357,15 +260,7 @@ export class AgentsService {
avatar: true,
},
},
specializations: {
include: {
specialization: {
include: {
category: true,
},
},
},
},
agentType: true,
},
});
@@ -382,26 +277,9 @@ export class AgentsService {
throw new NotFoundException('Agent profile not found');
}
const { specializationIds, ...profileData } = dto;
if (specializationIds !== undefined) {
await this.prisma.agentSpecialization.deleteMany({
where: { agentProfileId: profileId },
});
if (specializationIds.length > 0) {
await this.prisma.agentSpecialization.createMany({
data: specializationIds.map((specId) => ({
agentProfileId: profileId,
specializationId: specId,
})),
});
}
}
const updatedProfile = await this.prisma.agentProfile.update({
where: { id: profileId },
data: profileData,
data: dto,
include: {
user: {
select: {
@@ -410,15 +288,7 @@ export class AgentsService {
avatar: true,
},
},
specializations: {
include: {
specialization: {
include: {
category: true,
},
},
},
},
agentType: true,
},
});
@@ -434,15 +304,6 @@ export class AgentsService {
throw new NotFoundException('Agent profile not found');
}
// Delete related records first
await this.prisma.agentSpecialization.deleteMany({
where: { agentProfileId: profileId },
});
await this.prisma.verificationRequest.deleteMany({
where: { agentProfileId: profileId },
});
await this.prisma.agentProfile.delete({
where: { id: profileId },
});