import { Controller, Post, Body, Get, UseGuards, Request } from '@nestjs/common'; import { AuthService } from './auth.service'; import { JwtAuthGuard } from './guards/jwt-auth.guard'; import { IsString, IsIn, IsOptional } from 'class-validator'; class RegisterDto { @IsOptional() @IsString() email?: string; @IsOptional() @IsString() phone?: string; @IsString() password: string; @IsString() firstName: string; @IsString() lastName: string; @IsIn(['customer', 'driver', 'restaurant_owner']) role: string; } class LoginDto { @IsOptional() @IsString() email?: string; @IsOptional() @IsString() phone?: string; @IsString() password: string; } @Controller('auth') export class AuthController { constructor(private readonly authService: AuthService) {} @Post('register') register(@Body() dto: RegisterDto) { return this.authService.register(dto as any); } @Post('login') login(@Body() dto: LoginDto) { return this.authService.login(dto.email || dto.phone || '', dto.password); } @Get('me') @UseGuards(JwtAuthGuard) me(@Request() req) { return req.user; } }