- 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>
Replace sequential replaceOne calls with bulkWrite for batch upserts.
This improves performance when inserting multiple documents at once.
- activity.js: Use bulkWrite with replaceOne ops instead of forEach loop
- food.js: Same optimization for consistency
Both maintain exact same upsert behavior (query by _id+created_at or doc).
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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>
2018-08-04T10:25:32.244096+00:00 app[web.1]: Error: Argument passed in must be a single String of 12 bytes or a string of 24 hex characters
2018-08-04T10:25:32.244099+00:00 app[web.1]: at new ObjectID (/app/node_modules/bson/lib/bson/objectid.js:50:11)
2018-08-04T10:25:32.244101+00:00 app[web.1]: at Function.save (/app/lib/server/food.js:14:15)
2018-08-04T10:25:32.244103+00:00 app[web.1]: at /app/lib/api/food/index.js:59:18
2018-08-04T10:25:32.244105+00:00 app[web.1]: at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
2018-08-04T10:25:32.244106+00:00 app[web.1]: at next (/app/node_modules/express/lib/router/route.js:137:13)
2018-08-04T10:25:32.244107+00:00 app[web.1]: at check (/app/lib/authorization/index.js:182:9)
2018-08-04T10:25:32.244109+00:00 app[web.1]: at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
2018-08-04T10:25:32.244110+00:00 app[web.1]: at next (/app/node_modules/express/lib/router/route.js:137:13)
2018-08-04T10:25:32.244111+00:00 app[web.1]: at Route.dispatch (/app/node_modules/express/lib/router/route.js:112:3)
2018-08-04T10:25:32.244113+00:00 app[web.1]: at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
2018-08-04T10:25:32.249694+00:00 heroku[router]: at=info method=PUT path="/api/v1/food/" host=xxx.herokuapp.com request_id=yyy fwd="zzz" dyno=web.1 connect=0ms service=20ms status=500 bytes=1026 protocol=https