mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-12-28 14:38:52 +00:00
Can update post content
This commit is contained in:
parent
9f22f2df56
commit
627600685d
@ -310,9 +310,30 @@ export class PostsController {
|
||||
|
||||
await PostsHelper.SetLevel(postID, newVisibility);
|
||||
|
||||
// TODO : depending on new level, delete (or not) notifications about the post
|
||||
|
||||
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
|
||||
*
|
||||
|
@ -196,6 +196,8 @@ export const Routes : Route[] = [
|
||||
|
||||
{path: "/posts/set_visibility_level", cb: (h) => PostsController.SetVisibilityLevel(h)},
|
||||
|
||||
{path: "/posts/update_content", cb: (h) => PostsController.UpdateContent(h)},
|
||||
|
||||
|
||||
|
||||
// Notifications controller
|
||||
|
@ -572,7 +572,7 @@ export class RequestHandler {
|
||||
*
|
||||
* @param message Message associated to success
|
||||
*/
|
||||
public success(message: string) {
|
||||
public success(message: string = "") {
|
||||
|
||||
this.responseSent = true;
|
||||
|
||||
|
@ -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
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user