@ideal-photography/shared
Version:
Shared MongoDB and utility logic for Ideal Photography PWAs: users, products, services, bookings, orders/cart, galleries, reviews, notifications, campaigns, settings, audit logs, minimart items/orders, and push notification subscriptions.
37 lines (34 loc) • 1.18 kB
JavaScript
import { models } from '../mongoDB/index.js';
class NotificationMetrics {
static async aggregateDailyMetrics(startDate, endDate) {
const Notification = models.Notification;
return Notification.aggregate([
{
$match: {
createdAt: { $gte: startDate, $lte: endDate }
}
},
{
$group: {
_id: {
day: { $dateToString: { format: '%Y-%m-%d', date: '$createdAt' } },
trigger: '$trigger'
},
total: { $sum: 1 },
emailSent: {
$sum: {
$cond: [{ $eq: ['$channels.email', true] }, 1, 0]
}
},
pushSent: {
$sum: {
$cond: [{ $eq: ['$channels.push', true] }, 1, 0]
}
}
}
},
{ $sort: { '_id.day': 1 } }
]);
}
}
export default NotificationMetrics;