Skip to content

Commit

Permalink
feat(notifications): filter notifications by due date (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
shoom3301 authored May 15, 2024
1 parent 0c38267 commit 54dc161
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"push": {
"type": "boolean"
},
"due_date": {
"dueDate": {
"type": "datetime"
},
"thumbnail": {
Expand Down
20 changes: 17 additions & 3 deletions src/api/notification/services/notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@ const NOTIFICATIONS_POPULATE = {
}
}

const notificationsTemplateFilter = (push: boolean) => ({
$or: [
{
push,
dueDate: { $gt: new Date() }
},
{
push,
dueDate: { $null: true }
}
]
})

export default factories.createCoreService(MODULE_ID, ({ strapi }) => {
return {
async getNotificationsForAll(push: boolean) {
Expand All @@ -29,7 +42,7 @@ export default factories.createCoreService(MODULE_ID, ({ strapi }) => {
limit: 50,
filters: {
account: { $null: true },
notification_template: { push }
notification_template: notificationsTemplateFilter(push)
},
populate: NOTIFICATIONS_POPULATE
}
Expand All @@ -44,7 +57,7 @@ export default factories.createCoreService(MODULE_ID, ({ strapi }) => {
limit: 50,
filters: {
account,
notification_template: { push }
notification_template: notificationsTemplateFilter(push)
},
populate: NOTIFICATIONS_POPULATE
}
Expand All @@ -56,6 +69,7 @@ export default factories.createCoreService(MODULE_ID, ({ strapi }) => {
account: notification.account,
title: notification.notification_template.title,
description: templateNotification(notification.notification_template.description, notification.data),
dueDate: notification.notification_template.dueDate,
url: notification.notification_template.url,
createdAt: notification.createdAt,
thumbnail: notification.notification_template.thumbnail?.url
Expand All @@ -74,7 +88,7 @@ export default factories.createCoreService(MODULE_ID, ({ strapi }) => {
{
limit: 200,
filters: {
notification_template: { push },
notification_template: notificationsTemplateFilter(push),
...(lastConsumedNotificationDate ? {
createdAt: {$gt: lastConsumedNotificationDate}
} : undefined)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"name": "Apache 2.0",
"url": "https://www.apache.org/licenses/LICENSE-2.0.html"
},
"x-generation-date": "2024-05-09T07:14:54.538Z"
"x-generation-date": "2024-05-15T10:34:01.347Z"
},
"x-strapi-config": {
"path": "/documentation",
Expand Down Expand Up @@ -11737,7 +11737,7 @@
"push": {
"type": "boolean"
},
"due_date": {
"dueDate": {
"type": "string",
"format": "date-time"
},
Expand Down Expand Up @@ -12501,7 +12501,7 @@
"push": {
"type": "boolean"
},
"due_date": {
"dueDate": {
"type": "string",
"format": "date-time"
},
Expand Down Expand Up @@ -12581,7 +12581,7 @@
"push": {
"type": "boolean"
},
"due_date": {
"dueDate": {
"type": "string",
"format": "date-time"
},
Expand Down

0 comments on commit 54dc161

Please sign in to comment.