Skip to content

Commit

Permalink
Add push notification for announcements
Browse files Browse the repository at this point in the history
  • Loading branch information
mfjkri committed Oct 14, 2023
1 parent eacdb6c commit c62b91f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
16 changes: 15 additions & 1 deletion src/dataaccess/announcement.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Announcement from "../models/announcement";
import User from "../models/user";
import { getClassById, getClassesByStudentId } from "./class";
import { sendEmail } from "../utilities/mail";
import { getClassById, getClassViewById, getClassesByStudentId } from "./class";

async function createAnnouncement(
centreId: number,
Expand All @@ -10,6 +11,19 @@ async function createAnnouncement(
content: string
): Promise<Announcement> {
try {
const targetClass: any = await getClassViewById(centreId, classId);
targetClass.students.forEach((student: any) => {
sendEmail(
student.email,
`Announcement (${targetClass.name}): ${title}`,
`Hi ${student.fullName},
\n\nA new announcement has been posted in ${targetClass.name}:
\n ${content}
\n\nRegards,
\n${targetClass.centre.name}`
);
});

return await Announcement.create({
centreId: centreId,
classId: classId,
Expand Down
2 changes: 0 additions & 2 deletions src/dataaccess/assessment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ async function uploadAssessmentGrades(
}[] = [];

for (const row of data) {
console.log(row);
const studentId = parseInt(row["Student ID"]);
const score = parseInt(row["Score"]);

Expand Down Expand Up @@ -188,7 +187,6 @@ async function uploadAssessmentGrades(
}
}
} catch (error: any) {
console.log(error);
throw new Error(`Failed to upload assessment: ${error.message}`);
}
}
Expand Down

0 comments on commit c62b91f

Please sign in to comment.