Skip to content

Commit 014e807

Browse files
iChris-tianuwituzebchrisAime-Patrick
authored
Ft notifications tickets cycle (#135)
* add new models and seeders * application tickets * fix model * add filter tickets resolver * ticket create-notifications * allow multiple replies from admin and applicant * fix ticket resolver * fix update ticket resolver * ticket notifications-email * ticket notifications * Application cycle process on applicant * application stage notifications * ft-notifications-email-applicant-tickets-application-stages * update * ft-notifications-tickets-cycle * update * fix schema * fix nullable author field * merge develop * missing imports * resolved conflicts --------- Co-authored-by: uwituzeb <[email protected]> Co-authored-by: chris <[email protected]> Co-authored-by: Aime-Patrick <[email protected]>
1 parent 811e98f commit 014e807

File tree

6 files changed

+277
-41
lines changed

6 files changed

+277
-41
lines changed

Diff for: src/index.ts

100644100755
+2-2
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ const server = new ApolloServer({
190190
try {
191191
authToken =
192192
req.headers.authorization &&
193-
req.headers.authorization.startsWith("Bearer ")
193+
req.headers.authorization.startsWith("Bearer ")
194194
? req.headers.authorization.split(" ")[1]
195195
: req.headers.authorization;
196196
if (authToken) {
@@ -209,4 +209,4 @@ const server = new ApolloServer({
209209
connect().then(() => {
210210
console.log("Database connected!");
211211
server.listen(PORT).then(({ url }) => console.info(`App on ${url}`));
212-
});
212+
});

Diff for: src/models/dismissedStageSchema.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ const rejectedSchema = new Schema<IDismissed>({
2929
timestamps: true
3030
});
3131

32-
const Rejected = mongoose.model<IDismissed>("Rejected", rejectedSchema);
32+
const Rejected = mongoose.model<IDismissed>("Dismissed", rejectedSchema);
3333
export default Rejected;

Diff for: src/resolvers/applicationStageResolver.ts

+165-31
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ import Rejected from "../models/dismissedStageSchema";
77
import Admitted from "../models/admittedStageSchema";
88
import InterviewAssessment from "../models/InterviewAssessmentStageSchema";
99
import TechnicalAssessment from "../models/technicalAssessmentStage";
10-
import mongoose from "mongoose";
11-
import { traineEAttributes } from "../models/traineeAttribute";
10+
import { sendEmailTemplate } from "../helpers/bulkyMails";
11+
import { ApplicantNotificationsModel } from "../models/applicantNotifications";
1212
import { LoggedUserModel } from "../models/AuthUser";
13+
import { pusher } from "../helpers/pusher";
14+
import { traineEAttributes } from "../models/traineeAttribute";
15+
import mongoose from "mongoose";
1316

1417
const validStages = [
1518
"Shortlisted",
@@ -31,7 +34,7 @@ async function getApplicantsByModel(model: any) {
3134
async function updateApplicantAfterDismissed(model: any, applicantId: string) {
3235
await model.updateOne({ applicantId }, { $set: { status: "Rejected" } });
3336
}
34-
async function updateApplicantAfterAdmitted(model: any, applicantId: string) {
37+
async function updateApplicantAfterAdmitted(model: any,applicantId:string) {
3538
await model.updateOne({ applicantId }, { $set: { status: "Admitted" } });
3639
}
3740
export const applicationStageResolvers: any = {
@@ -179,6 +182,9 @@ export const applicationStageResolvers: any = {
179182
context: any
180183
) => {
181184
try {
185+
const applicant = await TraineeApplicant.findById(applicantId);
186+
const user = await LoggedUserModel.findOne({ email: applicant!.email });
187+
182188
if (!context.currentUser) {
183189
throw new CustomGraphQLError(
184190
"You must be logged in to perform this action"
@@ -208,6 +214,8 @@ export const applicationStageResolvers: any = {
208214
);
209215
}
210216

217+
let scoreDetails = "";
218+
211219
if (nextStage === "Interview Assessment") {
212220
const technicalScore = await TechnicalAssessment.findOne({
213221
applicantId,
@@ -221,6 +229,7 @@ export const applicationStageResolvers: any = {
221229
"Technical assessment score is required before moving to the Interview Assessment, Please add score😎."
222230
);
223231
}
232+
scoreDetails = `Your Technical Assessment Score: ${technicalScore.score}`;
224233
}
225234

226235
// If moving to Admitted, ensure Interview Assessment has a score
@@ -237,6 +246,7 @@ export const applicationStageResolvers: any = {
237246
"Interview assessment score is required before moving to Admitted, Please add score😎."
238247
);
239248
}
249+
scoreDetails = `Your Interview Assessment Score: ${interviewScore.interviewScore}`;
240250
}
241251

242252
if (!stageTracking) {
@@ -291,8 +301,36 @@ export const applicationStageResolvers: any = {
291301
await TraineeApplicant.updateOne(
292302
{ _id: applicantId },
293303
{ $set: { applicationPhase: nextStage, status: "No action" } }
304+
);
305+
message = `You have advanced to the ${nextStage} stage.`;
306+
const notification = await ApplicantNotificationsModel.create({
307+
userId: user!._id,
308+
message,
309+
eventType: "general",
310+
});
311+
312+
await sendEmailTemplate(
313+
user!.email,
314+
"Application Update",
315+
`Hello ${user!.email.split("@")[0]}, `,
316+
`Your application has been moved to ${nextStage} stage.
317+
<br />
318+
You will hear from us very soon.
319+
<br />
320+
Thank you for your patience.
321+
`
294322
);
295-
message = `Applicant advanced to ${nextStage} stage.`;
323+
324+
await pusher
325+
.trigger(`notifications-${user!._id}`, "new-notification", {
326+
message: notification.message,
327+
id: notification._id,
328+
createdAt: notification.createdAt,
329+
read: notification.read,
330+
})
331+
.catch((error) => {
332+
console.error("Error with Pusher trigger:", error);
333+
});
296334
break;
297335

298336
case "Interview Assessment":
@@ -311,7 +349,38 @@ export const applicationStageResolvers: any = {
311349
comments,
312350
status: "No action",
313351
});
314-
message = `Applicant advanced to ${nextStage} stage.`;
352+
message = `You have advanced to the ${nextStage} stage.`;
353+
const notification1 = await ApplicantNotificationsModel.create({
354+
userId: user!._id,
355+
message,
356+
eventType: "general",
357+
});
358+
359+
await sendEmailTemplate(
360+
user!.email,
361+
"Application Update",
362+
`Hello ${user!.email.split("@")[0]}, `,
363+
`Your application has been moved to ${nextStage} stage.
364+
<br />
365+
${scoreDetails}
366+
<br />
367+
<br />
368+
You will hear from us very soon.
369+
<br />
370+
Thank you for your patience.
371+
`
372+
);
373+
374+
await pusher
375+
.trigger(`notifications-${user!._id}`, "new-notification", {
376+
message: notification1.message,
377+
id: notification1._id,
378+
createdAt: notification1.createdAt,
379+
read: notification1.read,
380+
})
381+
.catch((error) => {
382+
console.error("Error with Pusher trigger:", error);
383+
});
315384
break;
316385

317386
case "Admitted":
@@ -333,8 +402,7 @@ export const applicationStageResolvers: any = {
333402
comments,
334403
status: "Passed",
335404
});
336-
message = `Applicant passed the application stage✅.`;
337-
405+
message = `You have passed the application stage✅.`;
338406
await TraineeApplicant.updateOne(
339407
{ _id: applicantId },
340408
{
@@ -345,29 +413,38 @@ export const applicationStageResolvers: any = {
345413
},
346414
}
347415
);
416+
417+
const notification2 = await ApplicantNotificationsModel.create({
418+
userId: user!._id,
419+
message,
420+
eventType: "general",
421+
});
348422

349-
const updatedApplicant = await TraineeApplicant.findOne({
350-
_id: applicantId,
351-
})
352-
.populate("email")
353-
.lean();
354-
355-
const email = updatedApplicant?.email;
356-
357-
if (email) {
358-
await LoggedUserModel.updateOne(
359-
{ email },
360-
{
361-
$set: {
362-
applicationPhase: nextStage,
363-
status: "Admitted",
364-
role: traineeRole._id,
365-
},
366-
}
367-
);
368-
} else {
369-
throw new Error("Email not found for the provided applicant ID");
370-
}
423+
await sendEmailTemplate(
424+
user!.email,
425+
"Application Update",
426+
`Hello ${user!.email.split("@")[0]}, `,
427+
`Your application has successfully passed the application stage.
428+
<br />
429+
${scoreDetails}
430+
<br />
431+
<br />
432+
You will hear from us very soon.
433+
<br />
434+
Thank you for your patience.
435+
`
436+
);
437+
438+
await pusher
439+
.trigger(`notifications-${user!._id}`, "new-notification", {
440+
message: notification2.message,
441+
id: notification2._id,
442+
createdAt: notification2.createdAt,
443+
read: notification2.read,
444+
})
445+
.catch((error) => {
446+
console.error("Error with Pusher trigger:", error);
447+
});
371448
break;
372449

373450
case "Rejected":
@@ -394,7 +471,36 @@ export const applicationStageResolvers: any = {
394471
{ _id: applicantId },
395472
{ $set: { applicationPhase: "Rejected", status: "Rejected" } }
396473
);
397-
message = `Applicant Rejected from the ${stageDismissedFrom?.applicationPhase} stage.`;
474+
message = `You have been rejected from the ${stageDismissedFrom?.applicationPhase} stage.`;
475+
476+
const notification3 = await ApplicantNotificationsModel.create({
477+
userId: user!._id,
478+
message,
479+
eventType: "general",
480+
});
481+
482+
await sendEmailTemplate(
483+
user!.email,
484+
"Application Update",
485+
`Hello ${user!.email.split("@")[0]}, `,
486+
`We are sorry to inform you that
487+
your application has been rejected from the ${stageDismissedFrom?.applicationPhase} stage.
488+
<br />
489+
<br />
490+
You can always apply again.
491+
`
492+
);
493+
494+
await pusher
495+
.trigger(`notifications-${user!._id}`, "new-notification", {
496+
message: notification3.message,
497+
id: notification3._id,
498+
createdAt: notification3.createdAt,
499+
read: notification3.read,
500+
})
501+
.catch((error) => {
502+
console.error("Error with Pusher trigger:", error);
503+
});
398504
break;
399505

400506
case "Shortlisted":
@@ -414,7 +520,35 @@ export const applicationStageResolvers: any = {
414520
{ _id: applicantId },
415521
{ $set: { applicationPhase: nextStage, status: "No action" } }
416522
);
417-
message = `Applicant advanced to ${nextStage} stage.`;
523+
message = `You have advanced to the ${nextStage} stage.`;
524+
const notification4 = await ApplicantNotificationsModel.create({
525+
userId: user!._id,
526+
message,
527+
eventType: "general",
528+
});
529+
530+
await sendEmailTemplate(
531+
user!.email,
532+
"Application Update",
533+
`Hello ${user!.email.split("@")[0]}, `,
534+
`Your application has been moved to ${nextStage} stage.
535+
<br />
536+
You will hear from us very soon.
537+
<br />
538+
Thank you for your patience.
539+
`
540+
);
541+
542+
await pusher
543+
.trigger(`notifications-${user!._id}`, "new-notification", {
544+
message: notification4.message,
545+
id: notification4._id,
546+
createdAt: notification4.createdAt,
547+
read: notification4.read,
548+
})
549+
.catch((error) => {
550+
console.error("Error with Pusher trigger:", error);
551+
});
418552
break;
419553
}
420554

0 commit comments

Comments
 (0)