增加兑换重试链路
This commit is contained in:
@@ -111,6 +111,34 @@ export async function markInventoryItemDelivered(inventoryItemId, deliveredAt) {
|
||||
})
|
||||
}
|
||||
|
||||
export async function markInventoryItemConsumed(inventoryItemId, reason, consumedAt) {
|
||||
return withTransaction(async (client) => {
|
||||
await client.query(
|
||||
`
|
||||
UPDATE inventory_items
|
||||
SET
|
||||
status = 'consumed',
|
||||
invalid_reason = $1,
|
||||
consumed_at = $2,
|
||||
updated_at = $2
|
||||
WHERE id = $3
|
||||
`,
|
||||
[String(reason || '').trim(), consumedAt, Number(inventoryItemId)],
|
||||
)
|
||||
|
||||
await client.query(
|
||||
`
|
||||
UPDATE task_inventory_bindings
|
||||
SET binding_status = 'consumed', consumed_at = $1, updated_at = $1
|
||||
WHERE inventory_item_id = $2 AND binding_status = 'reserved'
|
||||
`,
|
||||
[consumedAt, Number(inventoryItemId)],
|
||||
)
|
||||
|
||||
return getInventoryItemById(inventoryItemId)
|
||||
})
|
||||
}
|
||||
|
||||
export async function listInventoryItems({
|
||||
page = 1,
|
||||
pageSize = 20,
|
||||
@@ -249,3 +277,27 @@ export async function invalidateInventoryItem(inventoryItemId, invalidReason, up
|
||||
|
||||
return getInventoryItemById(inventoryItemId)
|
||||
}
|
||||
|
||||
export async function invalidateReservedInventoryItem(inventoryItemId, invalidReason, updatedAt) {
|
||||
return withTransaction(async (client) => {
|
||||
await client.query(
|
||||
`
|
||||
UPDATE task_inventory_bindings
|
||||
SET binding_status = 'released', released_at = $1, updated_at = $1
|
||||
WHERE inventory_item_id = $2 AND binding_status = 'reserved'
|
||||
`,
|
||||
[updatedAt, Number(inventoryItemId)],
|
||||
)
|
||||
|
||||
await client.query(
|
||||
`
|
||||
UPDATE inventory_items
|
||||
SET status = 'invalid', invalid_reason = $1, updated_at = $2
|
||||
WHERE id = $3
|
||||
`,
|
||||
[String(invalidReason || '').trim(), updatedAt, Number(inventoryItemId)],
|
||||
)
|
||||
|
||||
return getInventoryItemById(inventoryItemId)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -35,7 +35,13 @@ const TASK_JOINS = `
|
||||
FROM task_inventory_bindings tib
|
||||
JOIN inventory_items ii ON ii.id = tib.inventory_item_id
|
||||
WHERE tib.task_id = ft.id AND tib.binding_status IN ('reserved', 'consumed')
|
||||
ORDER BY tib.id ASC
|
||||
ORDER BY
|
||||
CASE tib.binding_status
|
||||
WHEN 'reserved' THEN 0
|
||||
WHEN 'consumed' THEN 1
|
||||
ELSE 2
|
||||
END ASC,
|
||||
tib.id DESC
|
||||
LIMIT 1
|
||||
) inv ON TRUE
|
||||
`
|
||||
|
||||
Reference in New Issue
Block a user