1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2025-06-21 00:55:17 +00:00

Get basic post information

This commit is contained in:
2020-01-04 15:25:26 +01:00
parent ac601877bb
commit a726ba4230
2 changed files with 47 additions and 2 deletions

View File

@ -11,6 +11,8 @@ import { CommentsHelper } from "../helpers/CommentsHelper";
import { CommentsController } from "./CommentsController";
import { GroupsAccessLevel } from "../entities/Group";
import { GroupsHelper } from "../helpers/GroupsHelper";
import { time } from "../utils/DateUtils";
import { findKey } from "../utils/ArrayUtils";
/**
* Posts controller
@ -130,10 +132,26 @@ export class PostsController {
}
// Initialize new post information
const newPost = new Post({
// Basic information about the post
id: -1,
userID: h.getUserId(),
timeCreate: time(),
kind: <PostKind>h.postString("kind"),
content: h.postContent("content"),
visibilityLevel: this.PostVisibilityLevel(h, "visibility"),
// Post target
kindPage: kindPage,
pageID: pageID,
});
console.info(newPost);
h.success("Go on.");
}
/**
* Send multiple posts to the API
*
@ -208,4 +226,17 @@ export class PostsController {
return data;
}
/**
* Get the visibility level for a POST included in a request
*
* @param h Request handler
* @param name The name of the POST field containing the visibility level of the user
*/
private static PostVisibilityLevel(h: RequestHandler, name: string) : PostVisibilityLevel {
const levelKey = findKey(VISIBILITY_LEVELS_API, h.postString(name, 3));
if(levelKey == null)
h.error(400, "Post visibility level level not recognized!");
return <PostVisibilityLevel>Number(levelKey);
}
}