File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -327,6 +327,34 @@ export const setupAdminPointsRoutes = function(app: Express, prisma: PrismaClien
327327 return res . status ( 404 ) . json ( { error : 'Score not found' } ) ;
328328 }
329329
330+ if ( score . fixed_type_id === 'point_donated' ) {
331+ // For points donated, there is no Intra object to retrigger the webhook with, so we have to recalculate the score here manually
332+ const newFixedPointType = await prisma . codamCoalitionFixedType . findFirst ( {
333+ where : {
334+ type : 'point_donated' ,
335+ }
336+ } ) ;
337+ if ( ! newFixedPointType ) {
338+ return res . status ( 501 ) . json ( { error : 'No point_donated fixed type found, cannot recalculate' } ) ;
339+ }
340+
341+ // Parse amount of points donated from the reason... no better way ATM
342+ const pointsDonated = parseInt ( score . reason . split ( ' ' ) [ 1 ] ) ;
343+ if ( isNaN ( pointsDonated ) ) {
344+ return res . status ( 400 ) . json ( { error : 'Invalid amount of points donated in the reason field' } ) ;
345+ }
346+ const newAmount = pointsDonated * newFixedPointType . point_amount ;
347+ await prisma . codamCoalitionScore . update ( {
348+ where : {
349+ id : score . id ,
350+ } ,
351+ data : {
352+ amount : newAmount ,
353+ } ,
354+ } ) ;
355+ return res . status ( 200 ) . json ( { status : 'ok' , new_amount : newAmount } ) ;
356+ }
357+
330358 if ( score . fixed_type_id === null || score . type_intra_id === null ) {
331359 return res . status ( 400 ) . json ( { error : 'Score is not based on a fixed type, cannot recalculate' } ) ;
332360 }
You can’t perform that action at this time.
0 commit comments