import type { PipeTransform } from '@nestjs/common' ; import { applyDecorators , Param , ParseUUIDPipe , SetMetadata , UseGuards , UseInterceptors , } from '@nestjs/common' ; import type { Type } from '@nestjs/common/interfaces' ; import { ApiBearerAuth , ApiUnauthorizedResponse } from '@nestjs/swagger' ; import type { RoleType } from '../constants' ; import { AuthGuard } from '../guards/auth.guard' ; import { RolesGuard } from '../guards/roles.guard' ; import { AuthUserInterceptor } from '../interceptors/auth-user-interceptor.service' ; import { PublicRoute } from './public-route.decorator' ; export function Auth ( roles = [ ] , options ? ) { const isPublicRoute = options ?. public ; return applyDecorators ( SetMetadata ( 'roles' , roles ) , UseGuards ( AuthGuard ( { public : isPublicRoute } ) , RolesGuard ) , ApiBearerAuth ( ) , UseInterceptors ( AuthUserInterceptor ) , ApiUnauthorizedResponse ( { description : 'Unauthorized' } ) , PublicRoute ( isPublicRoute ) ) ; } export function UUIDParam ( property , ... pipes ) { return Param ( property , new ParseUUIDPipe ( { version : '4' } ) , ... pipes ) ; }