feat: Add agent type ID field to registration DTO and implement validation for agent role registration.

This commit is contained in:
pradeepkumar
2026-01-26 22:48:51 +05:30
parent 75d1dc2914
commit 0abbe6bede
2 changed files with 26 additions and 0 deletions

View File

@@ -36,6 +36,22 @@ export class AuthService {
// REGISTER
// ==========================================
async register(dto: RegisterDto) {
// Validate agentTypeId is required for AGENT role
if (dto.role === 'AGENT') {
if (!dto.agentTypeId) {
throw new BadRequestException('Agent type is required for agent registration');
}
// Verify agent type exists
const agentType = await this.prisma.agentType.findUnique({
where: { id: dto.agentTypeId },
});
if (!agentType) {
throw new BadRequestException('Invalid agent type selected');
}
}
// Check if user exists
const existingUser = await this.prisma.user.findUnique({
where: { email: dto.email.toLowerCase() },
@@ -79,6 +95,7 @@ export class AuthService {
slug,
firstName: dto.firstName,
lastName: dto.lastName,
...(dto.agentTypeId && { agentTypeId: dto.agentTypeId }),
},
});
}