@@ -37,6 +37,7 @@ import {
37
37
ApiConsumes ,
38
38
ApiOperation ,
39
39
ApiQuery ,
40
+ ApiParam ,
40
41
ApiResponse ,
41
42
ApiTags ,
42
43
} from "@nestjs/swagger" ;
@@ -48,6 +49,7 @@ import { JWTUser } from "src/auth/interfaces/jwt-user.interface";
48
49
import { AccessGroupsType } from "src/config/configuration" ;
49
50
import { Logger } from "@nestjs/common" ;
50
51
import { UsersService } from "src/users/users.service" ;
52
+ import { FullFacetResponse } from "src/common/types" ;
51
53
import {
52
54
filterDescriptionSimplified ,
53
55
filterExampleSimplified ,
@@ -710,7 +712,7 @@ export class JobsController {
710
712
description : "It creates a new job." ,
711
713
} )
712
714
@ApiBody ( {
713
- description : "Input fields for the job to be created" ,
715
+ description : "Input fields for the job to be created. " ,
714
716
required : true ,
715
717
type : CreateJobDtoV3 ,
716
718
} )
@@ -831,6 +833,11 @@ export class JobsController {
831
833
summary : "It updates an existing job." ,
832
834
description : "It updates an existing job." ,
833
835
} )
836
+ @ApiParam ( {
837
+ name : "id" ,
838
+ description : "Id of the job to be modified." ,
839
+ type : String ,
840
+ } )
834
841
@ApiBody ( {
835
842
description : "Fields for the job to be updated" ,
836
843
required : true ,
@@ -866,6 +873,11 @@ export class JobsController {
866
873
"It updates an existing job. Set `content-type` to `application/merge-patch+json` if you would like to update nested objects. Warning! `application/merge-patch+json` doesn’t support updating a specific item in an array — the result will always replace the entire target if it’s not an object." ,
867
874
} )
868
875
@ApiConsumes ( "application/json" , "application/merge-patch+json" )
876
+ @ApiParam ( {
877
+ name : "id" ,
878
+ description : "Id of the job to be modified." ,
879
+ type : String ,
880
+ } )
869
881
@ApiBody ( {
870
882
description : "Fields for the job to be updated" ,
871
883
required : true ,
@@ -896,7 +908,9 @@ export class JobsController {
896
908
fields : JSON . parse ( filters . fields ?? ( "{}" as string ) ) ,
897
909
limits : JSON . parse ( filters . limits ?? ( "{}" as string ) ) ,
898
910
} ;
899
- const jobsFound = await this . jobsService . fullquery ( parsedFilters ) ;
911
+ const jobsFound = await this . jobsService . findByFilters (
912
+ parsedFilters . fields ,
913
+ ) ;
900
914
const jobsAccessible : JobClass [ ] = [ ] ;
901
915
902
916
// for each job run a casl JobReadOwner on a jobInstance
@@ -921,7 +935,10 @@ export class JobsController {
921
935
}
922
936
}
923
937
}
924
- return jobsAccessible ;
938
+ return this . jobsService . applyFilterLimits (
939
+ jobsAccessible ,
940
+ parsedFilters . limits ,
941
+ ) ;
925
942
} catch ( e ) {
926
943
throw new HttpException (
927
944
{
@@ -1029,33 +1046,11 @@ export class JobsController {
1029
1046
) : Promise < Record < string , unknown > [ ] > {
1030
1047
try {
1031
1048
const fields : IJobFields = JSON . parse ( filters . fields ?? ( "{}" as string ) ) ;
1032
- const queryFilters : IFilters < JobDocument , FilterQuery < JobDocument > > = {
1033
- fields : fields ,
1034
- limits : JSON . parse ( "{}" as string ) ,
1035
- } ;
1036
- const jobsFound = await this . jobsService . fullquery ( queryFilters ) ;
1049
+ const jobsFound = await this . fullQueryJobs ( request , filters ) ;
1037
1050
const jobIdsAccessible : string [ ] = [ ] ;
1038
-
1039
- // for each job run a casl JobReadOwner on a jobInstance
1040
1051
if ( jobsFound != null ) {
1041
1052
for ( const i in jobsFound ) {
1042
- const jobConfiguration = this . getJobTypeConfiguration (
1043
- jobsFound [ i ] . type ,
1044
- ) ;
1045
- const ability = this . caslAbilityFactory . jobsInstanceAccess (
1046
- request . user as JWTUser ,
1047
- jobConfiguration ,
1048
- ) ;
1049
- // check if the user can get this job
1050
- const jobInstance = await this . generateJobInstanceForPermissions (
1051
- jobsFound [ i ] ,
1052
- ) ;
1053
- const canRead =
1054
- ability . can ( Action . JobReadAny , JobClass ) ||
1055
- ability . can ( Action . JobReadAccess , jobInstance ) ;
1056
- if ( canRead ) {
1057
- jobIdsAccessible . push ( jobsFound [ i ] . _id ) ;
1058
- }
1053
+ jobIdsAccessible . push ( jobsFound [ i ] . _id ) ;
1059
1054
}
1060
1055
}
1061
1056
fields . _id = { $in : jobIdsAccessible } ;
@@ -1092,21 +1087,25 @@ export class JobsController {
1092
1087
@ApiQuery ( {
1093
1088
name : "fields" ,
1094
1089
description :
1095
- "Define the filter conditions by specifying the name of values of fields requested." ,
1090
+ "Define the filter conditions by specifying the values of fields requested.\n" +
1091
+ jobsFullQueryDescriptionFields ,
1096
1092
required : false ,
1097
1093
type : String ,
1094
+ example : jobsFullQueryExampleFields ,
1098
1095
} )
1099
1096
@ApiQuery ( {
1100
1097
name : "facets" ,
1101
1098
description :
1102
1099
"Define a list of field names, for which facet counts should be calculated." ,
1103
1100
required : false ,
1104
1101
type : String ,
1102
+ example : '["type","ownerGroup","statusCode"]' ,
1105
1103
} )
1106
1104
@ApiResponse ( {
1107
1105
status : HttpStatus . OK ,
1108
- type : [ Object ] ,
1109
- description : "Return jobs requested." ,
1106
+ type : FullFacetResponse ,
1107
+ isArray : true ,
1108
+ description : "Return fullfacet response for jobs requested." ,
1110
1109
} )
1111
1110
async fullFacetV3 (
1112
1111
@Req ( ) request : Request ,
@@ -1132,21 +1131,25 @@ export class JobsController {
1132
1131
@ApiQuery ( {
1133
1132
name : "fields" ,
1134
1133
description :
1135
- "Define the filter conditions by specifying the name of values of fields requested." ,
1134
+ "Define the filter conditions by specifying the values of fields requested.\n" +
1135
+ jobsFullQueryDescriptionFields ,
1136
1136
required : false ,
1137
1137
type : String ,
1138
+ example : jobsFullQueryExampleFields ,
1138
1139
} )
1139
1140
@ApiQuery ( {
1140
1141
name : "facets" ,
1141
1142
description :
1142
1143
"Define a list of field names, for which facet counts should be calculated." ,
1143
1144
required : false ,
1144
1145
type : String ,
1146
+ example : '["type","ownerGroup","statusCode"]' ,
1145
1147
} )
1146
1148
@ApiResponse ( {
1147
1149
status : HttpStatus . OK ,
1148
- type : [ Object ] ,
1149
- description : "Return jobs requested." ,
1150
+ type : FullFacetResponse ,
1151
+ isArray : true ,
1152
+ description : "Return fullfacet response for jobs requested." ,
1150
1153
} )
1151
1154
async fullFacetV4 (
1152
1155
@Req ( ) request : Request ,
@@ -1202,6 +1205,11 @@ export class JobsController {
1202
1205
summary : "It returns the requested job." ,
1203
1206
description : "It returns the requested job." ,
1204
1207
} )
1208
+ @ApiParam ( {
1209
+ name : "id" ,
1210
+ description : "Id of the job to be retrieved." ,
1211
+ type : String ,
1212
+ } )
1205
1213
@ApiResponse ( {
1206
1214
status : HttpStatus . OK ,
1207
1215
type : OutputJobV3Dto ,
@@ -1228,6 +1236,11 @@ export class JobsController {
1228
1236
summary : "It returns the requested job." ,
1229
1237
description : "It returns the requested job." ,
1230
1238
} )
1239
+ @ApiParam ( {
1240
+ name : "id" ,
1241
+ description : "Id of the job to be retrieved." ,
1242
+ type : String ,
1243
+ } )
1231
1244
@ApiResponse ( {
1232
1245
status : HttpStatus . OK ,
1233
1246
type : JobClass ,
@@ -1260,7 +1273,9 @@ export class JobsController {
1260
1273
throw { message : "Invalid filter syntax." } ;
1261
1274
}
1262
1275
// for each job run a casl JobReadOwner on a jobInstance
1263
- const jobsFound = await this . jobsService . findAll ( parsedFilter ) ;
1276
+ const jobsFound = await this . jobsService . findByFilters (
1277
+ parsedFilter . where ,
1278
+ ) ;
1264
1279
const jobsAccessible : JobClass [ ] = [ ] ;
1265
1280
1266
1281
for ( const i in jobsFound ) {
@@ -1282,7 +1297,10 @@ export class JobsController {
1282
1297
jobsAccessible . push ( jobsFound [ i ] ) ;
1283
1298
}
1284
1299
}
1285
- return jobsAccessible ;
1300
+ return this . jobsService . applyFilterLimits (
1301
+ jobsAccessible ,
1302
+ parsedFilter . limits ,
1303
+ ) ;
1286
1304
} catch ( e ) {
1287
1305
throw new HttpException (
1288
1306
{
@@ -1376,6 +1394,11 @@ export class JobsController {
1376
1394
summary : "It deletes the requested job." ,
1377
1395
description : "It deletes the requested job." ,
1378
1396
} )
1397
+ @ApiParam ( {
1398
+ name : "id" ,
1399
+ description : "Id of the job to be deleted." ,
1400
+ type : String ,
1401
+ } )
1379
1402
@ApiResponse ( {
1380
1403
status : HttpStatus . OK ,
1381
1404
type : undefined ,
@@ -1412,6 +1435,11 @@ export class JobsController {
1412
1435
summary : "It deletes the requested job." ,
1413
1436
description : "It deletes the requested job." ,
1414
1437
} )
1438
+ @ApiParam ( {
1439
+ name : "id" ,
1440
+ description : "Id of the job to be deleted." ,
1441
+ type : String ,
1442
+ } )
1415
1443
@ApiResponse ( {
1416
1444
status : HttpStatus . OK ,
1417
1445
type : undefined ,
0 commit comments