Skip to content
This repository has been archived by the owner on Feb 29, 2024. It is now read-only.

Commit

Permalink
Merge pull request #318 from kmcwebdev/development
Browse files Browse the repository at this point in the history
Refactor email approval service to handle expired approval links
  • Loading branch information
csulit authored Oct 9, 2023
2 parents 64beb00 + 57494b2 commit e90e161
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/finance/services/reimbursement.email-approval.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Injectable, Logger } from '@nestjs/common';
import { HttpException, HttpStatus, Injectable, Logger } from '@nestjs/common';
import { InjectKysely } from 'nestjs-kysely';
import { DB } from 'src/common/types';
import { ReimbursementApproveService } from './reimbursement.approve.service';
Expand All @@ -19,8 +19,16 @@ export class ReimbursementEmailApprovalService {
const approvalToken = await trx
.selectFrom('finance_reimbursement_approval_links as fral')
.select(['fral.approver_matrix_id', 'fral.token'])
.where('fral.link_expired', '=', false)
.where('fral.token', '=', data.token)
.executeTakeFirstOrThrow();
.executeTakeFirst();

if (!approvalToken) {
throw new HttpException(
'Approval link not found or has expired',
HttpStatus.NOT_FOUND,
);
}

const propelauthUser = await propelauth.validateAccessTokenAndGetUser(
`Bearer ${data.token}`,
Expand Down Expand Up @@ -63,6 +71,14 @@ export class ReimbursementEmailApprovalService {
},
);

await this.pgsql
.updateTable('finance_reimbursement_approval_links as fral')
.set({
link_expired: true,
})
.where('fral.token', '=', data.token)
.execute();

return 'OK';
});

Expand Down

0 comments on commit e90e161

Please sign in to comment.