Update state and proposals only on invalid items

Invalid items are those that are not ready, and not shown to the user.
When changing metadata, it should only be changed, if the item was not
already shown to the user.
This commit is contained in:
Eike Kettner
2020-05-23 15:46:24 +02:00
parent 855d4eefa8
commit 25d089da6c
6 changed files with 48 additions and 23 deletions

View File

@ -1,7 +1,8 @@
package docspell.store.records
import cats.implicits._
import cats.data.NonEmptyList
import cats.effect.Sync
import cats.implicits._
import doobie._
import doobie.implicits._
import docspell.common._
@ -110,12 +111,16 @@ object RItem {
def getCollective(itemId: Ident): ConnectionIO[Option[Ident]] =
selectSimple(List(cid), table, id.is(itemId)).query[Ident].option
def updateState(itemId: Ident, itemState: ItemState): ConnectionIO[Int] =
def updateState(
itemId: Ident,
itemState: ItemState,
existing: NonEmptyList[ItemState]
): ConnectionIO[Int] =
for {
t <- currentTime
n <- updateRow(
table,
id.is(itemId),
and(id.is(itemId), state.isIn(existing)),
commas(state.setTo(itemState), updated.setTo(t))
).update.run
} yield n