api/src/Application/Calendar/Command/CreateEventCommandHandler.ts   A
last analyzed

Complexity

Total Complexity 1
Complexity/F 1

Size

Lines of Code 41
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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

1 Function

Rating   Name   Duplication   Size   Complexity  
A CreateEventCommandHandler.execute 0 19 1
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