-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathcommon.controller.ts
More file actions
80 lines (73 loc) · 2.3 KB
/
common.controller.ts
File metadata and controls
80 lines (73 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { FileInterceptor } from '@nestjs/platform-express';
import { ApiTags, ApiOperation, ApiSecurity, ApiExcludeEndpoint, ApiConsumes } from '@nestjs/swagger';
import {
Body,
Controller,
Post,
Get,
UseGuards,
Query,
BadRequestException,
UseInterceptors,
UploadedFile,
} from '@nestjs/common';
import { ACCESS_KEY_NAME, IImportConfig } from '@impler/shared';
import { JwtAuthGuard } from '@shared/framework/auth.gaurd';
import { ValidRequestDto, SignedUrlDto } from './dtos';
import { ValidImportFile } from '@shared/validations/valid-import-file.validation';
import { ValidRequestCommand, GetSignedUrl, ValidRequest, GetImportConfig, GetSheetNames } from './usecases';
@ApiTags('Common')
@Controller('/common')
@ApiSecurity(ACCESS_KEY_NAME)
@UseGuards(JwtAuthGuard)
export class CommonController {
constructor(
private validRequest: ValidRequest,
private getSignedUrl: GetSignedUrl,
private getSheetNames: GetSheetNames,
private getImportConfig: GetImportConfig
) {}
@Post('/valid')
@ApiOperation({
summary: 'Check if request is valid (Checks Auth)',
})
async isRequestValid(@Body() body: ValidRequestDto): Promise<{ success: boolean }> {
return await this.validRequest.execute(
ValidRequestCommand.create({
projectId: body.projectId,
templateId: body.templateId,
schema: body.schema,
})
);
}
@Post('/signed-url')
@ApiOperation({
summary: 'Get signed url for the filename',
})
@ApiExcludeEndpoint()
async getSignedUrlRoute(@Body() body: SignedUrlDto): Promise<string> {
return this.getSignedUrl.execute(body.key);
}
@Get('/import-config')
@ApiOperation({
summary: 'Get import config',
})
async getImportConfigRoute(
@Query('projectId') projectId: string,
@Query('templateId') templateId: string
): Promise<IImportConfig> {
if (!projectId) {
throw new BadRequestException();
}
return this.getImportConfig.execute(projectId, templateId);
}
@Post('/sheet-names')
@ApiOperation({
summary: 'Get sheet names for user selected file',
})
@ApiConsumes('multipart/form-data')
@UseInterceptors(FileInterceptor('file'))
async getSheetNamesRoute(@UploadedFile('file', ValidImportFile) file: Express.Multer.File): Promise<string[]> {
return this.getSheetNames.execute({ file });
}
}