Merge branch 'main' into fix/otel-metrics-and-monitoring-dashboards
Run Tests on Branches / Detect Changes (push) Successful in 14s
Run Tests on Branches / PIP Platform Tests (push) Has been skipped
Run Tests on Branches / Backend Tests (push) Successful in 1m46s
Run Tests on Branches / Frontend Tests (push) Has been skipped
Run Tests on Branches / Frontend Mobile Tests (push) Has been skipped
Run Tests on Branches / Parapharmacy API Tests (push) Has been skipped

This commit is contained in:
2026-07-21 12:30:53 +00:00
+16
View File
@@ -2055,6 +2055,12 @@ app.put('/api/admin/pharmacy-medicines/:id', requireAdmin, async (req, res) => {
const id = parseInt(req.params.id); const id = parseInt(req.params.id);
const { price, stock } = req.body; const { price, stock } = req.body;
// Get current state before update to detect stock becoming available
const current = await userDbGet(
'SELECT * FROM pharmacy_medicines WHERE id = ?',
[id]
);
await userDbRun( await userDbRun(
'UPDATE pharmacy_medicines SET price = ?, stock = ? WHERE id = ?', 'UPDATE pharmacy_medicines SET price = ?, stock = ? WHERE id = ?',
[price || null, stock || 0, id] [price || null, stock || 0, id]
@@ -2069,6 +2075,16 @@ app.put('/api/admin/pharmacy-medicines/:id', requireAdmin, async (req, res) => {
return res.status(404).json({ error: 'Relationship not found' }); return res.status(404).json({ error: 'Relationship not found' });
} }
// Send push if stock went from 0 to available
if (current && (current.stock || 0) === 0 && (stock || 0) > 0) {
const pharmacy = await userDbGet('SELECT id, name FROM pharmacies WHERE id = ?', [updated.pharmacy_id]);
sendPushForMedicine({
medicine_nregistro: updated.medicine_nregistro,
medicine_name: updated.medicine_name,
pharmacy,
}).catch(err => console.error('[push] stock-change fanout error:', err));
}
res.json(updated); res.json(updated);
appMetrics.pharmacyMedicineLinkTotal.add(1, { op: 'update' }); appMetrics.pharmacyMedicineLinkTotal.add(1, { op: 'update' });
} catch (error) { } catch (error) {