Skip to content

Commit 2a5f742

Browse files
committed
Remove Need for Unnecessary Env Variables and Fix More CrId Slack Bugs
1 parent b4ebcfe commit 2a5f742

5 files changed

Lines changed: 23 additions & 24 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ export default class ChangeRequestsService {
152152
await sendCRSubmitterReviewedNotification(foundCR);
153153

154154
// send a reply to a CR's notifications of its updated status
155-
await sendSlackCRStatusToThread(updated.notificationSlackThreads, foundCR.crId, accepted);
155+
await sendSlackCRStatusToThread(updated.notificationSlackThreads, foundCR.crId, foundCR.identifier accepted);
156156

157157
return updated.crId;
158158
}

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,15 @@ export default class ReimbursementRequestService {
466466
text: `The following reimbursement requests need to be approved by you: ${saboNumbers.join(', ')}`
467467
};
468468

469-
await sendMailToAdvisor(mailOptions.subject, mailOptions.text);
469+
const organization = await prisma.organization.findUnique({
470+
where: { organizationId },
471+
include: { advisor: true }
472+
});
473+
474+
if (!organization) throw new NotFoundException('Organization', organizationId);
475+
if (!organization.advisor) throw new HttpException(400, 'Organization does not have an advisor');
476+
477+
await sendMailToAdvisor(mailOptions.subject, mailOptions.text, organization.advisor);
470478

471479
reimbursementRequests.forEach((reimbursementRequest) => {
472480
prisma.reimbursement_Status.create({

src/backend/src/utils/change-requests.utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ export const sendCRSubmitterReviewedNotification = async (
561561
const creatorUserSettings = await prisma.user_Settings.findUnique({ where: { userId: foundCR.submitterId } });
562562
if (creatorUserSettings && creatorUserSettings.slackId) {
563563
try {
564-
await sendSlackCRReviewedNotification(creatorUserSettings.slackId, foundCR.crId);
564+
await sendSlackCRReviewedNotification(creatorUserSettings.slackId, foundCR.crId, foundCR.identifier);
565565
} catch (err: unknown) {
566566
if (err instanceof Error) {
567567
throw new HttpException(500, `Failed to send slack notification: ${err.message}`);

src/backend/src/utils/google-integration.utils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import SMTPTransport from 'nodemailer/lib/smtp-transport';
44
import { HttpException } from './errors.utils';
55
import stream, { Readable } from 'stream';
66
import concat from 'concat-stream';
7+
import { User } from '@prisma/client';
78

89
const { OAuth2 } = google.auth;
910
const {
@@ -12,8 +13,7 @@ const {
1213
GOOGLE_CLIENT_SECRET,
1314
EMAIL_REFRESH_TOKEN,
1415
USER_EMAIL,
15-
DRIVE_REFRESH_TOKEN,
16-
ADVISOR_EMAIL
16+
DRIVE_REFRESH_TOKEN
1717
} = process.env;
1818

1919
const oauth2Client = new OAuth2(GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET, 'https://developers.google.com/oauthplayground');
@@ -49,12 +49,12 @@ const createTransporter = async () => {
4949
}
5050
};
5151

52-
export const sendMailToAdvisor = async (subject: string, text: string) => {
52+
export const sendMailToAdvisor = async (subject: string, text: string, advisor: User) => {
5353
try {
5454
//this sends an email from our email to our advisor: professor Goldstone
5555
const mailOptions = {
5656
from: USER_EMAIL,
57-
to: ADVISOR_EMAIL,
57+
to: advisor.email,
5858
subject,
5959
text
6060
};

src/backend/src/utils/slack.utils.ts

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export const sendSlackRequestedReviewNotification = async (
6464
const btnText = `View CR`;
6565
const changeRequestLink = `https://finishlinebyner.com/change-requests/${changeRequest.crId}`;
6666
const slackPingMessage = usersToSlackPings(reviewers);
67-
const fullMsg = `${slackPingMessage} Your review has been requested on CR #${changeRequest.crId}!`;
67+
const fullMsg = `${slackPingMessage} Your review has been requested on CR #${changeRequest.identifier}!`;
6868

6969
const threads = await prisma.message_Info.findMany({ where: { changeRequestId: changeRequest.crId } });
7070

@@ -173,15 +173,14 @@ export const sendSlackDesignReviewConfirmNotification = async (
173173
* @param team the teams of the cr to notify
174174
* @param message the message to send to the teams
175175
* @param crId the cr id
176-
* @param budgetImpact the amount of budget requested for the cr
176+
* @param identifier the cr identifier
177177
* @returns the channelId and timestamp of the messages sent in slack
178178
*/
179179
export const sendSlackChangeRequestNotification = async (
180180
team: Team,
181181
message: string,
182182
crId: string,
183-
identifier: number,
184-
budgetImpact?: number
183+
identifier: number
185184
): Promise<{ channelId: string; ts: string }[]> => {
186185
if (process.env.NODE_ENV !== 'production') return []; // don't send msgs unless in prod
187186
const msgs: { channelId: string; ts: string }[] = [];
@@ -191,16 +190,6 @@ export const sendSlackChangeRequestNotification = async (
191190
const notification = await sendMessage(team.slackId, fullMsg, fullLink, btnText);
192191
if (notification) msgs.push(notification);
193192

194-
if (budgetImpact && budgetImpact > 100) {
195-
const importantNotification = await sendMessage(
196-
process.env.SLACK_EBOARD_CHANNEL!,
197-
`${fullMsg} with $${budgetImpact} requested`,
198-
fullLink,
199-
btnText
200-
);
201-
if (importantNotification) msgs.push(importantNotification);
202-
}
203-
204193
return msgs;
205194
};
206195

@@ -374,12 +363,12 @@ export const sendDRScheduledSlackNotif = async (
374363
}
375364
};
376365

377-
export const sendSlackCRReviewedNotification = async (slackId: string, crId: string) => {
366+
export const sendSlackCRReviewedNotification = async (slackId: string, crId: string, identifier: number) => {
378367
if (process.env.NODE_ENV !== 'production') return; // don't send msgs unless in prod
379368
const msgs = [];
380369
const fullMsg = `:tada: Your Change Request was just reviewed! Click the link to view! :tada:`;
381370
const fullLink = `https://finishlinebyner.com/cr/${crId}`;
382-
const btnText = `View CR#${crId}`;
371+
const btnText = `View CR#${identifier}`;
383372
msgs.push(sendMessage(slackId, fullMsg, fullLink, btnText));
384373

385374
return Promise.all(msgs);
@@ -390,6 +379,7 @@ export const sendSlackCRReviewedNotification = async (slackId: string, crId: str
390379
*
391380
* @param threads the threads of cr slack notifications to reply/react to
392381
* @param crId the cr id
382+
* @param identifier the cr identifier
393383
* @param approved is the cr approved
394384
*/
395385
export const sendSlackCRStatusToThread = async (
@@ -400,12 +390,13 @@ export const sendSlackCRStatusToThread = async (
400390
changeRequestId: string | null;
401391
}[],
402392
crId: string,
393+
identifier: number,
403394
approved: boolean
404395
) => {
405396
if (process.env.NODE_ENV !== 'production') return; // don't send msgs unless in prod
406397
const fullMsg = `This Change Request was ${approved ? 'approved! :tada:' : 'denied.'} Click the link to view.`;
407398
const fullLink = `https://finishlinebyner.com/cr/${crId}`;
408-
const btnText = `View CR#${crId}`;
399+
const btnText = `View CR#${identifier}`;
409400
try {
410401
if (threads && threads.length !== 0) {
411402
const msgs = threads.map((thread) =>

0 commit comments

Comments
 (0)