-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathpoint-data.controller.ts
135 lines (129 loc) · 4.06 KB
/
point-data.controller.ts
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import {
Body,
Controller,
Get,
Param,
Post,
Put,
Query,
UploadedFile,
UseGuards,
UseInterceptors,
} from '@nestjs/common';
import { FileInterceptor } from '@nestjs/platform-express';
import {
ApiBearerAuth,
ApiBody,
ApiConsumes,
ApiOperation,
ApiParam,
ApiQuery,
ApiResponse,
ApiTags,
} from '@nestjs/swagger';
import { Roles } from '../../roles.decorator';
import { RolesGuard } from '../../roles.guard';
import { GeoJson } from '../../shared/geo.model';
import { UserRole } from '../user/user-role.enum';
import { PointDataService } from './point-data.service';
import { UploadAssetExposureStatusDto } from './dto/upload-asset-exposure-status.dto';
import { FILE_UPLOAD_API_FORMAT } from '../../shared/file-upload-api-format';
@ApiBearerAuth()
@ApiTags('point-data')
@Controller('point-data')
export class PointDataController {
public constructor(private readonly pointDataService: PointDataService) {}
@UseGuards(RolesGuard)
@ApiOperation({
summary:
'Get point data locations and attributes for given country and point data layer',
})
@ApiParam({ name: 'countryCodeISO3', required: true, type: 'string' })
@ApiParam({ name: 'pointDataCategory', required: true, type: 'string' })
@ApiQuery({ name: 'disasterType', required: true, type: 'string' })
@ApiResponse({
status: 200,
description:
'Retrieved point data locations and attributes for given country and point data layer',
type: GeoJson,
})
@Get(':pointDataCategory/:countryCodeISO3')
public async getPointData(@Param() params, @Query() query): Promise<GeoJson> {
return await this.pointDataService.getPointDataByCountry(
params.pointDataCategory,
params.countryCodeISO3,
query.disasterType,
);
}
@UseGuards(RolesGuard)
@Roles(UserRole.Admin)
@ApiOperation({
summary:
'Upload (and overwrite) via CSV point data locations and attributes for given country and point data layer',
})
@ApiResponse({
status: 201,
description: 'Uploaded point data locations and attributes',
})
@ApiResponse({
status: 400,
description: 'Validation errors in content of CSV',
})
@ApiParam({ name: 'pointDataCategory', required: true, type: 'string' })
@ApiParam({ name: 'countryCodeISO3', required: true, type: 'string' })
@Post('upload-csv/:pointDataCategory/:countryCodeISO3')
@ApiConsumes('multipart/form-data')
@ApiBody(FILE_UPLOAD_API_FORMAT)
@UseInterceptors(FileInterceptor('file'))
public async uploadCsv(
@UploadedFile() pointDataData,
@Param() params,
): Promise<void> {
await this.pointDataService.uploadCsv(
pointDataData,
params.pointDataCategory,
params.countryCodeISO3,
);
}
@ApiOperation({ summary: 'Upload community notification' })
@ApiResponse({
status: 201,
description: 'Uploaded community notification.',
})
@ApiParam({ name: 'countryCodeISO3', required: true, type: 'string' })
@Post('community-notification/:countryCodeISO3')
public async uploadCommunityNotification(
@Param() params,
@Body() communityNotification: any,
): Promise<void> {
return await this.pointDataService.uploadCommunityNotification(
params.countryCodeISO3,
communityNotification,
);
}
@UseGuards(RolesGuard)
@ApiOperation({ summary: 'Dismiss community notification' })
@ApiResponse({
status: 201,
description: 'Dismissed community notification.',
})
@ApiParam({ name: 'pointDataId', required: true, type: 'string' })
@Put('community-notification/:pointDataId')
public async dismissCommunityNotification(@Param() params): Promise<void> {
return await this.pointDataService.dismissCommunityNotification(
params.pointDataId,
);
}
@UseGuards(RolesGuard)
@ApiOperation({ summary: 'Upload asset exposure status' })
@ApiResponse({
status: 201,
description: 'Uploaded asset exposure status.',
})
@Post('exposure-status')
public async uploadAssetExposureStatus(
@Body() assetFids: UploadAssetExposureStatusDto,
): Promise<void> {
return await this.pointDataService.uploadAssetExposureStatus(assetFids);
}
}