Skip to content

Commit

Permalink
fix: types
Browse files Browse the repository at this point in the history
  • Loading branch information
arthur-er committed Jan 20, 2024
1 parent 011e55d commit d6ed27b
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/Mixins/HasDatabaseNotifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -26,33 +25,32 @@ function HasDatabaseNotifications(notificationsTable: string): HasDatabaseNotifi
private static $addNotificationsRelation() {
const relatedModel = () => DatabaseNotification
this.$addRelation('notifications', 'hasMany', relatedModel, {
relatedModel,
localKey: 'id',
foreignKey: 'notifiableId',
})
}

public notifications: HasMany<DatabaseNotificationModel>

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 })
}
}
Expand Down

0 comments on commit d6ed27b

Please sign in to comment.