-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotifyImageErr.js
More file actions
67 lines (63 loc) · 2.2 KB
/
notifyImageErr.js
File metadata and controls
67 lines (63 loc) · 2.2 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/**
* @fileoverview Image Error Notification Controller
*
* This controller handles reporting image loading errors from the frontend.
* It sends error notifications to administrators when politician profile images
* or other image assets fail to load, helping identify and fix image issues.
*
* BUSINESS LOGIC
*
* ERROR REPORTING
* - Receives image error reports from frontend
* - Sends notification email to administrator
* - Includes politician information for context
* - Helps identify broken image URLs or missing assets
*
* EMAIL NOTIFICATION
* - Sends to FIRST_CITIZEN (primary admin email)
* - Uses Image error email template
* - Includes politician ID/name for reference
*
* DEPENDENCIES
* - controller/comms: Email sending
* - controller/comms/emails: Email templates
* - process.env.EMAIL_JONATHAN_USER: Administrator email address
*
* @module controller/sys/notifyImageErr
* @requires ../comms
* @requires ../comms/emails
*/
const path = require('path');
const { emails } = require('../comms/emails');
const { sendEmail } = require('../comms');
if (process.env.NODE_ENV !== 'production') {
require('dotenv').config({
path: path.resolve(__dirname, '../../.env.local'),
});
}
const FIRST_CITIZEN = process.env.EMAIL_JONATHAN_USER;
module.exports = {
/**
* Sends image error notification to administrator
*
* This function receives image loading error reports from the frontend and
* sends a notification email to the administrator with the politician information
* to help identify and fix the image issue.
*
* @param {Object} req - Express request object
* @param {Object} req.body - Error report data
* @param {string} req.body.pol - Politician ID or name that failed to load image
* @param {Object} res - Express response object
* @returns {Promise<void>} Resolves when notification is sent
*
* @example
* ```javascript
* const { notifyImageErr } = require('./controller/sys/notifyImageErr');
* await notifyImageErr(req, res);
* ```
*/
notifyImageErr: (req, res) => {
const sent = sendEmail(FIRST_CITIZEN, emails.Image, req.body.pol);
if (sent) res.json(true);
},
};