Fix position of merged attachments

This commit is contained in:
eikek
2021-08-16 15:05:26 +02:00
parent 2252acff12
commit c7c488f0cc
2 changed files with 15 additions and 7 deletions

View File

@ -81,11 +81,12 @@ object Merge {
def moveAttachments(items: NonEmptyList[Ident]): F[Int] = {
val target = items.head
for {
nextPos <- store.transact(RAttachment.nextPosition(target))
attachs <- store.transact(items.tail.traverse(id => RAttachment.findByItem(id)))
attachFlat = attachs.flatMap(_.toList)
n <- attachFlat.traverse(a =>
store.transact(RAttachment.updateItemId(a.id, target))
)
n <- attachFlat.zipWithIndex.traverse({ case (a, idx) =>
store.transact(RAttachment.updateItemId(a.id, target, nextPos + idx))
})
} yield n.sum
}