Skip to content

73 calorie counting#83

Open
m-lyon wants to merge 18 commits intomainfrom
73-calorie-counting
Open

73 calorie counting#83
m-lyon wants to merge 18 commits intomainfrom
73-calorie-counting

Conversation

@m-lyon
Copy link
Copy Markdown
Owner

@m-lyon m-lyon commented Mar 30, 2026

No description provided.

m-lyon added 18 commits March 29, 2026 23:12
…QL schema

- Add NutritionalInfo Mongoose model with MacroNutrients sub-schema (perGram/perUnit)
- Add measureType field to Unit model (mass | volume)
- Create NutritionalInfo GraphQL schema with CRUD resolvers and ingredient-owner auth
- Add nutritionalInfosByIngredientIds batch query resolver
- Register NutritionalInfo queries/mutations in schema index
- Add USDA_API_KEY and EMAIL_FROM to constants and environment types
- Add explicit auth check in assertIngredientOwnerOrAdmin before ownership comparison
- Add not-found checks in updateById/removeById to return clear NOT_FOUND errors
  instead of misleading NOT_AUTHORIZED when document is absent
- Protect nutritionalInfoByIngredient query with auth guard (was unauthenticated)
- Remove redundant removeFields:[] option from NutritionalInfoCreateTC
- Create api/src/schema/Usda.ts with usdaSearch and usdaFoodItem queries
- Proxy calls to USDA FDC API server-side to keep API key out of client bundle
- Map USDA nutrient IDs (energy=1008, protein=1003, carbs=1005, fat=1004) to typed fields
- Return HTTP error details on USDA API failures
- Require authentication on both queries
- Register UsdaQuery in schema index
- Pass API key as X-Api-Key header instead of URL query param to prevent key exposure in logs
- Add AbortController with 10s timeout to prevent indefinite hang on USDA API
- Cap pageSize at 200 to prevent oversized responses
- Guard usdaFoodItem against empty/missing fdcId in response body
- Create api/src/utils/nutritionalNotifications.ts that checks all recipe
  ingredients for calculability after save and batches email notifications
- Group missing-data alerts by owner (ingredient owner / unit owner separately)
  so each owner gets exactly one email per recipe save
- Use passport-local-mongoose username field as recipient email address
- Add post('save') hook to Recipe schema that calls sendNutritionalNotifications;
  failures are caught and logged so they never fail the save response
- Replace N+1 NutritionalInfo queries with single batch $in query
- Fan out User.findById + sendEmail calls concurrently with Promise.all
- Clone recipe document before populate() to avoid mutating saved ObjectId refs
- Remove incorrect unitOwnerId from perGram-missing case (ingredient owner's responsibility)
- Add guard against dangling/unpopulated ingredient refs
- Add EMAIL_FROM guard to skip notifications gracefully when not configured
…ional info

- Add measureType to UNIT_FIELDS fragment (used by nutrition calc pipeline)
- Add density to Ingredient inline selection in RECIPE_FIELDS_FULL
- Add GET_NUTRITIONAL_INFO_BY_INGREDIENT, GET_NUTRITIONAL_INFOS_BY_INGREDIENT_IDS, and USDA_SEARCH queries
- Add CREATE/UPDATE/DELETE_NUTRITIONAL_INFO mutations
- Fix ApolloServerErrorCode.FORBIDDEN (not in this Apollo version) → string literal 'FORBIDDEN'
- Fix args type casts in Usda resolver (args typed as unknown in graphql-compose)
- Use UNAUTHENTICATED error code (not FORBIDDEN) for unauthenticated requests
- Add runtime type guard for args.query in usdaSearch resolver
- Add usdaFdcId to GET_NUTRITIONAL_INFOS_BY_INGREDIENT_IDS for shape consistency
- Pure functions: quantityToFloat, calculateIngredientNutrition, sumRecipeNutrition
- Supports mass/volume/countable pipelines with correct UnitConversion lookup
- Add measureType: null to all Unit mocks (required now that UNIT_FIELDS includes it)
…OS on all non-calculable returns to prevent mutation, and add comprehensive unit tests
…e view - NutritionalInfoPanel, useNutritionalInfo hook, uncounted ingredient highlighting in IngredientList
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant