feat: Add agent type ID field to registration DTO and implement validation for agent role registration.
This commit is contained in:
@@ -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 }),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
Matches,
|
||||
IsEnum,
|
||||
IsOptional,
|
||||
IsUUID,
|
||||
} from 'class-validator';
|
||||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
||||
import { UserRole } from '@prisma/client';
|
||||
@@ -62,4 +63,12 @@ export class RegisterDto {
|
||||
@IsString()
|
||||
@MaxLength(50)
|
||||
lastName?: string;
|
||||
|
||||
@ApiPropertyOptional({
|
||||
example: 'uuid-of-agent-type',
|
||||
description: 'Agent type ID (required when role is AGENT)',
|
||||
})
|
||||
@IsOptional()
|
||||
@IsUUID('4', { message: 'Agent type ID must be a valid UUID' })
|
||||
agentTypeId?: string;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user