feat: Introduce agent types module, replacing categories and verification modules, and updating agent-related DTOs, services, and Prisma schema.
This commit is contained in:
@@ -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 },
|
||||
});
|
||||
|
||||
@@ -2,7 +2,6 @@ import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
||||
import {
|
||||
IsString,
|
||||
IsOptional,
|
||||
IsArray,
|
||||
IsInt,
|
||||
IsUrl,
|
||||
IsUUID,
|
||||
@@ -13,6 +12,14 @@ import {
|
||||
} from 'class-validator';
|
||||
|
||||
export class CreateAgentProfileDto {
|
||||
@ApiPropertyOptional({
|
||||
example: 'uuid-agent-type-id',
|
||||
description: 'Agent type ID (Professional, Lender, Advisor, etc.)',
|
||||
})
|
||||
@IsOptional()
|
||||
@IsUUID('4')
|
||||
agentTypeId?: string;
|
||||
|
||||
@ApiProperty({ example: 'John' })
|
||||
@IsString()
|
||||
@MinLength(1)
|
||||
@@ -116,13 +123,4 @@ export class CreateAgentProfileDto {
|
||||
@IsOptional()
|
||||
@IsUrl()
|
||||
instagramUrl?: string;
|
||||
|
||||
@ApiPropertyOptional({
|
||||
example: ['uuid-1', 'uuid-2'],
|
||||
description: 'Array of specialization IDs',
|
||||
})
|
||||
@IsOptional()
|
||||
@IsArray()
|
||||
@IsUUID('4', { each: true })
|
||||
specializationIds?: string[];
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import {
|
||||
IsBoolean,
|
||||
IsInt,
|
||||
IsUUID,
|
||||
IsArray,
|
||||
Min,
|
||||
Max,
|
||||
} from 'class-validator';
|
||||
@@ -32,20 +31,13 @@ export class SearchAgentsDto {
|
||||
@IsString()
|
||||
country?: string;
|
||||
|
||||
@ApiPropertyOptional({ example: 'uuid-of-category' })
|
||||
@IsOptional()
|
||||
@IsUUID()
|
||||
categoryId?: string;
|
||||
|
||||
@ApiPropertyOptional({
|
||||
example: ['uuid-1', 'uuid-2'],
|
||||
description: 'Filter by specialization IDs',
|
||||
example: 'uuid-of-agent-type',
|
||||
description: 'Filter by agent type ID',
|
||||
})
|
||||
@IsOptional()
|
||||
@IsArray()
|
||||
@IsUUID('4', { each: true })
|
||||
@Transform(({ value }) => (typeof value === 'string' ? [value] : value))
|
||||
specializationIds?: string[];
|
||||
@IsUUID()
|
||||
agentTypeId?: string;
|
||||
|
||||
@ApiPropertyOptional({ example: true })
|
||||
@IsOptional()
|
||||
|
||||
Reference in New Issue
Block a user