From bebebe6508a3d91926e289c3fbada19982c260cf Mon Sep 17 00:00:00 2001 From: SrGooglo Date: Sun, 10 Nov 2024 20:39:40 +0000 Subject: [PATCH] improve attachments controls --- .../posts/classes/posts/methods/create.js | 18 ++++++++++-------- .../posts/classes/posts/methods/fullfill.js | 4 +++- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/packages/server/services/posts/classes/posts/methods/create.js b/packages/server/services/posts/classes/posts/methods/create.js index 0b235a92..63041acd 100644 --- a/packages/server/services/posts/classes/posts/methods/create.js +++ b/packages/server/services/posts/classes/posts/methods/create.js @@ -16,16 +16,18 @@ export default async (payload = {}) => { throw new OperationError(400, "Cannot create a post without message or attachments") } - // fix attachments with url strings - attachments = attachments.map((attachment) => { - if (typeof attachment === "string") { - attachment = { - url: attachment, + if (isAttachmentArray) { + // fix attachments with url strings if needed + attachments = attachments.map((attachment) => { + if (typeof attachment === "string") { + attachment = { + url: attachment, + } } - } - return attachment - }) + return attachment + }) + } if (!timestamp) { timestamp = DateTime.local().toISO() diff --git a/packages/server/services/posts/classes/posts/methods/fullfill.js b/packages/server/services/posts/classes/posts/methods/fullfill.js index 309428ba..92f37000 100644 --- a/packages/server/services/posts/classes/posts/methods/fullfill.js +++ b/packages/server/services/posts/classes/posts/methods/fullfill.js @@ -77,7 +77,9 @@ export default async (payload = {}) => { const replyUserData = await User.findById(post.reply_to_data.user_id) - post.reply_to_data.user = replyUserData.toObject() + if (replyUserData) { + post.reply_to_data.user = replyUserData.toObject() + } } }