Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

71 changes: 71 additions & 0 deletions src/controllers/kitchenRecipeController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
const kitchenRecipeController = function (KitchenRecipe) {
const getRecipes = function (req, res) {
KitchenRecipe.find()
.then((recipes) => {
res.status(200).send(recipes);
})
.catch((error) => {
res.status(500).send({ message: error.message || 'Error fetching recipes' });
});
};

const getRecipeById = function (req, res) {
const { recipeId } = req.params;
KitchenRecipe.findById(recipeId)
.then((recipe) => {
if (!recipe) {
return res.status(404).send({ message: 'Recipe not found' });
}
return res.status(200).send(recipe);
})
.catch((error) => {
res.status(500).send({ message: error.message || 'Error fetching recipe' });
});
};

const substituteIngredient = function (req, res) {
const { recipeId } = req.params;
const { ingredientId, substituteName, quantity } = req.body;

if (!ingredientId || !substituteName || !quantity) {
return res.status(400).send({
message: 'ingredientId, substituteName, and quantity are required',
});
}

return KitchenRecipe.findById(recipeId)
.then((recipe) => {
if (!recipe) {
return res.status(404).send({ message: 'Recipe not found' });
}

const ingredient = recipe.ingredients.id(ingredientId);
if (!ingredient) {
return res.status(404).send({ message: 'Ingredient not found in recipe' });
}

ingredient.name = substituteName;
ingredient.quantity = quantity;
ingredient.isAvailable = true;
recipe.updatedAt = Date.now();

return recipe.save().then((updatedRecipe) => {
res.status(200).send({
message: 'Ingredient substituted',
recipe: updatedRecipe,
});
});
})
.catch((error) => {
res.status(500).send({ message: error.message || 'Error substituting ingredient' });
});
};

return {
getRecipes,
getRecipeById,
substituteIngredient,
};
};

module.exports = kitchenRecipeController;
29 changes: 29 additions & 0 deletions src/models/kitchenRecipe.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const mongoose = require('mongoose');

const { Schema } = mongoose;

const ingredientSchema = new Schema({
name: { type: String, required: true },
quantity: { type: String, required: true },
isOnsite: { type: Boolean, default: false },
isAvailable: { type: Boolean, default: true },
});

const kitchenRecipeSchema = new Schema({
name: { type: String, required: true },
type: { type: String, required: true },
description: { type: String },
prepTime: { type: Number },
servings: { type: Number },
difficulty: { type: String, enum: ['Easy', 'Medium', 'Hard'] },
tags: [{ type: String }],
hasPriorityIngredients: { type: Boolean, default: false },
onsitePercentage: { type: Number, default: 0 },
ingredients: [ingredientSchema],
instructions: [{ type: String }],
createdBy: { type: Schema.Types.ObjectId, ref: 'userProfile' },
createdAt: { type: Date, default: Date.now },
updatedAt: { type: Date, default: Date.now },
});

module.exports = mongoose.model('kitchenRecipe', kitchenRecipeSchema, 'kitchenRecipes');
18 changes: 18 additions & 0 deletions src/routes/kitchenRecipeRouter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const express = require('express');

const routes = function (KitchenRecipe) {
const controller = require('../controllers/kitchenRecipeController')(KitchenRecipe);
const kitchenRecipeRouter = express.Router();

kitchenRecipeRouter.route('/kitchenandinventory/recipes').get(controller.getRecipes);

kitchenRecipeRouter.route('/kitchenandinventory/recipes/:recipeId').get(controller.getRecipeById);

kitchenRecipeRouter
.route('/kitchenandinventory/recipes/:recipeId/substitute')
.put(controller.substituteIngredient);

return kitchenRecipeRouter;
};

module.exports = routes;
8 changes: 7 additions & 1 deletion src/startup/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,10 @@ const summaryDashboardRouter = require('../routes/summaryDashboard.routes');
// Actual Cost
const actualCostRouter = require('../routes/actualCostRouter')();

// Kitchen and Inventory
const kitchenRecipe = require('../models/kitchenRecipe');
const kitchenRecipeRouter = require('../routes/kitchenRecipeRouter')(kitchenRecipe);

module.exports = function (app) {
app.use('/api/bm/summary-dashboard', summaryDashboardRouter);
app.use('/api', forgotPwdRouter);
Expand Down Expand Up @@ -496,7 +500,6 @@ module.exports = function (app) {
app.use('/api', toolUtilizationRouter);
// lb dashboard


app.use('/api', toolAvailabilityRouter);
app.use('/api', projectCostTrackingRouter);

Expand Down Expand Up @@ -563,4 +566,7 @@ module.exports = function (app) {
app.use('/api', materialCostRouter);

app.use('/api/lp', lessonPlanSubmissionRouter);

// Kitchen and Inventory
app.use('/api', kitchenRecipeRouter);
};