Commit Graph
12 Commits
Author SHA1 Message Date
Andy Low 69b620dd2f Harden MongoDB driver compatibility 2026-04-19 23:24:22 +01:00
Ben WestandCopilot c6c60af906 Add array input tests for food API
- Add tests for POST with array of foods
- Add tests for PUT with array of foods
- Add test for empty array returning empty array
- Fix PUT endpoint to normalize array input like POST
- Fix food.save() storage to handle arrays with bulkWrite
- Rename test file to follow *.test.js convention

Validates fix from ef7bff3d for complete array handling.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-18 15:58:50 -07:00
Ben WestandCopilot ef7bff3d53 fix(food): add array support to food API POST
Add array normalization to food API POST endpoint:
- API layer: normalize single object to array (like activity/profile)
- Storage layer: use replaceOne loop with upsert (same as activity pattern)
- Storage layer: accept both single object and array for backward compat

Previously POST /api/food/ with array input would crash:
  insertOne([{...}]) → MongoDB error

Now supports both single object and array input consistently.
Response format is now array (matching treatments pattern).

Fixes #8447

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-18 14:06:16 -07:00
Ben WestandCopilot 808b923e8e feat(api): add _id validation to activity and food APIs
Add validation for _id field in activity and food APIs:
- activity: POST, PUT, DELETE now validate _id format
- food: POST, PUT, DELETE now validate _id format

Accepts: undefined, null, or 24-character hex string
Rejects: UUIDs, short strings, numbers, objects with 400 Bad Request

Previously:
- activity: 500 crash on invalid _id in save/remove
- food: silently replaced invalid _id with new ObjectId (data loss)

Tests added covering all validation cases.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-18 11:05:40 -07:00
Ben West 2e65b1dd9b Revert "Merge pull request #8026 from nightscout/less_frequent_db_updates"
This reverts commit 2757fe585d, reversing
changes made to 4a461e5890.
2023-10-19 13:03:38 -07:00
Sulka Haro 32163a0cd1 * Fix storage so tests pass with new Mongo driver
* Removes old openaps-storage feature
2023-06-01 22:45:07 +03:00
Ben West 41fdb8e88f respect per route body-parser configuration
This change allows each route to express policies for interpreting and parsing
the request body.  Before this change uploads to entries or treatments api
would error if they were larger than 100Kb due to the preference being set for
the whole server.  This change removes the global preference in favor of
allowing each route to choose it's own request size limit.

We also refactor usage of body-parser to be more consistent throughout the code
base.  Most routes can use jsonParser, rawPraser, and urlencodedParser provided
by the common wares component.  Anything doing something else should be called
out as such.  For example, treatments, activity, and entries allow uploads up
to 50Mb.  Other v1 endpoints are using the common configuration set to 1Mb.
2021-10-12 22:57:03 -07:00
Sulka Haro ebb58141cd Fix json decoding for some api endpoints 2021-02-09 12:52:23 +02:00
Ben West 0f735d0af5 implement read-access against token, mod default
Could see an endpoint changing the global server variable, `defaultRoles` as well.
Seems to work well to disable/enable access really quickly.
2016-08-04 15:40:02 -07:00
Jason Calabrese 3d88bd33a6 replace old wares.verifyAuthorization with ctx.authorization.isPermitted; some refactoring 2016-07-31 20:10:10 -07:00
MilosKozak 9d42964a94 fixing bugs 2015-10-28 12:00:20 +01:00
MilosKozak 51363c6ab0 extracted needed files 2015-10-28 12:00:14 +01:00