1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2024-11-22 21:39:22 +00:00

Can count all new elements

This commit is contained in:
Pierre HUBERT 2019-12-27 19:05:29 +01:00
parent 704e05bafe
commit b4c44fff1b
3 changed files with 51 additions and 0 deletions

View File

@ -1,5 +1,7 @@
import { RequestHandler } from "../entities/RequestHandler"; import { RequestHandler } from "../entities/RequestHandler";
import { NotificationsHelper } from "../helpers/NotificationsHelper"; import { NotificationsHelper } from "../helpers/NotificationsHelper";
import { ConversationsHelper } from "../helpers/ConversationsHelper";
import { FriendsHelper } from "../helpers/FriendsHelper";
/** /**
* Notifications controller * 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);
}
} }

View File

@ -136,4 +136,6 @@ export const Routes : Route[] = [
// Notifications controller // Notifications controller
{path: "/notifications/count_unread", cb: (h) => NotificationsController.CountUnread(h)}, {path: "/notifications/count_unread", cb: (h) => NotificationsController.CountUnread(h)},
{path: "/notifications/count_all_news", cb: (h) => NotificationsController.CountAllNews(h)},
] ]

View 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
}
});
}
}