Let admins unfinalise a cash up from history

Adds POST /api/cashup/:id/unfinalise (admin-only) to revert a
finalised cash up back to draft so it can be corrected, plus an
Unfinalise button in the history table for admin users.
This commit is contained in:
jtricerolph 2026-08-03 08:53:00 +00:00
parent cbabda81d5
commit 2e9b4a2ca3
2 changed files with 23 additions and 0 deletions

View file

@ -117,6 +117,19 @@ export async function cashupRoutes(app) {
return { message: 'Deleted' }
})
// POST /api/cashup/:id/unfinalise (admin only)
app.post('/api/cashup/:id/unfinalise', async (req, reply) => {
if (!req.user.is_admin) return reply.status(403).send({ error: 'Admin only' })
const { rows } = await pool.query('SELECT status FROM cash_ups WHERE id = $1', [req.params.id])
if (!rows.length) return reply.status(404).send({ error: 'Not found' })
if (rows[0].status !== 'final') return reply.status(409).send({ error: 'Not finalised' })
await pool.query(
'UPDATE cash_ups SET status=$1, submitted_at=NULL, submitted_by=NULL WHERE id=$2',
['draft', req.params.id]
)
return { message: 'Cash up reverted to draft.' }
})
// POST /api/cashup/bulk-finalize (requires cashup:finalise)
app.post('/api/cashup/bulk-finalize', async (req, reply) => {
if (!hasCap(req, 'finalise')) return reply.status(403).send({ error: 'Missing capability: finalise' })