replace file with url when sending post to client

This commit is contained in:
Guillaume Dorce 2022-09-02 10:34:50 +02:00
parent b3cdc9f518
commit 6b79e36c98
1 changed files with 4 additions and 0 deletions

View File

@ -31,6 +31,7 @@ const getAllPosts = async (): Promise<PrismaPost[]> => {
});
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<PrismaPost> => {
image: post.image,
},
});
newPost.image = newPost.image ? `/uploads/${newPost.image}` : null;
return newPost;
};
@ -72,6 +74,8 @@ const editPost = async (post: Post): Promise<PrismaPost | null | Error> => {
return null;
}
editedPost.image = editedPost.image ? `/uploads/${editedPost.image}` : null;
return editedPost;
};