Add paycheck-centric main view
Two-column monthly view showing bills, amounts, paid status, and remaining balance per paycheck. Month navigation included. Also adds PATCH /api/paycheck-bills/:id/paid endpoint. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -232,4 +232,37 @@ router.get('/paychecks/months', async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// PATCH /api/paycheck-bills/:id/paid
|
||||
router.patch('/paycheck-bills/:id/paid', async (req, res) => {
|
||||
const id = parseInt(req.params.id, 10);
|
||||
if (isNaN(id)) {
|
||||
return res.status(400).json({ error: 'Invalid id' });
|
||||
}
|
||||
|
||||
const { paid } = req.body;
|
||||
if (typeof paid !== 'boolean') {
|
||||
return res.status(400).json({ error: 'paid must be a boolean' });
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await pool.query(
|
||||
`UPDATE paycheck_bills
|
||||
SET paid = $1,
|
||||
paid_at = CASE WHEN $1 THEN NOW() ELSE NULL END
|
||||
WHERE id = $2
|
||||
RETURNING id, paid, paid_at`,
|
||||
[paid, id]
|
||||
);
|
||||
|
||||
if (result.rows.length === 0) {
|
||||
return res.status(404).json({ error: 'paycheck_bill not found' });
|
||||
}
|
||||
|
||||
res.json(result.rows[0]);
|
||||
} catch (err) {
|
||||
console.error('PATCH /api/paycheck-bills/:id/paid error:', err);
|
||||
res.status(500).json({ error: 'Failed to update paid status' });
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
||||
Reference in New Issue
Block a user