Skip to content

Commit

Permalink
fix(apply-jobpost): incorporate feedback (#168)
Browse files Browse the repository at this point in the history
- remove 'submitted' status
- add comments for 'rejected status'
  • Loading branch information
jkarenzi authored and bahati10 committed Dec 6, 2024
1 parent 9b4f163 commit c9b1a29
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 6 deletions.
8 changes: 6 additions & 2 deletions src/models/JobApplication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ const jobApplicationSchema = new mongoose.Schema({
},
status:{
type:String,
enum:['submitted','under-review','accepted','rejected'],
default:'submitted'
enum:['under-review','accepted','rejected'],
default:'under-review'
},
comment: {
type:String,
required: false
}
},{timestamps:true})

Expand Down
28 changes: 24 additions & 4 deletions src/resolvers/jobApplicationResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ interface getOneFormData {

interface statusData {
applicationId: string,
status: string
status: string,
comment: string
}

const formatDate = (date:Date) => {
Expand Down Expand Up @@ -114,6 +115,7 @@ export const jobApplicationResolver = {
essay: application.essay,
resume: application.resume,
status: application.status,
comment: application.comment,
jobId: application.jobId,
createdAt: formatDate(application.createdAt)
}
Expand Down Expand Up @@ -175,10 +177,28 @@ export const jobApplicationResolver = {
);
}

const { status, applicationId } = input
await JobApplication.findByIdAndUpdate(applicationId, {status})
const { status, applicationId, comment } = input
if(comment){
await JobApplication.findByIdAndUpdate(applicationId, {status, comment})
}else{
await JobApplication.findByIdAndUpdate(applicationId, {status})
}

const application = await JobApplication.findOne({_id:applicationId}).populate('userId').populate('jobId')
return application
if(!application){
throw new Error('Application not found');
}

return {
_id: application._id,
userId: application.userId,
essay: application.essay,
resume: application.resume,
status: application.status,
comment: application.comment,
jobId: application.jobId,
createdAt: formatDate(application.createdAt)
}
}
},
};
37 changes: 37 additions & 0 deletions src/resolvers/scheduleInterviewResolver.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { sendEmailTemplate } from "../helpers/bulkyMails";
import { pusher } from "../helpers/pusher";
import { ApplicantNotificationsModel } from "../models/applicantNotifications";
import { LoggedUserModel } from "../models/AuthUser";
import { RoleModel } from "../models/roleModel";
import TechnicalInterview from "../models/technicalInterviewSchema";
Expand Down Expand Up @@ -220,6 +222,41 @@ export const technicalInterviewResolvers = {
const applicantData = await TraineeApplicant.findById(applicantId);
const coordinatorData = await LoggedUserModel.findById(coordinatorId);

// Create notification for applicant
const applicantNotification = await ApplicantNotificationsModel.create({
userId: applicantId,
message: `Technical Interview Scheduled for ${interview.scheduledDate.toLocaleString()}`,
eventType: "applicationUpdate",
relatedObjectId: interview._id,
});

// Create notification for coordinator
const coordinatorNotification =
await ApplicantNotificationsModel.create({
userId: coordinatorId,
message: `Technical Interview Assigned: Candidate ${applicantData?.firstName} ${applicantData?.lastName}`,
eventType: "applicationUpdate",
relatedObjectId: interview._id,
});

// Send Pusher notifications
await Promise.all([
pusher.trigger(`notifications-${applicantId}`, "new-notification", {
message: applicantNotification.message,
id: applicantNotification._id,
createdAt: applicantNotification.createdAt,
read: applicantNotification.read,
}),
pusher.trigger(`notifications-${coordinatorId}`, "new-notification", {
message: coordinatorNotification.message,
id: coordinatorNotification._id,
createdAt: coordinatorNotification.createdAt,
read: coordinatorNotification.read,
}),
]).catch((error) => {
console.error("Error with Pusher triggers:", error);
});

if (applicantData?.email && coordinatorData?.email) {
const applicantEmailTemplate = `
<!DOCTYPE html>
Expand Down
2 changes: 2 additions & 0 deletions src/schema/jobApplicationSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const jobApplicationTypeDefs = gql`
essay: String!
resume: String!
status: String!
comment: String
createdAt: String!
}
Expand All @@ -39,6 +40,7 @@ export const jobApplicationTypeDefs = gql`
input StatusInput {
applicationId: ID!
status: String!
comment: String
}
type checkIfUserAppliedOutput {
Expand Down

0 comments on commit c9b1a29

Please sign in to comment.