ability to ban and unban users
This commit is contained in:
@@ -118,6 +118,57 @@ class UserEngagementEmailService {
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send notification when a user's account is banned
|
||||
* @param {Object} bannedUser - User who was banned
|
||||
* @param {string} bannedUser.firstName - Banned user's first name
|
||||
* @param {string} bannedUser.email - Banned user's email
|
||||
* @param {Object} admin - Admin who performed the ban
|
||||
* @param {string} admin.firstName - Admin's first name
|
||||
* @param {string} admin.lastName - Admin's last name
|
||||
* @param {string} banReason - Reason for the ban
|
||||
* @returns {Promise<{success: boolean, messageId?: string, error?: string}>}
|
||||
*/
|
||||
async sendUserBannedNotification(bannedUser, admin, banReason) {
|
||||
if (!this.initialized) {
|
||||
await this.initialize();
|
||||
}
|
||||
|
||||
try {
|
||||
const supportEmail = process.env.SUPPORT_EMAIL;
|
||||
|
||||
const variables = {
|
||||
userName: bannedUser.firstName || "there",
|
||||
banReason: banReason,
|
||||
supportEmail: supportEmail,
|
||||
};
|
||||
|
||||
const htmlContent = await this.templateManager.renderTemplate(
|
||||
"userBannedNotification",
|
||||
variables
|
||||
);
|
||||
|
||||
const subject = "Important: Your Village Share Account Has Been Suspended";
|
||||
|
||||
const result = await this.emailClient.sendEmail(
|
||||
bannedUser.email,
|
||||
subject,
|
||||
htmlContent
|
||||
);
|
||||
|
||||
if (result.success) {
|
||||
console.log(
|
||||
`User banned notification email sent to ${bannedUser.email}`
|
||||
);
|
||||
}
|
||||
|
||||
return result;
|
||||
} catch (error) {
|
||||
console.error("Failed to send user banned notification email:", error);
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = UserEngagementEmailService;
|
||||
|
||||
Reference in New Issue
Block a user