| Total Complexity | 2 |
| Complexity/F | 2 |
| Lines of Code | 53 |
| Function Count | 1 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 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 |