Passed
Pull Request — master (#56)
by
unknown
03:10 queued 01:29
created

api/src/Infrastructure/Ingestion/Action/CreateFileIngestionAction.ts   A

Complexity

Total Complexity 2
Complexity/F 2

Size

Lines of Code 53
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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

1 Function

Rating   Name   Duplication   Size   Complexity  
A CreateFileIngestionAction.index 0 20 2
1
import {
2
  Controller,
3
  Inject,
4
  UseGuards,
5
  Post,
6
  Param,
7
  BadRequestException
8
} from '@nestjs/common';
9
import { AuthGuard } from '@nestjs/passport';
10
import { ApiTags, ApiBearerAuth, ApiOperation } from '@nestjs/swagger';
11
import { IdDTO } from 'src/Infrastructure/Common/DTO/IdDTO';
12
import { Roles } from 'src/Infrastructure/User/Decorator/Roles';
13
import { RolesGuard } from 'src/Infrastructure/User/Security/RolesGuard';
14
import { SchoolUploadEndpointView } from 'src/Application/School/View/SchoolUploadEndpointView';
15
import { IFileUpload } from 'src/Application/IFileUpload';
16
import { CreateIngestionCommand } from 'src/Application/Ingestion/Command/CreateIngestionCommand';
17
import { ICommandBus } from '@nestjs/cqrs';
18
19
@Controller('ingestions')
20
@ApiTags('Ingestion')
21
@ApiBearerAuth()
22
@UseGuards(AuthGuard('bearer'), RolesGuard)
23
export class CreateFileIngestionAction {
24
  constructor(
25
    @Inject('ICommandBus')
26
    private readonly commandBus: ICommandBus,
27
    @Inject('IFileUpload')
28
    private readonly fileUploadAdapter: IFileUpload
29
  ) {}
30
31
  @Post(':id/photos')
32
  @Roles('photographer')
33
  @ApiOperation({
34
    summary:
35
      'Create ingestion for a school, and return enpoint to upload files containing photos'
36
  })
37
  public async index(@Param() idDto: IdDTO): Promise<SchoolUploadEndpointView> {
38
    try {
39
      const ingestionId = await this.commandBus.execute(
40
        new CreateIngestionCommand(idDto.id)
41
      );
42
43
      const url = await this.fileUploadAdapter.getEndPoint(
44
        `upload/photo/${ingestionId}.zip`
45
      );
46
47
      return new SchoolUploadEndpointView(url);
48
    } catch (e) {
49
      throw new BadRequestException(e.message);
50
    }
51
  }
52
}
53