improve attachments controls

This commit is contained in:
SrGooglo 2024-11-10 20:39:40 +00:00
parent 07b3913c58
commit bebebe6508
2 changed files with 13 additions and 9 deletions

View File

@ -16,7 +16,8 @@ export default async (payload = {}) => {
throw new OperationError(400, "Cannot create a post without message or attachments")
}
// fix attachments with url strings
if (isAttachmentArray) {
// fix attachments with url strings if needed
attachments = attachments.map((attachment) => {
if (typeof attachment === "string") {
attachment = {
@ -26,6 +27,7 @@ export default async (payload = {}) => {
return attachment
})
}
if (!timestamp) {
timestamp = DateTime.local().toISO()

View File

@ -77,9 +77,11 @@ export default async (payload = {}) => {
const replyUserData = await User.findById(post.reply_to_data.user_id)
if (replyUserData) {
post.reply_to_data.user = replyUserData.toObject()
}
}
}
post.hasReplies = await Post.countDocuments({ reply_to: post._id })