Repository navigation
Expand file tree
/
Copy pathfile_delete.controller.ts
More file actions
74 lines (68 loc) · 1.78 KB
/
Copy pathfile_delete.controller.ts
File metadata and controls
74 lines (68 loc) · 1.78 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
import {
Body,
Controller,
Delete,
HttpStatus,
Inject,
OnModuleInit,
} from '@nestjs/common';
import { ClientGrpc } from '@nestjs/microservices';
import { lastValueFrom } from 'rxjs';
import { AuthCommonProto, FileProto } from 'juno-proto';
import {
ApiBearerAuth,
ApiOperation,
ApiResponse,
ApiTags,
} from '@nestjs/swagger';
import {
DeleteFilesModel,
DeleteFilesResponse,
} from 'src/models/file_delete.dto';
import { ApiKey } from 'src/decorators/api_key.decorator';
const { FILE_SERVICE_NAME } = FileProto;
@ApiBearerAuth('API_Key')
@ApiTags('file_delete')
@Controller('file')
export class FileDeleteController implements OnModuleInit {
private fileService: FileProto.FileServiceClient;
constructor(
@Inject(FILE_SERVICE_NAME)
private fileClient: ClientGrpc,
) {}
onModuleInit() {
this.fileService =
this.fileClient.getService<FileProto.FileServiceClient>(
FILE_SERVICE_NAME,
);
}
@Delete('delete')
@ApiOperation({ summary: 'Delete files from a bucket' })
@ApiResponse({
status: HttpStatus.BAD_REQUEST,
description: 'Parameters are invalid',
})
@ApiResponse({
status: HttpStatus.NOT_FOUND,
description: 'Bucket or file not found',
})
@ApiResponse({
status: HttpStatus.OK,
description: 'Returns the bucket name and list of deleted file names',
type: DeleteFilesResponse,
})
async deleteFiles(
@ApiKey() apiKey: AuthCommonProto.ApiKey,
@Body() params: DeleteFilesModel,
): Promise<DeleteFilesResponse> {
const res = await lastValueFrom(
this.fileService.deleteFiles({
bucketName: params.bucketName,
configId: params.configId,
configEnv: apiKey.environment,
fileNames: params.fileNames,
}),
);
return new DeleteFilesResponse(res);
}
}