Total Complexity | 1 |
Complexity/F | 1 |
Lines of Code | 41 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import { CommandHandler } from '@nestjs/cqrs'; |
||
2 | import { Inject } from '@nestjs/common'; |
||
3 | import { CreateEventCommand } from './CreateEventCommand'; |
||
4 | import { IEventRepository } from 'src/Domain/Calendar/Repository/IEventRepository'; |
||
5 | import { ISchoolRepository } from 'src/Domain/School/Repository/ISchoolRepository'; |
||
6 | import { Event } from 'src/Domain/Calendar/Event.entity'; |
||
7 | import { IUserRepository } from 'src/Domain/User/Repository/IUserRepository'; |
||
8 | import { AbstractEventCommandHandler } from './AbstractEventCommandHandler'; |
||
9 | |||
10 | @CommandHandler(CreateEventCommand) |
||
11 | export class CreateEventCommandHandler extends AbstractEventCommandHandler { |
||
12 | constructor( |
||
13 | @Inject('ISchoolRepository') schoolRepository: ISchoolRepository, |
||
14 | @Inject('IUserRepository') userRepository: IUserRepository, |
||
15 | @Inject('IEventRepository') |
||
16 | private readonly eventRepository: IEventRepository, |
||
17 | ) { |
||
18 | super(schoolRepository, userRepository); |
||
19 | } |
||
20 | |||
21 | public async execute(command: CreateEventCommand): Promise<string> { |
||
22 | const { date, summary, userId, schoolId } = command; |
||
23 | |||
24 | const [ user, school ] = await Promise.all([ |
||
25 | this.getUser(userId), |
||
26 | this.getSchool(schoolId) |
||
27 | ]); |
||
28 | |||
29 | const event = await this.eventRepository.save( |
||
30 | new Event( |
||
31 | date, |
||
32 | user, |
||
33 | school, |
||
34 | summary |
||
35 | ) |
||
36 | ); |
||
37 | |||
38 | return event.getId(); |
||
39 | } |
||
40 | } |
||
41 |