mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
fix notification
This commit is contained in:
@@ -36,10 +36,18 @@ export class LocalNotificationService {
|
||||
async updateNotifications(data: NotificationTable[]) {
|
||||
// db.eve
|
||||
try {
|
||||
const result = await NotificationDataSource.notification.bulkUpdate(data.map(e => ({
|
||||
key: e.notificationId,
|
||||
changes: { status: e.status }
|
||||
})))
|
||||
const result = await NotificationDataSource.notification.bulkDelete(data.map(e => e.notificationId))
|
||||
return ok(result)
|
||||
} catch (e) {
|
||||
return err(false)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async deleteNotifications(data: NotificationTable[]) {
|
||||
// db.eve
|
||||
try {
|
||||
const result = await NotificationDataSource.notification.bulkDelete(data.map(e => e.notificationId))
|
||||
return ok(result)
|
||||
} catch (e) {
|
||||
return err(false)
|
||||
@@ -58,6 +66,46 @@ export class LocalNotificationService {
|
||||
return result.success;
|
||||
});
|
||||
|
||||
// Add valid notifications to the database
|
||||
if (validNotifications.length > 0) {
|
||||
|
||||
} else {
|
||||
console.log('No valid notifications to add.');
|
||||
}
|
||||
|
||||
console.log({failed})
|
||||
|
||||
return ok(failed)
|
||||
}
|
||||
|
||||
async clearAndAddRecords(notifications: NotificationTable[]) {
|
||||
try {
|
||||
await NotificationDataSource.transaction('rw', NotificationDataSource.notification, async () => {
|
||||
// Clear existing records from myTable
|
||||
await NotificationDataSource.notification.clear();
|
||||
|
||||
await NotificationDataSource.notification.bulkAdd(notifications);
|
||||
|
||||
});
|
||||
console.log('Clear and add operations completed within transaction.');
|
||||
} catch (error) {
|
||||
console.error('Error performing transaction:', error, notifications);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async addRemove(notifications: NotificationTable[]) {
|
||||
// Validate each notification
|
||||
const failed = []
|
||||
const validNotifications = notifications.filter(notification => {
|
||||
const result = NotificationTableSchema.safeParse(notification);
|
||||
|
||||
if(!result.success) {
|
||||
failed.push(notification)
|
||||
}
|
||||
return result.success;
|
||||
});
|
||||
|
||||
// Add valid notifications to the database
|
||||
if (validNotifications.length > 0) {
|
||||
await NotificationDataSource.notification.bulkAdd(validNotifications);
|
||||
@@ -73,6 +121,19 @@ export class LocalNotificationService {
|
||||
getNotificationLive() {
|
||||
return from(liveQuery( () => {
|
||||
return NotificationDataSource.notification.orderBy('createdAt').reverse().toArray()
|
||||
.then(notifications => {
|
||||
return notifications.filter(notification => notification.status === false)
|
||||
})
|
||||
}))
|
||||
}
|
||||
|
||||
getNotificationLiveCount() {
|
||||
return from(liveQuery( () => {
|
||||
return NotificationDataSource.notification
|
||||
.toArray()
|
||||
.then(notifications => {
|
||||
return notifications.filter(notification => notification.status === false).length
|
||||
})
|
||||
}))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user