@@ -44,8 +44,21 @@ export class AdminController {
4444 private readonly tcMembersService : TopcoderMembersService ,
4545 ) { }
4646
47+ private isBaAdmin ( user ?: { roles ?: string [ ] } ) {
48+ return ( user ?. roles || [ ] ) . some (
49+ ( r ) =>
50+ r &&
51+ r . trim ( ) . toLowerCase ( ) === Role . PaymentBaAdmin . trim ( ) . toLowerCase ( ) ,
52+ ) ;
53+ }
54+
4755 @Post ( '/winnings/search' )
48- @Roles ( Role . PaymentAdmin , Role . PaymentEditor , Role . PaymentViewer )
56+ @Roles (
57+ Role . PaymentAdmin ,
58+ Role . PaymentBaAdmin ,
59+ Role . PaymentEditor ,
60+ Role . PaymentViewer ,
61+ )
4962 @ApiOperation ( {
5063 summary : 'Search winnings with parameters' ,
5164 description : 'Roles: Payment Admin, Payment Editor, Payment Viewer' ,
@@ -62,8 +75,16 @@ export class AdminController {
6275 @HttpCode ( HttpStatus . OK )
6376 async searchWinnings (
6477 @Body ( ) body : WinningRequestDto ,
78+ @User ( ) user : any ,
6579 ) : Promise < ResponseDto < SearchWinningResult > > {
66- const result = await this . winningsRepo . searchWinnings ( body ) ;
80+ const result = await this . winningsRepo . searchWinnings (
81+ await this . adminService . applyBaAdminUserFilters (
82+ user . id ,
83+ this . isBaAdmin ( user ) ,
84+ body ,
85+ ) ,
86+ ) ;
87+
6788 if ( result . error ) {
6889 result . status = ResponseStatusType . ERROR ;
6990 }
@@ -74,7 +95,12 @@ export class AdminController {
7495 }
7596
7697 @Post ( '/winnings/export' )
77- @Roles ( Role . PaymentAdmin , Role . PaymentEditor , Role . PaymentViewer )
98+ @Roles (
99+ Role . PaymentAdmin ,
100+ Role . PaymentBaAdmin ,
101+ Role . PaymentEditor ,
102+ Role . PaymentViewer ,
103+ )
78104 @ApiOperation ( {
79105 summary : 'Export search winnings result in csv file format' ,
80106 description : 'Roles: Payment Admin, Payment Editor, Payment Viewer' ,
@@ -91,11 +117,17 @@ export class AdminController {
91117 @HttpCode ( HttpStatus . OK )
92118 @Header ( 'Content-Type' , 'text/csv' )
93119 @Header ( 'Content-Disposition' , 'attachment; filename="winnings.csv"' )
94- async exportWinnings ( @Body ( ) body : WinningRequestDto ) {
95- const result = await this . winningsRepo . searchWinnings ( {
96- ...body ,
97- limit : 999 ,
98- } ) ;
120+ async exportWinnings ( @Body ( ) body : WinningRequestDto , @User ( ) user : any ) {
121+ const result = await this . winningsRepo . searchWinnings (
122+ await this . adminService . applyBaAdminUserFilters (
123+ user . id ,
124+ this . isBaAdmin ( user ) ,
125+ {
126+ ...body ,
127+ limit : 999 ,
128+ } ,
129+ ) ,
130+ ) ;
99131
100132 const handles = await this . tcMembersService . getHandlesByUserIds (
101133 result . data . winnings . map ( ( d ) => d . winnerId ) ,
@@ -149,7 +181,7 @@ export class AdminController {
149181 }
150182
151183 @Patch ( '/winnings' )
152- @Roles ( Role . PaymentAdmin , Role . PaymentEditor )
184+ @Roles ( Role . PaymentAdmin , Role . PaymentBaAdmin , Role . PaymentEditor )
153185 @ApiOperation ( {
154186 summary : 'Update winnings with given parameter' ,
155187 description :
@@ -175,7 +207,11 @@ export class AdminController {
175207 ) ;
176208 }
177209
178- const result = await this . adminService . updateWinnings ( body , user . id ) ;
210+ const result = await this . adminService . updateWinnings (
211+ body ,
212+ user . id ,
213+ this . isBaAdmin ( user ) ,
214+ ) ;
179215
180216 result . status = ResponseStatusType . SUCCESS ;
181217 if ( result . error ) {
@@ -186,7 +222,12 @@ export class AdminController {
186222 }
187223
188224 @Get ( '/winnings/:winningID/audit' )
189- @Roles ( Role . PaymentAdmin , Role . PaymentEditor , Role . PaymentViewer )
225+ @Roles (
226+ Role . PaymentAdmin ,
227+ Role . PaymentBaAdmin ,
228+ Role . PaymentEditor ,
229+ Role . PaymentViewer ,
230+ )
190231 @ApiOperation ( {
191232 summary : 'List winning audit logs with given winning id' ,
192233 description : 'Roles: Payment Admin, Payment Editor, Payment Viewer' ,
@@ -203,7 +244,12 @@ export class AdminController {
203244 } )
204245 async getWinningAudit (
205246 @Param ( 'winningID' ) winningId : string ,
247+ @User ( ) user : any ,
206248 ) : Promise < ResponseDto < WinningAuditDto [ ] > > {
249+ if ( this . isBaAdmin ( user ) ) {
250+ await this . adminService . verifyBaAdminAccessToWinning ( winningId , user . id ) ;
251+ }
252+
207253 const result = await this . adminService . getWinningAudit ( winningId ) ;
208254
209255 result . status = ResponseStatusType . SUCCESS ;
@@ -215,7 +261,12 @@ export class AdminController {
215261 }
216262
217263 @Get ( '/winnings/:winningID/audit-payout' )
218- @Roles ( Role . PaymentAdmin , Role . PaymentEditor , Role . PaymentViewer )
264+ @Roles (
265+ Role . PaymentAdmin ,
266+ Role . PaymentBaAdmin ,
267+ Role . PaymentEditor ,
268+ Role . PaymentViewer ,
269+ )
219270 @ApiOperation ( {
220271 summary : 'Fetch winnings payout audit logs with given winning id.' ,
221272 description :
@@ -233,7 +284,12 @@ export class AdminController {
233284 } )
234285 async getWinningAuditPayout (
235286 @Param ( 'winningID' ) winningId : string ,
287+ @User ( ) user : any ,
236288 ) : Promise < ResponseDto < AuditPayoutDto [ ] > > {
289+ if ( this . isBaAdmin ( user ) ) {
290+ await this . adminService . verifyBaAdminAccessToWinning ( winningId , user . id ) ;
291+ }
292+
237293 const result = await this . adminService . getWinningAuditPayout ( winningId ) ;
238294
239295 result . status = ResponseStatusType . SUCCESS ;
0 commit comments