1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2024-11-25 23:09:22 +00:00

Can update post content

This commit is contained in:
Pierre HUBERT 2020-03-20 18:41:32 +01:00
parent 9f22f2df56
commit 627600685d
4 changed files with 42 additions and 1 deletions

View File

@ -310,9 +310,30 @@ export class PostsController {
await PostsHelper.SetLevel(postID, newVisibility); await PostsHelper.SetLevel(postID, newVisibility);
// TODO : depending on new level, delete (or not) notifications about the post
h.success(""); h.success("");
} }
/**
* Update the content of a post
*
* @param h Request handler
*/
public static async UpdateContent(h: RequestHandler) {
const postID = await h.postPostIDWithAccess("postID", PostAccessLevel.FULL_ACCESS);
const content = h.postContent("new_content");
if(!check_string_before_insert(content))
h.error(401, "Given content is invalid!");
await PostsHelper.SetContent(postID, content);
// TODO : delete notifications targetting current user about the post
h.success();
}
/** /**
* Send multiple posts to the API * Send multiple posts to the API
* *

View File

@ -196,6 +196,8 @@ export const Routes : Route[] = [
{path: "/posts/set_visibility_level", cb: (h) => PostsController.SetVisibilityLevel(h)}, {path: "/posts/set_visibility_level", cb: (h) => PostsController.SetVisibilityLevel(h)},
{path: "/posts/update_content", cb: (h) => PostsController.UpdateContent(h)},
// Notifications controller // Notifications controller

View File

@ -572,7 +572,7 @@ export class RequestHandler {
* *
* @param message Message associated to success * @param message Message associated to success
*/ */
public success(message: string) { public success(message: string = "") {
this.responseSent = true; this.responseSent = true;

View File

@ -460,6 +460,24 @@ export class PostsHelper {
}) })
} }
/**
* Set new content to the post
*
* @param postID Target post ID
* @param content Target content
*/
public static async SetContent(postID: number, content: string) {
await DatabaseHelper.UpdateRows({
table: TABLE_NAME,
where: {
ID: postID
},
set: {
texte: content
}
})
}
/** /**
* Turn a database entry into a row object * Turn a database entry into a row object
* *