From 6b79e36c9844116e67786e39b8bfde6c9d578cab Mon Sep 17 00:00:00 2001 From: Guillaume Dorce Date: Fri, 2 Sep 2022 10:34:50 +0200 Subject: [PATCH] replace file with url when sending post to client --- src/controller/PostController.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/controller/PostController.ts b/src/controller/PostController.ts index 0d42537..eba2ecd 100644 --- a/src/controller/PostController.ts +++ b/src/controller/PostController.ts @@ -31,6 +31,7 @@ const getAllPosts = async (): Promise => { }); return (await posts).map((post) => { post.author = exclude(post.author, 'password'); + post.image = post.image ? `/uploads/${post.image}` : null; return post; }); }; @@ -43,6 +44,7 @@ const createPost = async (post: Post): Promise => { image: post.image, }, }); + newPost.image = newPost.image ? `/uploads/${newPost.image}` : null; return newPost; }; @@ -72,6 +74,8 @@ const editPost = async (post: Post): Promise => { return null; } + editedPost.image = editedPost.image ? `/uploads/${editedPost.image}` : null; + return editedPost; };