| Total Complexity | 2 |
| Complexity/F | 2 |
| Lines of Code | 34 |
| Function Count | 1 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import { |
||
| 2 | Controller, |
||
| 3 | Inject, |
||
| 4 | Post, |
||
| 5 | Body, |
||
| 6 | UnauthorizedException |
||
| 7 | } from '@nestjs/common'; |
||
| 8 | import {ApiUseTags, ApiOperation} from '@nestjs/swagger'; |
||
| 9 | import {IQueryBus} from 'src/Application/IQueryBus'; |
||
| 10 | import {LoginQuery} from 'src/Application/HumanResource/User/Query/LoginQuery'; |
||
| 11 | import {AuthenticatedView} from 'src/Application/HumanResource/User/View/AuthenticatedView'; |
||
| 12 | import {LoginDTO} from '../DTO/LoginDTO'; |
||
| 13 | |||
| 14 | @Controller('login') |
||
| 15 | @ApiUseTags('User') |
||
| 16 | export class LoginAction { |
||
| 17 | constructor( |
||
| 18 | @Inject('IQueryBus') |
||
| 19 | private readonly queryBus: IQueryBus |
||
| 20 | ) {} |
||
| 21 | |||
| 22 | @Post() |
||
| 23 | @ApiOperation({title: 'User authentication'}) |
||
| 24 | public async index(@Body() loginDto: LoginDTO): Promise<AuthenticatedView> { |
||
| 25 | try { |
||
| 26 | return await this.queryBus.execute( |
||
| 27 | new LoginQuery(loginDto.email, loginDto.password) |
||
| 28 | ); |
||
| 29 | } catch (e) { |
||
| 30 | throw new UnauthorizedException(e.message); |
||
| 31 | } |
||
| 32 | } |
||
| 33 | } |
||
| 34 |