fix(sync): patchItemPartial upserts new items instead of returning 404
This commit is contained in:
parent
6d5066e26a
commit
93a52c5814
1 changed files with 19 additions and 1 deletions
|
|
@ -272,7 +272,25 @@ internal class InventoryRepository {
|
|||
val exists = Items.selectAll()
|
||||
.where { (Items.id eq itemId) and (Items.inventoryId eq inventoryId) }
|
||||
.count() > 0
|
||||
if (!exists) return@transaction false
|
||||
|
||||
if (!exists) {
|
||||
// Neues Item: INSERT mit allen gelieferten Feldern, Defaults für fehlende
|
||||
Items.insert {
|
||||
it[Items.id] = itemId
|
||||
it[Items.inventoryId] = inventoryId
|
||||
it[name] = EncryptionService.encrypt(fields["name"]?.jsonPrimitive?.content ?: "")
|
||||
it[categoryId] = fields["categoryId"]?.jsonPrimitive?.intOrNull ?: 0
|
||||
it[quantity] = fields["quantity"]?.jsonPrimitive?.doubleOrNull ?: 0.0
|
||||
it[unit] = fields["unit"]?.jsonPrimitive?.content ?: ""
|
||||
it[unitPrice] = fields["unitPrice"]?.jsonPrimitive?.doubleOrNull ?: 0.0
|
||||
it[kcalPerUnit] = fields["kcalPerUnit"]?.jsonPrimitive?.intOrNull
|
||||
it[expiryDate] = fields["expiryDate"]?.jsonPrimitive?.contentOrNull
|
||||
it[locationId] = fields["locationId"]?.jsonPrimitive?.intOrNull ?: 0
|
||||
it[notes] = EncryptionService.encrypt(fields["notes"]?.jsonPrimitive?.content ?: "")
|
||||
it[lastUpdated] = fields["lastUpdated"]?.jsonPrimitive?.longOrNull ?: System.currentTimeMillis()
|
||||
}
|
||||
return@transaction true
|
||||
}
|
||||
|
||||
val hasUpdatableFields = fields.keys.any { it in updatableKeys }
|
||||
if (!hasUpdatableFields) return@transaction true
|
||||
|
|
|
|||
Loading…
Reference in a new issue