Completed
Push — master ( 7c7ab7...45cb8f )
by Mathieu
19s queued 11s
created

server/src/Infrastructure/HumanResource/User/Action/LoginAction.ts   A

Complexity

Total Complexity 2
Complexity/F 2

Size

Lines of Code 34
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 29
mnd 1
bc 1
fnc 1
dl 0
loc 34
bpm 1
cpm 2
noi 0
c 0
b 0
f 0
rs 10

1 Function

Rating   Name   Duplication   Size   Complexity  
A LoginAction.index 0 10 2
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