Total Complexity | 2 |
Complexity/F | 2 |
Lines of Code | 34 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import { Inject } from '@nestjs/common'; |
||
2 | import { CommandHandler } from '@nestjs/cqrs'; |
||
3 | import { Ingestion } from 'src/Domain/Ingestion/Ingestion.entity'; |
||
4 | import { SchoolNotFoundException } from 'src/Domain/School/Exception/SchoolNotFoundException'; |
||
5 | import { IIngestionRepository } from 'src/Domain/Ingestion/Repository/IIngestionRepository'; |
||
6 | import { ISchoolRepository } from 'src/Domain/School/Repository/ISchoolRepository'; |
||
7 | import { CreateIngestionCommand } from './CreateIngestionCommand'; |
||
8 | |||
9 | @CommandHandler(CreateIngestionCommand) |
||
10 | export class CreateIngestionCommandHandler { |
||
11 | constructor( |
||
12 | @Inject('ISchoolRepository') |
||
13 | private readonly schoolRepository: ISchoolRepository, |
||
14 | @Inject('IIngestionRepository') |
||
15 | private readonly ingestionRepository: IIngestionRepository, |
||
16 | ) {} |
||
17 | |||
18 | public async execute(command: CreateIngestionCommand): Promise<string> { |
||
19 | const { schoolId } = command; |
||
20 | const school = await this.schoolRepository.findOneById(schoolId); |
||
21 | if (!school) { |
||
22 | throw new SchoolNotFoundException(); |
||
23 | } |
||
24 | |||
25 | const ingestion = await this.ingestionRepository.save( |
||
26 | new Ingestion( |
||
27 | school |
||
28 | ) |
||
29 | ); |
||
30 | |||
31 | return ingestion.getId(); |
||
32 | } |
||
33 | } |
||
34 |