Skip to content

Commit 331470b

Browse files
committed
1448: added finiance team heads ability to edit vendor names
1 parent f1fedb7 commit 331470b

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

src/backend/src/services/reimbursement-requests.services.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,12 @@ export default class ReimbursementRequestService {
702702
* @returns the updated vendor
703703
*/
704704
static async editVendors(name: string, vendorId: string, submitter: User) {
705-
if (!isHead(submitter.role)) throw new AccessDeniedAdminOnlyException('only Admins and Heads can edit vendors');
705+
if (!isAdmin(submitter.role)) {
706+
await validateUserIsPartOfFinanceTeam(submitter);
707+
708+
if (!isHead(submitter.role))
709+
throw new AccessDeniedAdminOnlyException('only Admins and Finance Heads can edit vendors');
710+
}
706711

707712
const vendorUniqueName = await prisma.vendor.findUnique({
708713
where: { name }

src/backend/tests/reimbursement-requests.test.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,16 @@ import {
2323
sharedGiveMeMyMoney,
2424
KFC
2525
} from './test-data/reimbursement-requests.test-data';
26-
import { alfred, batman, flash, sharedBatman, superman, wonderwoman, theVisitor } from './test-data/users.test-data';
26+
import {
27+
alfred,
28+
batman,
29+
flash,
30+
sharedBatman,
31+
superman,
32+
wonderwoman,
33+
theVisitor,
34+
alfredGuest
35+
} from './test-data/users.test-data';
2736
import reimbursementRequestQueryArgs from '../src/prisma-query-args/reimbursement-requests.query-args';
2837
import { Prisma, Reimbursement_Status_Type } from '@prisma/client';
2938
import {
@@ -628,10 +637,10 @@ describe('Reimbursement Requests', () => {
628637
});
629638

630639
describe('Edit Vendor Tests', () => {
631-
test('Throws error if user isnt an admin or head', async () => {
640+
test('Throws error if user isnt an admin or lead/head of the finance', async () => {
632641
await expect(
633642
ReimbursementRequestService.editVendors('I Love Benny', GiveMeMyMoney.vendorId, wonderwoman)
634-
).rejects.toThrow(new AccessDeniedAdminOnlyException('only Admins and Heads can edit vendors'));
643+
).rejects.toThrow(new AccessDeniedException('You are not a member of the finance team!'));
635644
});
636645

637646
test('Throws error if the vendor name already exists', async () => {

0 commit comments

Comments
 (0)