Skip to content

Commit

Permalink
Merge pull request #2832 from Northeastern-Electric-Racing/#1934-dele…
Browse files Browse the repository at this point in the history
…te-account-code-endpoint

#1934 Create delete account code endpoint
  • Loading branch information
walker-sean authored Sep 13, 2024
2 parents 285c626 + bba4b85 commit 3d4bd95
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/backend/src/controllers/reimbursement-requests.controllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,21 @@ export default class ReimbursementRequestsController {
}
}

static async deleteAccountCode(req: Request, res: Response, next: NextFunction) {
try {
const { accountCodeId } = req.params;

const deletedAccountCode = await ReimbursementRequestService.deleteAccountCode(
accountCodeId,
req.currentUser,
req.organization
);
return res.status(200).json(deletedAccountCode);
} catch (error: unknown) {
return next(error);
}
}

static async editVendor(req: Request, res: Response, next: NextFunction) {
try {
const { vendorId } = req.params;
Expand Down
2 changes: 2 additions & 0 deletions src/backend/src/routes/reimbursement-requests.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ reimbursementRequestsRouter.post(
ReimbursementRequestController.editAccountCode
);

reimbursementRequestsRouter.post('/account-codes/:accountCodeId/delete', ReimbursementRequestController.deleteAccountCode);

reimbursementRequestsRouter.post(
'/reimburse',
intMinZero(body('amount')),
Expand Down
25 changes: 25 additions & 0 deletions src/backend/src/services/reimbursement-requests.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,31 @@ export default class ReimbursementRequestService {
return accountCodeUpdated;
}

/**
* Deletes the Account Code with the given id
*
* @param accountCodeId the requested account code to be deleted
* @param submitter the user deleting the account code
* @param organizationId the organization the user is currently in
* @returns the 'deleted' account code
*/
static async deleteAccountCode(accountCodeId: string, submitter: User, organization: Organization) {
await isUserAdminOrOnFinance(submitter, organization.organizationId);

const accountCode = await ReimbursementRequestService.getSingleAccountCode(accountCodeId, organization);

if (accountCode.dateDeleted) {
throw new DeletedException('Account Code', accountCodeId);
}

const deletedAccountCode = await prisma.account_Code.update({
where: { accountCodeId: accountCode.accountCodeId },
data: { dateDeleted: new Date() }
});

return accountCodeTransformer(deletedAccountCode);
}

/**
* Service function to upload a picture to the receipts folder in the NER google drive
* @param reimbursementRequestId id for the reimbursement request we're tying the receipt to
Expand Down

0 comments on commit 3d4bd95

Please sign in to comment.