mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2025-06-20 00:25:17 +00:00
Can get the list of notifications of the user
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
import { DatabaseHelper } from "./DatabaseHelper";
|
||||
import { Notif } from "../entities/Notification";
|
||||
|
||||
/**
|
||||
* Notifications helper
|
||||
@ -25,4 +26,42 @@ export class NotificationsHelper {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of unread notifications of a user
|
||||
*
|
||||
* @param userID Target user ID
|
||||
*/
|
||||
public static async GetListUnread(userID: number) : Promise<Array<Notif>> {
|
||||
const list = await DatabaseHelper.Query({
|
||||
table: NOTIFICATIONS_TABLE,
|
||||
where: {
|
||||
dest_user_id: userID,
|
||||
seen: 0
|
||||
},
|
||||
order: "id DESC"
|
||||
});
|
||||
|
||||
return list.map((e) => this.DBToNotif(e));
|
||||
}
|
||||
|
||||
/**
|
||||
* Database entry to notification
|
||||
*
|
||||
* @param row Database entry
|
||||
*/
|
||||
private static DBToNotif(row: any) : Notif {
|
||||
return new Notif({
|
||||
id: row.id,
|
||||
seen: row.seen == 1,
|
||||
timeCreate: row.time_create,
|
||||
fromUserID: row.from_user_id,
|
||||
destUserID: row.dest_user_id,
|
||||
onElemID: row.on_elem_id,
|
||||
onElemType: row.on_elem_type,
|
||||
type: row.type,
|
||||
eventVisibility: row.visibility,
|
||||
fromContainerID: row.from_container_id,
|
||||
fromContainerType: row.from_container_type
|
||||
});
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user