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:
Ben West
2026-03-18 10:26:16 -07:00
co-authored by Copilot
parent cbb6d06107
commit 2e81ce07e5
+11 -3
View File
@@ -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 {