Total Complexity | 2 |
Complexity/F | 1 |
Lines of Code | 28 |
Function Count | 2 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import { Inject, Injectable } from '@nestjs/common'; |
||
2 | import { PassportSerializer } from '@nestjs/passport'; |
||
3 | import { AuthenticatedView } from 'src/Application/HumanResource/User/View/AuthenticatedView'; |
||
4 | import { IUserRepository } from 'src/Domain/HumanResource/User/Repository/IUserRepository'; |
||
5 | |||
6 | @Injectable() |
||
7 | export class UserSerializer extends PassportSerializer { |
||
8 | constructor( |
||
9 | @Inject('IUserRepository') |
||
10 | private readonly userRepository: IUserRepository |
||
11 | ) { |
||
12 | super(); |
||
13 | } |
||
14 | |||
15 | serializeUser(user: AuthenticatedView, done: Function) { |
||
16 | done(null, user); |
||
17 | } |
||
18 | |||
19 | public async deserializeUser( |
||
20 | view: AuthenticatedView, |
||
21 | done: Function |
||
22 | ): Promise<void> { |
||
23 | const user = await this.userRepository.findOneById(view.id); |
||
24 | |||
25 | done(null, user); |
||
26 | } |
||
27 | } |
||
28 |