From 54dc161c66eea8c07f9ff681e3d2751bcc3d9410 Mon Sep 17 00:00:00 2001 From: Alexandr Kazachenko Date: Wed, 15 May 2024 15:36:10 +0500 Subject: [PATCH] feat(notifications): filter notifications by due date (#29) --- .../notification-template/schema.json | 2 +- src/api/notification/services/notification.ts | 20 ++++++++++++++++--- .../1.0.0/full_documentation.json | 8 ++++---- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/api/notification-template/content-types/notification-template/schema.json b/src/api/notification-template/content-types/notification-template/schema.json index cd74701..30a77cc 100644 --- a/src/api/notification-template/content-types/notification-template/schema.json +++ b/src/api/notification-template/content-types/notification-template/schema.json @@ -24,7 +24,7 @@ "push": { "type": "boolean" }, - "due_date": { + "dueDate": { "type": "datetime" }, "thumbnail": { diff --git a/src/api/notification/services/notification.ts b/src/api/notification/services/notification.ts index 02dc67d..c7ec742 100644 --- a/src/api/notification/services/notification.ts +++ b/src/api/notification/services/notification.ts @@ -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) { @@ -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 } @@ -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 } @@ -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 @@ -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) diff --git a/src/extensions/documentation/documentation/1.0.0/full_documentation.json b/src/extensions/documentation/documentation/1.0.0/full_documentation.json index 5d44cca..7291a5c 100644 --- a/src/extensions/documentation/documentation/1.0.0/full_documentation.json +++ b/src/extensions/documentation/documentation/1.0.0/full_documentation.json @@ -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", @@ -11737,7 +11737,7 @@ "push": { "type": "boolean" }, - "due_date": { + "dueDate": { "type": "string", "format": "date-time" }, @@ -12501,7 +12501,7 @@ "push": { "type": "boolean" }, - "due_date": { + "dueDate": { "type": "string", "format": "date-time" }, @@ -12581,7 +12581,7 @@ "push": { "type": "boolean" }, - "due_date": { + "dueDate": { "type": "string", "format": "date-time" },