mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-04 06:05:59 +00:00
Fix deleting items that have sent mails
This commit is contained in:
parent
14213c4c27
commit
64c96942a9
@ -448,10 +448,11 @@ object QItem {
|
||||
|
||||
def delete[F[_]: Sync](store: Store[F])(itemId: Ident, collective: Ident): F[Int] =
|
||||
for {
|
||||
tn <- store.transact(RTagItem.deleteItemTags(itemId))
|
||||
rn <- QAttachment.deleteItemAttachments(store)(itemId, collective)
|
||||
tn <- store.transact(RTagItem.deleteItemTags(itemId))
|
||||
mn <- store.transact(RSentMail.deleteByItem(itemId))
|
||||
n <- store.transact(RItem.deleteByIdAndCollective(itemId, collective))
|
||||
} yield tn + rn + n
|
||||
} yield tn + rn + n + mn
|
||||
|
||||
def findByFileIds(fileMetaIds: Seq[Ident]): ConnectionIO[Vector[RItem]] = {
|
||||
val IC = RItem.Columns
|
||||
|
@ -3,6 +3,7 @@ package docspell.store.records
|
||||
import fs2.Stream
|
||||
import cats.effect._
|
||||
import cats.implicits._
|
||||
import cats.data.NonEmptyList
|
||||
import doobie._
|
||||
import doobie.implicits._
|
||||
import docspell.common._
|
||||
@ -115,4 +116,15 @@ object RSentMail {
|
||||
|
||||
def delete(mailId: Ident): ConnectionIO[Int] =
|
||||
deleteFrom(table, id.is(mailId)).update.run
|
||||
|
||||
def deleteByItem(item: Ident): ConnectionIO[Int] =
|
||||
for {
|
||||
list <- RSentMailItem.findSentMailIdsByItem(item)
|
||||
n1 <- RSentMailItem.deleteAllByItem(item)
|
||||
n0 <- NonEmptyList.fromList(list.toList) match {
|
||||
case Some(nel) => deleteFrom(table, id.isIn(nel)).update.run
|
||||
case None => 0.pure[ConnectionIO]
|
||||
}
|
||||
} yield n0 + n1
|
||||
|
||||
}
|
||||
|
@ -54,4 +54,10 @@ object RSentMailItem {
|
||||
|
||||
def deleteMail(mailId: Ident): ConnectionIO[Int] =
|
||||
deleteFrom(table, sentMailId.is(mailId)).update.run
|
||||
|
||||
def findSentMailIdsByItem(item: Ident): ConnectionIO[Set[Ident]] =
|
||||
selectSimple(Seq(sentMailId), table, itemId.is(item)).query[Ident].to[Set]
|
||||
|
||||
def deleteAllByItem(item: Ident): ConnectionIO[Int] =
|
||||
deleteFrom(table, itemId.is(item)).update.run
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user