mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-11-22 13:29:22 +00:00
Can count all new elements
This commit is contained in:
parent
704e05bafe
commit
b4c44fff1b
@ -1,5 +1,7 @@
|
||||
import { RequestHandler } from "../entities/RequestHandler";
|
||||
import { NotificationsHelper } from "../helpers/NotificationsHelper";
|
||||
import { ConversationsHelper } from "../helpers/ConversationsHelper";
|
||||
import { FriendsHelper } from "../helpers/FriendsHelper";
|
||||
|
||||
/**
|
||||
* Notifications controller
|
||||
@ -20,4 +22,22 @@ export class NotificationsController {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Count the entire number of unread notifications
|
||||
*
|
||||
* @param h Request handler
|
||||
*/
|
||||
public static async CountAllNews(h: RequestHandler) {
|
||||
let data = {
|
||||
notifications: await NotificationsHelper.CountUnread(h.getUserId()),
|
||||
conversations: await ConversationsHelper.CountUnreadForUser(h.getUserId())
|
||||
}
|
||||
|
||||
if(h.postBool("friends_request", false))
|
||||
data["friends_requests"] = await FriendsHelper.CountRequests(h.getUserId());
|
||||
|
||||
// TODO : add pending calls
|
||||
|
||||
h.send(data);
|
||||
}
|
||||
}
|
@ -136,4 +136,6 @@ export const Routes : Route[] = [
|
||||
|
||||
// Notifications controller
|
||||
{path: "/notifications/count_unread", cb: (h) => NotificationsController.CountUnread(h)},
|
||||
|
||||
{path: "/notifications/count_all_news", cb: (h) => NotificationsController.CountAllNews(h)},
|
||||
]
|
29
src/helpers/FriendsHelper.ts
Normal file
29
src/helpers/FriendsHelper.ts
Normal file
@ -0,0 +1,29 @@
|
||||
import { DatabaseHelper } from "./DatabaseHelper";
|
||||
|
||||
/**
|
||||
* Friends helper
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
|
||||
const FRIENDS_TABLE = "amis";
|
||||
|
||||
export class FriendsHelper {
|
||||
|
||||
/**
|
||||
* Count the number of friendship requests a user
|
||||
* received
|
||||
*
|
||||
* @param userID Target user ID
|
||||
*/
|
||||
public static async CountRequests(userID: number) : Promise<number> {
|
||||
return await DatabaseHelper.Count({
|
||||
table: FRIENDS_TABLE,
|
||||
where: {
|
||||
ID_personne: userID,
|
||||
actif: 0
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user