UNPKG

node-backend-generator

Version:

🚀 CLI tool to generate professional Node.js backend templates with best practices, multiple databases, authentication, and production-ready features

84 lines (71 loc) • 1.84 kB
import { notificationQueue } from '../queues/notificationQueue.js'; import { sendEmail } from '../services/emailService.js'; import { sendSMS } from '../services/smsService.js'; export class NotificationController { async sendEmail(req, res) { try { const { to, subject, template, data } = req.body; await notificationQueue.add('send-email', { to, subject, template, data }); res.json({ success: true, message: 'Email queued for sending' }); } catch (error) { res.status(500).json({ success: false, error: error.message }); } } async sendBulkEmail(req, res) { try { const { emails, subject, template, data } = req.body; const jobs = emails.map(email => ({ name: 'send-email', data: { to: email, subject, template, data } })); await notificationQueue.addBulk(jobs); res.json({ success: true, message: `${emails.length} emails queued for sending` }); } catch (error) { res.status(500).json({ success: false, error: error.message }); } } async getNotificationStatus(req, res) { try { const { jobId } = req.params; const job = await notificationQueue.getJob(jobId); if (!job) { return res.status(404).json({ success: false, error: 'Job not found' }); } res.json({ success: true, data: { id: job.id, status: await job.getState(), progress: job.progress, result: job.returnvalue } }); } catch (error) { res.status(500).json({ success: false, error: error.message }); } } } export default new NotificationController();