Verfied response system for electeds
This commit is contained in:
@@ -409,6 +409,62 @@ class EmailService {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send response verification email to representative
|
||||
* @param {Object} options - Email options
|
||||
* @param {string} options.representativeEmail - Representative's email address
|
||||
* @param {string} options.representativeName - Representative's name
|
||||
* @param {string} options.campaignTitle - Campaign title
|
||||
* @param {string} options.responseType - Type of response (Email, Letter, etc.)
|
||||
* @param {string} options.responseText - The actual response text
|
||||
* @param {string} options.submittedDate - Date the response was submitted
|
||||
* @param {string} options.submitterName - Name of person who submitted
|
||||
* @param {string} options.verificationUrl - URL to verify the response
|
||||
* @param {string} options.reportUrl - URL to report as invalid
|
||||
*/
|
||||
async sendResponseVerification(options) {
|
||||
try {
|
||||
const {
|
||||
representativeEmail,
|
||||
representativeName,
|
||||
campaignTitle,
|
||||
responseType,
|
||||
responseText,
|
||||
submittedDate,
|
||||
submitterName,
|
||||
verificationUrl,
|
||||
reportUrl
|
||||
} = options;
|
||||
|
||||
const templateVariables = {
|
||||
REPRESENTATIVE_NAME: representativeName,
|
||||
CAMPAIGN_TITLE: campaignTitle,
|
||||
RESPONSE_TYPE: responseType,
|
||||
RESPONSE_TEXT: responseText,
|
||||
SUBMITTED_DATE: submittedDate,
|
||||
SUBMITTER_NAME: submitterName || 'Anonymous',
|
||||
VERIFICATION_URL: verificationUrl,
|
||||
REPORT_URL: reportUrl,
|
||||
APP_NAME: process.env.APP_NAME || 'BNKops Influence',
|
||||
TIMESTAMP: new Date().toLocaleString()
|
||||
};
|
||||
|
||||
const emailOptions = {
|
||||
to: representativeEmail,
|
||||
from: {
|
||||
email: process.env.SMTP_FROM_EMAIL,
|
||||
name: process.env.SMTP_FROM_NAME
|
||||
},
|
||||
subject: `Response Verification Request - ${campaignTitle}`
|
||||
};
|
||||
|
||||
return await this.sendTemplatedEmail('response-verification', templateVariables, emailOptions);
|
||||
} catch (error) {
|
||||
console.error('Failed to send response verification email:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = new EmailService();
|
||||
@@ -758,6 +758,11 @@ class NocoDBService {
|
||||
'Is Anonymous': responseData.is_anonymous,
|
||||
'Status': responseData.status,
|
||||
'Is Verified': responseData.is_verified,
|
||||
'Representative Email': responseData.representative_email,
|
||||
'Verification Token': responseData.verification_token,
|
||||
'Verification Sent At': responseData.verification_sent_at,
|
||||
'Verified At': responseData.verified_at,
|
||||
'Verified By': responseData.verified_by,
|
||||
'Upvote Count': responseData.upvote_count,
|
||||
'Submitted IP': responseData.submitted_ip
|
||||
};
|
||||
@@ -780,6 +785,11 @@ class NocoDBService {
|
||||
if (updates.upvote_count !== undefined) data['Upvote Count'] = updates.upvote_count;
|
||||
if (updates.response_text !== undefined) data['Response Text'] = updates.response_text;
|
||||
if (updates.user_comment !== undefined) data['User Comment'] = updates.user_comment;
|
||||
if (updates.representative_email !== undefined) data['Representative Email'] = updates.representative_email;
|
||||
if (updates.verification_token !== undefined) data['Verification Token'] = updates.verification_token;
|
||||
if (updates.verification_sent_at !== undefined) data['Verification Sent At'] = updates.verification_sent_at;
|
||||
if (updates.verified_at !== undefined) data['Verified At'] = updates.verified_at;
|
||||
if (updates.verified_by !== undefined) data['Verified By'] = updates.verified_by;
|
||||
|
||||
console.log(`Updating response ${responseId} with data:`, JSON.stringify(data, null, 2));
|
||||
|
||||
@@ -858,6 +868,11 @@ class NocoDBService {
|
||||
is_anonymous: data['Is Anonymous'] || data.is_anonymous || false,
|
||||
status: data['Status'] || data.status,
|
||||
is_verified: data['Is Verified'] || data.is_verified || false,
|
||||
representative_email: data['Representative Email'] || data.representative_email,
|
||||
verification_token: data['Verification Token'] || data.verification_token,
|
||||
verification_sent_at: data['Verification Sent At'] || data.verification_sent_at,
|
||||
verified_at: data['Verified At'] || data.verified_at,
|
||||
verified_by: data['Verified By'] || data.verified_by,
|
||||
upvote_count: data['Upvote Count'] || data.upvote_count || 0,
|
||||
submitted_ip: data['Submitted IP'] || data.submitted_ip,
|
||||
created_at: data.CreatedAt || data.created_at,
|
||||
|
||||
Reference in New Issue
Block a user