Files
starr-philproperties/apps/api/utils/notificationVisibility.util.js
T

26 lines
1.2 KiB
JavaScript

/***********************************************************************************************************************************************************************
* File Name : notificationVisibility.util.js
* Type : Utility
* Description : Shared visibility-window filter for AdminNotification/
* UserNotification rows carrying a denormalized start_date/
* end_date (copied from NotificationBroadcast at send time —
* see notificationBroadcasts.controller.js#sendBroadcast).
* Non-announcement notifications have both columns null, so
* this filter is a no-op for them.
*
* Author: Kenneth Obsequio (@lash0000)
* Date Created: Jul. 11, 2026
***********************************************************************************************************************************************************************/
const { Op } = require('sequelize');
function notInFutureOrExpired(now = new Date()) {
return {
[Op.and]: [
{ [Op.or]: [{ start_date: null }, { start_date: { [Op.lte]: now } }] },
{ [Op.or]: [{ end_date: null }, { end_date: { [Op.gte]: now } }] },
],
};
}
module.exports = { notInFutureOrExpired };