sdrgs
This commit is contained in:
@@ -60,6 +60,28 @@ router.post('/plans', async (req, res, next) => {
|
||||
} catch (e) { next(e); }
|
||||
});
|
||||
|
||||
// PUT /api/watering/plans/:id - rename/update notes
|
||||
router.put('/plans/:id', async (req, res, next) => {
|
||||
try {
|
||||
const planId = req.params.id;
|
||||
// Verify ownership
|
||||
const own = await pool.query('SELECT id FROM watering_plans WHERE id=$1 AND user_id=$2', [planId, req.user.id]);
|
||||
if (own.rows.length === 0) throw new AppError('Plan not found', 404);
|
||||
|
||||
const { name, notes } = req.body || {};
|
||||
const rs = await pool.query(
|
||||
`UPDATE watering_plans
|
||||
SET name = COALESCE($1, name),
|
||||
notes = COALESCE($2, notes),
|
||||
updated_at = NOW()
|
||||
WHERE id=$3
|
||||
RETURNING *`,
|
||||
[name, notes, planId]
|
||||
);
|
||||
res.json({ success: true, data: { plan: rs.rows[0] } });
|
||||
} catch (e) { next(e); }
|
||||
});
|
||||
|
||||
// GET /api/watering/plans/:id/points
|
||||
router.get('/plans/:id/points', async (req, res, next) => {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user