1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2025-06-20 16:45:16 +00:00

Start to determine post access level

This commit is contained in:
2020-01-03 16:38:44 +01:00
parent 8bcbcfb2b3
commit 015cf1e0d7
2 changed files with 71 additions and 2 deletions

View File

@ -1,7 +1,7 @@
import { RequestHandler } from "../entities/RequestHandler";
import { UserHelper } from "../helpers/UserHelper";
import { PostsHelper } from "../helpers/PostsHelper";
import { Post, PostVisibilityLevel, PostKind } from "../entities/Post";
import { Post, PostVisibilityLevel, PostKind, PostAccessLevel } from "../entities/Post";
import { MoviesController } from "./MoviesController";
import { MoviesHelper } from "../helpers/MoviesHelper";
import { SurveyHelper } from "../helpers/SurveyHelper";
@ -20,6 +20,14 @@ VISIBILITY_LEVELS_API[PostVisibilityLevel.VISIBILITY_FRIENDS] = "friends";
VISIBILITY_LEVELS_API[PostVisibilityLevel.VISIBILITY_USER] = "private";
VISIBILITY_LEVELS_API[PostVisibilityLevel.VISIBILITY_GROUP_MEMBERS] = "members";
const ACCESS_LEVELS_API = {};
ACCESS_LEVELS_API[PostAccessLevel.NO_ACCESS] = "no-access";
ACCESS_LEVELS_API[PostAccessLevel.BASIC_ACCESS] = "basic";
ACCESS_LEVELS_API[PostAccessLevel.INTERMEDIATE_ACCESS] = "intermediate";
ACCESS_LEVELS_API[PostAccessLevel.FULL_ACCESS] = "full";
export class PostsController {
/**
@ -93,6 +101,11 @@ export class PostsController {
// Likes information
likes: await LikesHelper.Count(p.id, LikesType.POST),
userlike: h.signedIn ? await LikesHelper.IsLiking(h.getUserId(), p.id, LikesType.POST) : false,
// Determine user access level
user_access: ACCESS_LEVELS_API[await PostsHelper.GetAccessLevel(h.optionnalUserID, p)],
// TODO : add comments
};
return data;