Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/backend/src/controllers/finance.controllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ export default class FinanceController {
contactPhone,
contactPosition,
stockDescription,
discountDescription
discountDescription,
req.file
);
res.status(200).json(sponsor);
} catch (error: unknown) {
Expand Down Expand Up @@ -383,7 +384,8 @@ export default class FinanceController {
contactPhone,
contactPosition,
stockDescription,
discountDescription
discountDescription,
req.file
);

res.status(200).json(updatedSponsor);
Expand Down
5 changes: 5 additions & 0 deletions src/backend/src/routes/finance.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ import {
} from '../utils/validation.utils.js';
import { body } from 'express-validator';
import FinanceController from '../controllers/finance.controllers.js';
import multer, { memoryStorage } from 'multer';
import { MAX_FILE_SIZE } from 'shared';

const financeRouter = express.Router();
const upload = multer({ limits: { fileSize: MAX_FILE_SIZE }, storage: memoryStorage() });

financeRouter.post(
'/sponsor/create',
upload.single('logoImage'),
nonEmptyString(body('name')),
body('activeStatus').isBoolean(),
body('valueTypes').isArray(),
Expand Down Expand Up @@ -142,6 +146,7 @@ financeRouter.get('/sponsorTiers', FinanceController.getAllSponsorTiers);

financeRouter.post(
'/sponsor/:sponsorId/edit',
upload.single('logoImage'),
nonEmptyString(body('name')),
body('activeStatus').isBoolean(),
body('valueTypes').isArray(),
Expand Down
27 changes: 23 additions & 4 deletions src/backend/src/services/finance.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
getReimbursementRequestWhereInput
} from '../utils/finance.utils.js';
import { notifySponsorTaskAssignee } from '../utils/slack.utils.js';
import { uploadFile } from '../utils/google-integration.utils.js';
import { isUserFinanceTeamOrHead } from '../utils/reimbursement-requests.utils.js';

export default class FinanceServices {
Expand All @@ -56,7 +57,7 @@ export default class FinanceServices {
* @param contactPosition The position of the sponsor contact.
* @param sponsorTasks An array of sponsor tasks associated with the sponsor.
* @param organization The organization for which the sponsor is being created.
*
* @param logoImage An optional logo image file for the sponsor.
* @returns The created sponsor object, including associated tasks.
*
* @throws AccessDeniedAdminOnlyException If the submitter does not have permission to create a sponsor.
Expand All @@ -80,7 +81,8 @@ export default class FinanceServices {
contactPhone?: string,
contactPosition?: string,
stockDescription?: string,
discountDescription?: string
discountDescription?: string,
logoImage?: Express.Multer.File
) {
if (!(await userHasPermission(submitter.userId, organization.organizationId, isHead)))
throw new AccessDeniedException('Only heads can create a sponsor');
Expand All @@ -104,6 +106,12 @@ export default class FinanceServices {
data: { name: contactName, email: contactEmail, phone: contactPhone, position: contactPosition }
});

let logoImageId: string | undefined;
if (logoImage) {
const logoImageData = await uploadFile(logoImage);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use object destructuring

logoImageId = logoImageData.id;
}

const sponsor = await prisma.sponsor.create({
data: {
name,
Expand All @@ -118,6 +126,7 @@ export default class FinanceServices {
taxExempt,
discountCode,
sponsorNotes,
logoImageId,
contactId: contact.sponsorContactId,
sponsorTasks: {
create: sponsorTasks.map((task) => ({
Expand Down Expand Up @@ -1200,6 +1209,8 @@ export default class FinanceServices {
* @param contactPosition The position of the sponsor contact.
* @param sponsorTasks An array of sponsor tasks associated with the sponsor.
* @param organization The organization for which the sponsor is being edited.
* @param logoImage An optional logo image file for the sponsor.
*
* @returns the edited sponsor.
*/

Expand All @@ -1223,7 +1234,8 @@ export default class FinanceServices {
contactPhone?: string,
contactPosition?: string,
stockDescription?: string,
discountDescription?: string
discountDescription?: string,
logoImage?: Express.Multer.File
): Promise<Sponsor> {
if (!(await userHasPermission(submitter.userId, organization.organizationId, isHead)))
throw new AccessDeniedException('Only heads can edit sponsors.');
Expand Down Expand Up @@ -1321,6 +1333,12 @@ export default class FinanceServices {
data: { name: contactName, email: contactEmail, phone: contactPhone, position: contactPosition }
});

let logoImageId: string | undefined;
if (logoImage) {
const logoImageData = await uploadFile(logoImage);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

logoImageId = logoImageData.id;
}

const updatedSponsor = await prisma.sponsor.update({
where: { sponsorId: oldSponsor.sponsorId },
data: {
Expand All @@ -1335,7 +1353,8 @@ export default class FinanceServices {
tier: sponsorTierId ? { connect: { sponsorTierId } } : { disconnect: true },
taxExempt,
discountCode,
sponsorNotes
sponsorNotes,
...(logoImageId && { logoImageId })
},
...getSponsorQueryArgs(organization.organizationId)
});
Expand Down
1 change: 1 addition & 0 deletions src/backend/src/transformers/finance.transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const sponsorTransformer = (sponsor: Prisma.SponsorGetPayload<SponsorQuer
: undefined,
sponsorNotes: sponsor.sponsorNotes ?? undefined,
discountCode: sponsor.discountCode ?? undefined,
logoImageId: sponsor.logoImageId ?? undefined,
sponsorTasks: sponsor.sponsorTasks.map(sponsorTaskTranformer)
};
};
Expand Down
1 change: 1 addition & 0 deletions src/shared/src/types/finance-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export interface Sponsor {
sponsorNotes?: string;
sponsorTasks: SponsorTask[];
tier?: SponsorTier;
logoImageId?: string;
}

export interface SponsorTask {
Expand Down
Loading