File tree Expand file tree Collapse file tree 3 files changed +39
-3
lines changed Expand file tree Collapse file tree 3 files changed +39
-3
lines changed Original file line number Diff line number Diff line change 8
8
Param ,
9
9
Query ,
10
10
UseInterceptors ,
11
+ ValidationPipe ,
11
12
} from '@nestjs/common' ;
12
13
import {
13
14
ApiTags ,
@@ -56,7 +57,8 @@ export class ScorecardController {
56
57
} )
57
58
@ApiResponse ( { status : 403 , description : 'Forbidden.' } )
58
59
async addScorecard (
59
- @Body ( ) body : ScorecardRequestDto ,
60
+ @Body ( new ValidationPipe ( { whitelist : true , transform : true } ) )
61
+ body : ScorecardRequestDto ,
60
62
@User ( ) user : JwtUser ,
61
63
) : Promise < ScorecardWithGroupResponseDto > {
62
64
return await this . scorecardService . addScorecard ( body , user ) ;
@@ -84,7 +86,8 @@ export class ScorecardController {
84
86
@ApiResponse ( { status : 404 , description : 'Scorecard not found.' } )
85
87
async editScorecard (
86
88
@Param ( 'id' ) id : string ,
87
- @Body ( ) body : ScorecardRequestDto ,
89
+ @Body ( new ValidationPipe ( { whitelist : true , transform : true } ) )
90
+ body : ScorecardRequestDto ,
88
91
@User ( ) user : JwtUser ,
89
92
) : Promise < ScorecardWithGroupResponseDto > {
90
93
return await this . scorecardService . editScorecard ( id , body , user ) ;
@@ -114,6 +117,7 @@ export class ScorecardController {
114
117
}
115
118
116
119
@Get ( '/:id' )
120
+ @Roles ( UserRole . Admin )
117
121
@Scopes ( Scope . ReadScorecard )
118
122
@ApiOperation ( {
119
123
summary : 'View a scorecard' ,
Original file line number Diff line number Diff line change 5
5
} from '@nestjs/common' ;
6
6
import { Prisma } from '@prisma/client' ;
7
7
import {
8
+ mapScorecardRequestForCreate ,
8
9
mapScorecardRequestToDto ,
9
10
ScorecardGroupBaseDto ,
10
11
ScorecardPaginatedResponseDto ,
@@ -33,7 +34,7 @@ export class ScoreCardService {
33
34
) : Promise < ScorecardWithGroupResponseDto > {
34
35
const data = await this . prisma . scorecard . create ( {
35
36
data : {
36
- ...( mapScorecardRequestToDto ( {
37
+ ...( mapScorecardRequestForCreate ( {
37
38
...body ,
38
39
createdBy : user . isMachine ? 'System' : ( user . userId as string ) ,
39
40
updatedBy : user . isMachine ? 'System' : ( user . userId as string ) ,
Original file line number Diff line number Diff line change @@ -322,6 +322,37 @@ export class ScorecardQueryDto {
322
322
scorecardTypesArray ?: $Enums . ScorecardType [ ] ;
323
323
}
324
324
325
+ export function mapScorecardRequestForCreate ( request : ScorecardRequestDto ) {
326
+ const userFields = {
327
+ ...( request . createdBy ? { createdBy : request . createdBy } : { } ) ,
328
+ updatedBy : request . updatedBy ,
329
+ } ;
330
+
331
+ return {
332
+ ...request ,
333
+ ...userFields ,
334
+ scorecardGroups : {
335
+ create : request . scorecardGroups . map ( ( group ) => ( {
336
+ ...group ,
337
+ ...userFields ,
338
+ sections : {
339
+ create : group . sections . map ( ( section ) => ( {
340
+ ...section ,
341
+ ...userFields ,
342
+ questions : {
343
+ create : section . questions . map ( ( question ) => ( {
344
+ ...question ,
345
+ sortOrder : 1 ,
346
+ ...userFields ,
347
+ } ) ) ,
348
+ } ,
349
+ } ) ) ,
350
+ } ,
351
+ } ) ) ,
352
+ } ,
353
+ } ;
354
+ }
355
+
325
356
export function mapScorecardRequestToDto ( request : ScorecardRequestDto ) {
326
357
const userFields = {
327
358
...( request . createdBy ? { createdBy : request . createdBy } : { } ) ,
You can’t perform that action at this time.
0 commit comments