@@ -24,15 +24,14 @@ import { TopcoderMembersService } from 'src/shared/topcoder/members.service';
2424import { Role } from 'src/core/auth/auth.constants' ;
2525import { Roles , User } from 'src/core/auth/decorators' ;
2626
27- import { UserInfo } from 'src/dto/user.type' ;
28-
2927import { AdminService } from './admin.service' ;
3028import { ResponseDto , ResponseStatusType } from 'src/dto/api-response.dto' ;
3129import { WinningAuditDto , AuditPayoutDto } from './dto/audit.dto' ;
3230
3331import { WinningRequestDto , SearchWinningResult } from 'src/dto/winning.dto' ;
3432import { WinningsRepository } from '../repository/winnings.repo' ;
3533import { WinningUpdateRequestDto } from './dto/winnings.dto' ;
34+ import { AccessControlService } from 'src/shared/access-control' ;
3635
3736@ApiTags ( 'AdminWinnings' )
3837@Controller ( '/admin' )
@@ -42,20 +41,14 @@ export class AdminController {
4241 private readonly adminService : AdminService ,
4342 private readonly winningsRepo : WinningsRepository ,
4443 private readonly tcMembersService : TopcoderMembersService ,
44+ private readonly accessControlService : AccessControlService ,
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-
5547 @Post ( '/winnings/search' )
5648 @Roles (
5749 Role . PaymentAdmin ,
5850 Role . PaymentBaAdmin ,
51+ Role . EngagementPaymentApprover ,
5952 Role . PaymentEditor ,
6053 Role . PaymentViewer ,
6154 )
@@ -77,13 +70,14 @@ export class AdminController {
7770 @Body ( ) body : WinningRequestDto ,
7871 @User ( ) user : any ,
7972 ) : Promise < ResponseDto < SearchWinningResult > > {
80- const result = await this . winningsRepo . searchWinnings (
81- await this . adminService . applyBaAdminUserFilters (
73+ const filters =
74+ await this . accessControlService . applyFilters < WinningRequestDto > (
8275 user . id ,
83- this . isBaAdmin ( user ) ,
76+ user . roles ,
8477 body ,
85- ) ,
86- ) ;
78+ ) ;
79+
80+ const result = await this . winningsRepo . searchWinnings ( filters ) ;
8781
8882 if ( result . error ) {
8983 result . status = ResponseStatusType . ERROR ;
@@ -98,6 +92,7 @@ export class AdminController {
9892 @Roles (
9993 Role . PaymentAdmin ,
10094 Role . PaymentBaAdmin ,
95+ Role . EngagementPaymentApprover ,
10196 Role . PaymentEditor ,
10297 Role . PaymentViewer ,
10398 )
@@ -118,16 +113,16 @@ export class AdminController {
118113 @Header ( 'Content-Type' , 'text/csv' )
119114 @Header ( 'Content-Disposition' , 'attachment; filename="winnings.csv"' )
120115 async exportWinnings ( @Body ( ) body : WinningRequestDto , @User ( ) user : any ) {
121- const result = await this . winningsRepo . searchWinnings (
122- await this . adminService . applyBaAdminUserFilters (
116+ const filters =
117+ await this . accessControlService . applyFilters < WinningRequestDto > (
123118 user . id ,
124- this . isBaAdmin ( user ) ,
119+ user . roles ,
125120 {
126121 ...body ,
127122 limit : 999 ,
128123 } ,
129- ) ,
130- ) ;
124+ ) ;
125+ const result = await this . winningsRepo . searchWinnings ( filters ) ;
131126
132127 const handles = await this . tcMembersService . getHandlesByUserIds (
133128 result . data . winnings . map ( ( d ) => d . winnerId ) ,
@@ -181,7 +176,12 @@ export class AdminController {
181176 }
182177
183178 @Patch ( '/winnings' )
184- @Roles ( Role . PaymentAdmin , Role . PaymentBaAdmin , Role . PaymentEditor )
179+ @Roles (
180+ Role . PaymentAdmin ,
181+ Role . PaymentBaAdmin ,
182+ Role . EngagementPaymentApprover ,
183+ Role . PaymentEditor ,
184+ )
185185 @ApiOperation ( {
186186 summary : 'Update winnings with given parameter' ,
187187 description :
@@ -194,7 +194,7 @@ export class AdminController {
194194 } )
195195 async updateWinning (
196196 @Body ( ) body : WinningUpdateRequestDto ,
197- @User ( ) user : UserInfo ,
197+ @User ( ) user : any ,
198198 ) : Promise < ResponseDto < string > > {
199199 if (
200200 ! body . paymentAmount &&
@@ -210,7 +210,7 @@ export class AdminController {
210210 const result = await this . adminService . updateWinnings (
211211 body ,
212212 user . id ,
213- this . isBaAdmin ( user ) ,
213+ user . roles ,
214214 ) ;
215215
216216 result . status = ResponseStatusType . SUCCESS ;
@@ -225,6 +225,7 @@ export class AdminController {
225225 @Roles (
226226 Role . PaymentAdmin ,
227227 Role . PaymentBaAdmin ,
228+ Role . EngagementPaymentApprover ,
228229 Role . PaymentEditor ,
229230 Role . PaymentViewer ,
230231 )
@@ -246,9 +247,11 @@ export class AdminController {
246247 @Param ( 'winningID' ) winningId : string ,
247248 @User ( ) user : any ,
248249 ) : Promise < ResponseDto < WinningAuditDto [ ] > > {
249- if ( this . isBaAdmin ( user ) ) {
250- await this . adminService . verifyBaAdminAccessToWinning ( winningId , user . id ) ;
251- }
250+ await this . adminService . verifyUserAccessToWinning (
251+ winningId ,
252+ user . id ,
253+ user . roles ,
254+ ) ;
252255
253256 const result = await this . adminService . getWinningAudit ( winningId ) ;
254257
@@ -264,6 +267,7 @@ export class AdminController {
264267 @Roles (
265268 Role . PaymentAdmin ,
266269 Role . PaymentBaAdmin ,
270+ Role . EngagementPaymentApprover ,
267271 Role . PaymentEditor ,
268272 Role . PaymentViewer ,
269273 )
@@ -286,9 +290,11 @@ export class AdminController {
286290 @Param ( 'winningID' ) winningId : string ,
287291 @User ( ) user : any ,
288292 ) : Promise < ResponseDto < AuditPayoutDto [ ] > > {
289- if ( this . isBaAdmin ( user ) ) {
290- await this . adminService . verifyBaAdminAccessToWinning ( winningId , user . id ) ;
291- }
293+ await this . adminService . verifyUserAccessToWinning (
294+ winningId ,
295+ user . id ,
296+ user . roles ,
297+ ) ;
292298
293299 const result = await this . adminService . getWinningAuditPayout ( winningId ) ;
294300
0 commit comments