Skip to content

Commit

Permalink
Ft notifications tickets cycle (#135)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
4 people authored Nov 21, 2024
1 parent 811e98f commit 014e807
Show file tree
Hide file tree
Showing 6 changed files with 277 additions and 41 deletions.
4 changes: 2 additions & 2 deletions src/index.ts
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ const server = new ApolloServer({
try {
authToken =
req.headers.authorization &&
req.headers.authorization.startsWith("Bearer ")
req.headers.authorization.startsWith("Bearer ")
? req.headers.authorization.split(" ")[1]
: req.headers.authorization;
if (authToken) {
Expand All @@ -209,4 +209,4 @@ const server = new ApolloServer({
connect().then(() => {
console.log("Database connected!");
server.listen(PORT).then(({ url }) => console.info(`App on ${url}`));
});
});
2 changes: 1 addition & 1 deletion src/models/dismissedStageSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ const rejectedSchema = new Schema<IDismissed>({
timestamps: true
});

const Rejected = mongoose.model<IDismissed>("Rejected", rejectedSchema);
const Rejected = mongoose.model<IDismissed>("Dismissed", rejectedSchema);
export default Rejected;
196 changes: 165 additions & 31 deletions src/resolvers/applicationStageResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ import Rejected from "../models/dismissedStageSchema";
import Admitted from "../models/admittedStageSchema";
import InterviewAssessment from "../models/InterviewAssessmentStageSchema";
import TechnicalAssessment from "../models/technicalAssessmentStage";
import mongoose from "mongoose";
import { traineEAttributes } from "../models/traineeAttribute";
import { sendEmailTemplate } from "../helpers/bulkyMails";
import { ApplicantNotificationsModel } from "../models/applicantNotifications";
import { LoggedUserModel } from "../models/AuthUser";
import { pusher } from "../helpers/pusher";
import { traineEAttributes } from "../models/traineeAttribute";
import mongoose from "mongoose";

const validStages = [
"Shortlisted",
Expand All @@ -31,7 +34,7 @@ async function getApplicantsByModel(model: any) {
async function updateApplicantAfterDismissed(model: any, applicantId: string) {
await model.updateOne({ applicantId }, { $set: { status: "Rejected" } });
}
async function updateApplicantAfterAdmitted(model: any, applicantId: string) {
async function updateApplicantAfterAdmitted(model: any,applicantId:string) {
await model.updateOne({ applicantId }, { $set: { status: "Admitted" } });
}
export const applicationStageResolvers: any = {
Expand Down Expand Up @@ -179,6 +182,9 @@ export const applicationStageResolvers: any = {
context: any
) => {
try {
const applicant = await TraineeApplicant.findById(applicantId);
const user = await LoggedUserModel.findOne({ email: applicant!.email });

if (!context.currentUser) {
throw new CustomGraphQLError(
"You must be logged in to perform this action"
Expand Down Expand Up @@ -208,6 +214,8 @@ export const applicationStageResolvers: any = {
);
}

let scoreDetails = "";

if (nextStage === "Interview Assessment") {
const technicalScore = await TechnicalAssessment.findOne({
applicantId,
Expand All @@ -221,6 +229,7 @@ export const applicationStageResolvers: any = {
"Technical assessment score is required before moving to the Interview Assessment, Please add score😎."
);
}
scoreDetails = `Your Technical Assessment Score: ${technicalScore.score}`;
}

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

if (!stageTracking) {
Expand Down Expand Up @@ -291,8 +301,36 @@ export const applicationStageResolvers: any = {
await TraineeApplicant.updateOne(
{ _id: applicantId },
{ $set: { applicationPhase: nextStage, status: "No action" } }
);
message = `You have advanced to the ${nextStage} stage.`;
const notification = await ApplicantNotificationsModel.create({
userId: user!._id,
message,
eventType: "general",
});

await sendEmailTemplate(
user!.email,
"Application Update",
`Hello ${user!.email.split("@")[0]}, `,
`Your application has been moved to ${nextStage} stage.
<br />
You will hear from us very soon.
<br />
Thank you for your patience.
`
);
message = `Applicant advanced to ${nextStage} stage.`;

await pusher
.trigger(`notifications-${user!._id}`, "new-notification", {
message: notification.message,
id: notification._id,
createdAt: notification.createdAt,
read: notification.read,
})
.catch((error) => {
console.error("Error with Pusher trigger:", error);
});
break;

case "Interview Assessment":
Expand All @@ -311,7 +349,38 @@ export const applicationStageResolvers: any = {
comments,
status: "No action",
});
message = `Applicant advanced to ${nextStage} stage.`;
message = `You have advanced to the ${nextStage} stage.`;
const notification1 = await ApplicantNotificationsModel.create({
userId: user!._id,
message,
eventType: "general",
});

await sendEmailTemplate(
user!.email,
"Application Update",
`Hello ${user!.email.split("@")[0]}, `,
`Your application has been moved to ${nextStage} stage.
<br />
${scoreDetails}
<br />
<br />
You will hear from us very soon.
<br />
Thank you for your patience.
`
);

await pusher
.trigger(`notifications-${user!._id}`, "new-notification", {
message: notification1.message,
id: notification1._id,
createdAt: notification1.createdAt,
read: notification1.read,
})
.catch((error) => {
console.error("Error with Pusher trigger:", error);
});
break;

case "Admitted":
Expand All @@ -333,8 +402,7 @@ export const applicationStageResolvers: any = {
comments,
status: "Passed",
});
message = `Applicant passed the application stage✅.`;

message = `You have passed the application stage✅.`;
await TraineeApplicant.updateOne(
{ _id: applicantId },
{
Expand All @@ -345,29 +413,38 @@ export const applicationStageResolvers: any = {
},
}
);

const notification2 = await ApplicantNotificationsModel.create({
userId: user!._id,
message,
eventType: "general",
});

const updatedApplicant = await TraineeApplicant.findOne({
_id: applicantId,
})
.populate("email")
.lean();

const email = updatedApplicant?.email;

if (email) {
await LoggedUserModel.updateOne(
{ email },
{
$set: {
applicationPhase: nextStage,
status: "Admitted",
role: traineeRole._id,
},
}
);
} else {
throw new Error("Email not found for the provided applicant ID");
}
await sendEmailTemplate(
user!.email,
"Application Update",
`Hello ${user!.email.split("@")[0]}, `,
`Your application has successfully passed the application stage.
<br />
${scoreDetails}
<br />
<br />
You will hear from us very soon.
<br />
Thank you for your patience.
`
);

await pusher
.trigger(`notifications-${user!._id}`, "new-notification", {
message: notification2.message,
id: notification2._id,
createdAt: notification2.createdAt,
read: notification2.read,
})
.catch((error) => {
console.error("Error with Pusher trigger:", error);
});
break;

case "Rejected":
Expand All @@ -394,7 +471,36 @@ export const applicationStageResolvers: any = {
{ _id: applicantId },
{ $set: { applicationPhase: "Rejected", status: "Rejected" } }
);
message = `Applicant Rejected from the ${stageDismissedFrom?.applicationPhase} stage.`;
message = `You have been rejected from the ${stageDismissedFrom?.applicationPhase} stage.`;

const notification3 = await ApplicantNotificationsModel.create({
userId: user!._id,
message,
eventType: "general",
});

await sendEmailTemplate(
user!.email,
"Application Update",
`Hello ${user!.email.split("@")[0]}, `,
`We are sorry to inform you that
your application has been rejected from the ${stageDismissedFrom?.applicationPhase} stage.
<br />
<br />
You can always apply again.
`
);

await pusher
.trigger(`notifications-${user!._id}`, "new-notification", {
message: notification3.message,
id: notification3._id,
createdAt: notification3.createdAt,
read: notification3.read,
})
.catch((error) => {
console.error("Error with Pusher trigger:", error);
});
break;

case "Shortlisted":
Expand All @@ -414,7 +520,35 @@ export const applicationStageResolvers: any = {
{ _id: applicantId },
{ $set: { applicationPhase: nextStage, status: "No action" } }
);
message = `Applicant advanced to ${nextStage} stage.`;
message = `You have advanced to the ${nextStage} stage.`;
const notification4 = await ApplicantNotificationsModel.create({
userId: user!._id,
message,
eventType: "general",
});

await sendEmailTemplate(
user!.email,
"Application Update",
`Hello ${user!.email.split("@")[0]}, `,
`Your application has been moved to ${nextStage} stage.
<br />
You will hear from us very soon.
<br />
Thank you for your patience.
`
);

await pusher
.trigger(`notifications-${user!._id}`, "new-notification", {
message: notification4.message,
id: notification4._id,
createdAt: notification4.createdAt,
read: notification4.read,
})
.catch((error) => {
console.error("Error with Pusher trigger:", error);
});
break;
}

Expand Down
Loading

0 comments on commit 014e807

Please sign in to comment.