Skip to content

Commit f4a755a

Browse files
authored
feat: decline open requests when freezing mentor (#235)
1 parent 4a68ae9 commit f4a755a

File tree

5 files changed

+49
-6
lines changed

5 files changed

+49
-6
lines changed

content/email_templates/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ nodemon --config nodemon-emails.json
1111
|Welcome|http://localhost:3003/welcome?data={%22name%22:%22Moshe%22}|
1212
|Mentorship accepted|http://localhost:3003/mentorship-accepted?data={%22menteeName%22:%22Moshe%22,%22mentorName%22:%20%22Brent%22,%22contactURL%22:%20%22https%22,%20%22openRequests%22:%208}|
1313
|Mentorship declined|http://localhost:3003/mentorship-declined?data={%22menteeName%22:%22Moshe%22,%22mentorName%22:%22Brent%22,%22reason%22:%22because%22}|
14+
|Mentorship declined (by system)|http://localhost:3003/mentorship-declined?data={%22menteeName%22:%22Moshe%22,%22mentorName%22:%22Brent%22,%22reason%22:%22because%22,%22bySystem%22:true}|
1415
|Mentorship cancelled|http://localhost:3003/mentorship-cancelled?data={%22menteeName%22:%22Moshe%22,%22mentorName%22:%20%22Brent%22,%22reason%22:%20%22I%27ve%20already%20found%20a%20mentor%22}|
1516
|Mentorship requested|http://localhost:3003/mentorship-requested?data={%22menteeName%22:%22Moshe%22,%22mentorName%22:%22Brent%22,%22message%22:%22because%22,%22background%22:%22here%20is%20my%20background%22,%22expectation%22:%22I'm%20expecting%20for%20the%20best!%22}|
1617
|Mentorship reminder|http://localhost:3003/mentorship-reminder?data={%22menteeName%22:%22Moshe%22,%22mentorName%22:%22Brent%22,%22message%22:%22because%22}|

content/email_templates/mentorship-declined.html

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,51 @@
1-
<div style="font-size: 18px;">
1+
<div style="font-size: 18px">
22
<table width="100%">
33
<tbody>
44
<tr>
55
<td align="center">
66
<img
7-
style="width: 39%; max-width: 234px;"
7+
style="width: 39%; max-width: 234px"
88
src="http://cdn.mcauto-images-production.sendgrid.net/83a8af126d5ca8ff/a3372217-691c-453e-bda3-27046e59b871/600x533.png"
99
alt="Illustration"
1010
/>
1111
</td>
1212
</tr>
1313
</tbody>
1414
</table>
15-
<h2 style="font-size: 26px; font-weight: normal;">
15+
<h2 style="font-size: 26px; font-weight: normal">
1616
Hello, <%= menteeName %>!
1717
</h2>
1818
<h1
19-
style="font-size: 32px; line-height: 42px; font-weight: normal; color: #69d5b1"
19+
style="
20+
font-size: 32px;
21+
line-height: 42px;
22+
font-weight: normal;
23+
color: #69d5b1;
24+
"
2025
>
2126
Mentorship Request Not Accepted
2227
</h1>
2328

29+
<% if (bySystem) { %>
2430
<p>
2531
Unfortunately, your request for mentorship with
26-
<span style="font-weight: bold; font-style: italic;"><%= mentorName %></span>
32+
<span style="font-weight: bold; font-style: italic"><%= mentorName %></span>
33+
has been declined by our system because
34+
<span style="font-weight: bold; font-style: italic"><%= mentorName %></span>
35+
seems to be unavailable at the moment.
36+
</p>
37+
<% } else { %>
38+
<p>
39+
Unfortunately, your request for mentorship with
40+
<span style="font-weight: bold; font-style: italic"><%= mentorName %></span>
2741
was not accepted.
2842
</p>
2943
<p>
3044
They provided the reason below, which we hope will help you find your next
3145
mentor:
3246
</p>
33-
3447
<pre><%= reason %></pre>
48+
<% } %>
3549

3650
<p>
3751
Although this one didn't work out, there are many other mentors at

src/modules/admin/admin.controller.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,32 @@ export class AdminController {
115115
},
116116
});
117117

118+
const mentorships = (
119+
await this.mentorshipsService.findMentorshipsByUser(id)
120+
).filter(
121+
(mentorship) =>
122+
mentorship.mentor.id === id &&
123+
[Status.NEW, Status.VIEWED].includes(mentorship.status),
124+
);
125+
126+
mentorships.forEach((mentorship) => {
127+
mentorship.status = Status.REJECTED;
128+
mentorship.reason = 'Automatic decline - Mentor is no longer available';
129+
(mentorship as any).save();
130+
131+
this.emailService.sendLocalTemplate({
132+
to: mentorship.mentee.email,
133+
name: 'mentorship-declined',
134+
subject: 'Mentorship Declined – Mentor no longer available',
135+
data: {
136+
mentorName: mentorship.mentor.name,
137+
menteeName: mentorship.mentee.name,
138+
reason: mentorship.reason,
139+
bySystem: true,
140+
},
141+
});
142+
});
143+
118144
return {
119145
success: true,
120146
};

src/modules/email/interfaces/email.interface.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type MentorshipDeclined = {
4444
menteeName: string;
4545
mentorName: string;
4646
reason: string;
47+
bySystem: boolean;
4748
};
4849
};
4950

src/modules/mentorships/mentorships.controller.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ export class MentorshipsController {
265265
menteeName: menteeFirstName,
266266
mentorName: currentUser.name,
267267
reason: reason || '',
268+
bySystem: false,
268269
},
269270
});
270271
}

0 commit comments

Comments
 (0)