From d6ed27b362616844b690d42a72701762cbb2450d Mon Sep 17 00:00:00 2001 From: Arthur Rezende Date: Sat, 20 Jan 2024 10:36:27 -0300 Subject: [PATCH] fix: types --- src/Mixins/HasDatabaseNotifications.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Mixins/HasDatabaseNotifications.ts b/src/Mixins/HasDatabaseNotifications.ts index 869ed39..27a3b97 100644 --- a/src/Mixins/HasDatabaseNotifications.ts +++ b/src/Mixins/HasDatabaseNotifications.ts @@ -6,7 +6,6 @@ import { } from '@ioc:Verful/Notification' import { DateTime } from 'luxon' import createNotificationModel from '../Models/DatabaseNotification' -import Application from '@adonisjs/core/build/services/app.js' /** * This mixin is used to add the notifications relationship to the model @@ -26,7 +25,6 @@ function HasDatabaseNotifications(notificationsTable: string): HasDatabaseNotifi private static $addNotificationsRelation() { const relatedModel = () => DatabaseNotification this.$addRelation('notifications', 'hasMany', relatedModel, { - relatedModel, localKey: 'id', foreignKey: 'notifiableId', }) @@ -34,25 +32,25 @@ function HasDatabaseNotifications(notificationsTable: string): HasDatabaseNotifi public notifications: HasMany - public async readNotifications(this: HasDatabaseNotificationsModel) { + public async readNotifications(this: HasDatabaseNotificationsModelContract) { return this.related('notifications') .query() .whereNotNull('readAt') .orderBy('createdAt', 'desc') } - public async unreadNotifications(this: HasDatabaseNotificationsModel) { + public async unreadNotifications(this: HasDatabaseNotificationsModelContract) { return this.related('notifications') .query() .whereNull('readAt') .orderBy('createdAt', 'desc') } - public async markNotificationsAsRead(this: HasDatabaseNotificationsModel) { + public async markNotificationsAsRead(this: HasDatabaseNotificationsModelContract) { await this.related('notifications').query().update({ readAt: DateTime.now().toSQL() }) } - public async markNotificationsAsUnread(this: HasDatabaseNotificationsModel) { + public async markNotificationsAsUnread(this: HasDatabaseNotificationsModelContract) { await this.related('notifications').query().update({ readAt: null }) } }