diff --git a/mccs-it/thermal/app.js b/mccs-it/thermal/app.js index 205e952..56b7b5e 100644 --- a/mccs-it/thermal/app.js +++ b/mccs-it/thermal/app.js @@ -21,15 +21,7 @@ app.post('/print-credentials', async (req, res) => { const infoString = Thermal.generateInfo.credentials(username, studentId); // Generate the PDF, saved to disk - Thermal.generatePdf(infoString).then(result => { - // Print the document - Thermal.print().then(result => { - res.send('PDF sent to printer successfully.'); - }).catch(e => { - console.error('Failed to start printing process:', e); - res.status(500).json({ message: 'Failed to start printing process', error: e.message }); - }); - }).catch(e => { + Thermal.generatePdf(infoString).catch(e => { console.error(e); res.status(500).json({ message: 'Error writing PDF file', error: e.message }); }); @@ -54,15 +46,7 @@ app.post('/print-temp-pw', async (req, res) => { const infoString = Thermal.generateInfo.tempPassword(password); // Generate the PDF, saved to disk - Thermal.generatePdf(infoString).then(result => { - // Print the document - Thermal.print().then(result => { - res.send('PDF sent to printer successfully.'); - }).catch(e => { - console.error('Failed to start printing process:', err); - res.status(500).json({ message: 'Failed to start printing process', error: err.message }); - }); - }).catch(e => { + Thermal.generatePdf(infoString).catch(e => { console.error(e); res.status(500).json({ message: 'Error writing PDF file', error: err.message }); }); @@ -79,15 +63,7 @@ app.post('/print-mcc', async (req, res) => { const infoString = Thermal.generateInfo.maineCC(); // Generate the PDF, saved to disk - Thermal.generatePdf(infoString).then(result => { - // Print the document - Thermal.print().then(result => { - res.send('PDF sent to printer successfully.'); - }).catch(e => { - console.error('Failed to start printing process:', err); - res.status(500).json({ message: 'Failed to start printing process', error: err.message }); - }); - }).catch(e => { + Thermal.generatePdf(infoString).catch(e => { console.error(e); res.status(500).json({ message: 'Error writing PDF file', error: e.message }); }); @@ -97,6 +73,22 @@ app.post('/print-mcc', async (req, res) => { } }); +// Print Student MaineCC Info +app.post('/print', async (req, res) => { + try { + // Print the document + Thermal.print().then(result => { + res.send('PDF sent to printer successfully.'); + }).catch(e => { + console.error('Failed to start printing process:', err); + res.status(500).json({ message: 'Failed to start printing process', error: err.message }); + }); + } catch (e) { + console.error('Print Error:', e); + res.status(500).json({ message: 'Print Error', error: e.message }); + } +}); + // Start the server app.listen(port, () => { console.log(`Server running at http://localhost:${port}`); diff --git a/mccs-it/thermal/public/index.html b/mccs-it/thermal/public/index.html index c9b2136..0f20d41 100644 --- a/mccs-it/thermal/public/index.html +++ b/mccs-it/thermal/public/index.html @@ -34,7 +34,7 @@ @@ -57,7 +57,7 @@ @@ -67,7 +67,7 @@ @@ -84,6 +84,12 @@