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:
@ -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
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user