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
|
// REGISTER
|
||||||
// ==========================================
|
// ==========================================
|
||||||
async register(dto: RegisterDto) {
|
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
|
// Check if user exists
|
||||||
const existingUser = await this.prisma.user.findUnique({
|
const existingUser = await this.prisma.user.findUnique({
|
||||||
where: { email: dto.email.toLowerCase() },
|
where: { email: dto.email.toLowerCase() },
|
||||||
@@ -79,6 +95,7 @@ export class AuthService {
|
|||||||
slug,
|
slug,
|
||||||
firstName: dto.firstName,
|
firstName: dto.firstName,
|
||||||
lastName: dto.lastName,
|
lastName: dto.lastName,
|
||||||
|
...(dto.agentTypeId && { agentTypeId: dto.agentTypeId }),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
Matches,
|
Matches,
|
||||||
IsEnum,
|
IsEnum,
|
||||||
IsOptional,
|
IsOptional,
|
||||||
|
IsUUID,
|
||||||
} from 'class-validator';
|
} from 'class-validator';
|
||||||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
||||||
import { UserRole } from '@prisma/client';
|
import { UserRole } from '@prisma/client';
|
||||||
@@ -62,4 +63,12 @@ export class RegisterDto {
|
|||||||
@IsString()
|
@IsString()
|
||||||
@MaxLength(50)
|
@MaxLength(50)
|
||||||
lastName?: string;
|
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