mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-11-22 13:29:22 +00:00
Can get the list of post targets of a user
This commit is contained in:
parent
8c09848ee9
commit
d362c0faab
@ -18,6 +18,7 @@ import { pathUserData } from "../utils/UserDataUtils";
|
||||
import { statSync } from "fs";
|
||||
import { lookup } from "mime-types";
|
||||
import { NewSurvey } from "../entities/NewSurvey";
|
||||
import { FriendsHelper } from "../helpers/FriendsHelper";
|
||||
|
||||
/**
|
||||
* Posts controller
|
||||
@ -349,6 +350,21 @@ export class PostsController {
|
||||
h.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the lists of targets where the current user can create posts
|
||||
*
|
||||
* @param h Request handler
|
||||
*/
|
||||
public static async GetTargets(h: RequestHandler) {
|
||||
const friends = await FriendsHelper.GetListThatAllowsPostsFromUser(h.getUserId());
|
||||
const groups = await GroupsHelper.GetListUserWhereCanCreatePosts(h.getUserId());
|
||||
|
||||
h.send({
|
||||
friends: friends,
|
||||
groups: groups
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Send multiple posts to the API
|
||||
*
|
||||
|
@ -200,6 +200,8 @@ export const Routes : Route[] = [
|
||||
|
||||
{path: "/posts/delete", cb: (h) => PostsController.DeletePost(h)},
|
||||
|
||||
{path: "/posts/getAvailableTargets", cb: (h) => PostsController.GetTargets(h)},
|
||||
|
||||
|
||||
|
||||
// Notifications controller
|
||||
|
@ -44,6 +44,25 @@ export class FriendsHelper {
|
||||
return results.map((r) => this.DbToFriend(r));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of friends of a given user who allows
|
||||
* him to create post on their pages
|
||||
*
|
||||
* @param userID ID of the user making the request
|
||||
*/
|
||||
public static async GetListThatAllowsPostsFromUser(userID: number) : Promise<Array<number>> {
|
||||
const list = await DatabaseHelper.Query({
|
||||
table: FRIENDS_TABLE,
|
||||
where: {
|
||||
autoriser_post_page: 1,
|
||||
ID_amis: userID
|
||||
},
|
||||
fields: ["ID_personne as user_id"]
|
||||
});
|
||||
|
||||
return list.map((e) => e.user_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get information about a single membership
|
||||
*
|
||||
|
@ -83,6 +83,46 @@ export class GroupsHelper {
|
||||
return list.map(e => e.groups_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of gruops of a user where the users can create
|
||||
* posts
|
||||
*
|
||||
* @param userID The ID of the target user
|
||||
*/
|
||||
public static async GetListUserWhereCanCreatePosts(userID: number) : Promise<Array<number>> {
|
||||
const list = await DatabaseHelper.Query({
|
||||
// Members table
|
||||
table: GROUPS_MEMBERS_TABLE,
|
||||
tableAlias: "m",
|
||||
|
||||
// Groups liist table
|
||||
joins: [
|
||||
{
|
||||
table: GROUPS_LIST_TABLE,
|
||||
tableAlias: "g",
|
||||
condition: "m.groups_id = g.id"
|
||||
}
|
||||
],
|
||||
|
||||
where: {
|
||||
user_id: userID
|
||||
},
|
||||
|
||||
customWhere: "level = ? OR level = ? OR (level = ? AND posts_level = ?)",
|
||||
customWhereArgs: [
|
||||
GroupMembershipLevels.ADMINISTRATOR.toString(),
|
||||
GroupMembershipLevels.MODERATOR.toString(),
|
||||
|
||||
GroupMembershipLevels.MEMBER.toString(),
|
||||
GroupPostsCreationLevel.POSTS_LEVEL_ALL_MEMBERS.toString()
|
||||
],
|
||||
|
||||
fields: ["g.id"]
|
||||
});
|
||||
|
||||
return list.map((e) => e.id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get information about a group
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user