Skip to content

Commit 4677a0d

Browse files
committed
#1592 Fix Cr Bug
1 parent 6bfeece commit 4677a0d

2 files changed

Lines changed: 40 additions & 17 deletions

File tree

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -579,12 +579,20 @@ export default class ChangeRequestsService {
579579
const project = createdCR.wbsElement.workPackage?.project || createdCR.wbsElement.project;
580580
const teams = project?.teams;
581581
if (teams && teams.length > 0) {
582-
teams.forEach(async (team) => {
582+
const completion: Promise<void>[] = teams.map(async (team) => {
583583
const slackMsg =
584584
`${type} CR submitted by ${submitter.firstName} ${submitter.lastName} ` +
585585
`for the ${project.wbsElement.name} project`;
586-
await sendSlackChangeRequestNotification(team, slackMsg, createdCR.crId);
586+
try {
587+
await sendSlackChangeRequestNotification(team, slackMsg, createdCR.crId);
588+
} catch (error) {
589+
if (error instanceof Error) {
590+
throw new HttpException(511, `Failed to send slack notification for CR: ${createdCR.crId}`);
591+
}
592+
}
587593
});
594+
595+
await Promise.all(completion);
588596
}
589597

590598
return createdCR.crId;

src/frontend/src/pages/CreateChangeRequestPage/CreateChangeRequest.tsx

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,31 +44,46 @@ const CreateChangeRequest: React.FC<CreateChangeRequestProps> = () => {
4444

4545
const { userId } = auth.user;
4646

47+
const addProposedSolutions = async (crId: number) => {
48+
proposedSolutions.forEach(async (ps) => {
49+
const { description, timelineImpact, scopeImpact, budgetImpact } = ps;
50+
51+
await cpsMutateAsync({
52+
crId,
53+
submitterId: userId,
54+
description,
55+
timelineImpact,
56+
scopeImpact,
57+
budgetImpact
58+
});
59+
});
60+
};
61+
4762
const handleConfirm = async (data: FormInput) => {
63+
let crId: number;
4864
try {
4965
const cr = await mutateAsync({
5066
...data,
5167
wbsNum: validateWBS(wbsNum)
5268
});
53-
const crId = parseInt(cr.message);
54-
proposedSolutions.forEach(async (ps) => {
55-
const { description, timelineImpact, scopeImpact, budgetImpact } = ps;
56-
57-
await cpsMutateAsync({
58-
crId,
59-
submitterId: userId,
60-
description,
61-
timelineImpact,
62-
scopeImpact,
63-
budgetImpact
64-
});
65-
});
66-
67-
history.push(routes.CHANGE_REQUESTS);
69+
crId = parseInt(cr.message);
6870
} catch (e) {
6971
if (e instanceof Error) {
72+
if (e.message.startsWith('Failed to send slack notification for CR: ')) {
73+
const splitMessage = e.message.split(': ');
74+
crId = parseInt(splitMessage[1]);
75+
try {
76+
await addProposedSolutions(crId);
77+
} catch (e) {
78+
if (e instanceof Error) {
79+
toast.error(e.message);
80+
}
81+
}
82+
}
7083
toast.error(e.message);
7184
}
85+
} finally {
86+
history.push(routes.CHANGE_REQUESTS);
7287
}
7388
};
7489

0 commit comments

Comments
 (0)