1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2025-06-20 08:35:17 +00:00

Can create text posts

This commit is contained in:
2020-01-04 17:06:43 +01:00
parent a726ba4230
commit 037916e7eb
4 changed files with 127 additions and 5 deletions

View File

@ -13,6 +13,7 @@ import { GroupsAccessLevel } from "../entities/Group";
import { GroupsHelper } from "../helpers/GroupsHelper";
import { time } from "../utils/DateUtils";
import { findKey } from "../utils/ArrayUtils";
import { check_string_before_insert } from "../utils/StringUtils";
/**
* Posts controller
@ -139,7 +140,7 @@ export class PostsController {
userID: h.getUserId(),
timeCreate: time(),
kind: <PostKind>h.postString("kind"),
content: h.postContent("content"),
content: h.postContent("content", 0),
visibilityLevel: this.PostVisibilityLevel(h, "visibility"),
// Post target
@ -148,8 +149,31 @@ export class PostsController {
});
console.info(newPost);
h.success("Go on.");
// Process each kind of post
switch(newPost.kind) {
// Text posts
case PostKind.POST_KIND_TEXT:
// Check the string
if(!check_string_before_insert(newPost.content))
h.error(400, "Specified post content is invalid!");
break;
default:
h.error(500, "Unsupported kind of post!");
}
// Create the post
const postID = await PostsHelper.Create(newPost);
// TODO : create a notification
h.send({
success: "The post has been created!",
postID: postID
});
}
/**