import { Controller , Inject , Post , Body , UnauthorizedException } from '@nestjs/common' ; import { ApiTags , ApiOperation } from '@nestjs/swagger' ; import { IQueryBus } from 'src/Application/IQueryBus' ; import { LoginQuery } from 'src/Application/HumanResource/User/Query/LoginQuery' ; import { AuthenticatedView } from 'src/Application/HumanResource/User/View/AuthenticatedView' ; import { LoginDTO } from '../DTO/LoginDTO' ; @ Controller ( 'login' ) @ ApiTags ( 'Human Resource' ) export class LoginAction { constructor ( @ Inject ( 'IQueryBus' ) private readonly queryBus ) { } @ Post ( ) @ ApiOperation ( { summary : 'User authentication' } ) public async index ( @ Body ( ) loginDto ) { try { return await this . queryBus . execute ( new LoginQuery ( loginDto . email , loginDto . password ) ) ; } catch ( e ) { throw new UnauthorizedException ( e . message ) ; } } }