-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreportGenerator.js
52 lines (40 loc) · 1.3 KB
/
reportGenerator.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const PDFDocument = require('pdfkit');
const fs = require('fs');
const path = require('path');
// Mock database functions
async function getStudentDetails(studentId) {
return Promise.resolve({
id: studentId,
name: "John Doe",
class: "10A"
});
}
async function getAcademicPerformance(studentId) {
return Promise.resolve([
{ subject: "Math", score: 95 },
{ subject: "Science", score: 88 }
]);
}
async function getAttendanceRecords(studentId) {
return Promise.resolve([
{ date: "2023-01-01", status: "Present" },
{ date: "2023-01-02", status: "Absent" }
]);
}
function generateReport(studentId) {
return new Promise(async (resolve, reject) => {
const studentDetails = await getStudentDetails(studentId);
const academicPerformance = await getAcademicPerformance(studentId);
const attendanceRecords = await getAttendanceRecords(studentId);
// Create a new PDF document
const doc = new PDFDocument();
const reportPath = path.join(__dirname, `report_${studentId}.pdf`);
// Pipe the PDF into a file
doc.pipe(fs.createWriteStream(reportPath));
doc.fontSize(25).text('Student Report', 100, 80);
doc.fontSize(12).text(`Name: ${studentDetails.name}`, 100, 120);
doc.end();
resolve(reportPath);
});
}
module.exports = { generateReport };