mirror of
https://github.com/bckelley/cgm-remote-monitor.git
synced 2026-08-24 03:14:12 -05:00
fix(devicestatus): purify each item in array input
The API layer was calling purifyObject() on the raw req.body without handling arrays. When NightscoutKit sends [status], only the outer array would be purified (no-op), not the individual status objects. Now normalizes to array and purifies each devicestatus object, matching the treatments pattern. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -67,11 +67,19 @@ function configure (app, wares, ctx, env) {
|
||||
function config_authed (app, api, wares, ctx) {
|
||||
|
||||
function doPost (req, res) {
|
||||
var obj = req.body;
|
||||
var statuses = req.body;
|
||||
|
||||
ctx.purifier.purifyObject(obj);
|
||||
// Normalize to array (NightscoutKit sends arrays)
|
||||
if (!Array.isArray(statuses)) {
|
||||
statuses = [statuses];
|
||||
}
|
||||
|
||||
// Purify each devicestatus object
|
||||
for (var i = 0; i < statuses.length; i++) {
|
||||
ctx.purifier.purifyObject(statuses[i]);
|
||||
}
|
||||
|
||||
ctx.devicestatus.create(obj, function(err, created) {
|
||||
ctx.devicestatus.create(statuses, function(err, created) {
|
||||
if (err) {
|
||||
res.sendJSONStatus(res, consts.HTTP_INTERNAL_ERROR, 'Mongo Error', err);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user