From 0abbe6beded069b9651e72d8b8bcc75129ec5a37 Mon Sep 17 00:00:00 2001 From: pradeepkumar Date: Mon, 26 Jan 2026 22:48:51 +0530 Subject: [PATCH] feat: Add agent type ID field to registration DTO and implement validation for agent role registration. --- src/auth/auth.service.ts | 17 +++++++++++++++++ src/auth/dto/register.dto.ts | 9 +++++++++ 2 files changed, 26 insertions(+) diff --git a/src/auth/auth.service.ts b/src/auth/auth.service.ts index b3e74c3..ad75007 100644 --- a/src/auth/auth.service.ts +++ b/src/auth/auth.service.ts @@ -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 }), }, }); } diff --git a/src/auth/dto/register.dto.ts b/src/auth/dto/register.dto.ts index afeffed..1110adb 100644 --- a/src/auth/dto/register.dto.ts +++ b/src/auth/dto/register.dto.ts @@ -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; }