From 0aca077f6e12438b45b1a478885c4e3645fc6f2e Mon Sep 17 00:00:00 2001 From: PieLord757 Date: Sat, 14 Sep 2024 22:11:20 -0400 Subject: [PATCH] Pretty much cloned users.js in the api folder and made it recipes.js --- server/api/recipes.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 server/api/recipes.js diff --git a/server/api/recipes.js b/server/api/recipes.js new file mode 100644 index 0000000..6e50d71 --- /dev/null +++ b/server/api/recipes.js @@ -0,0 +1,35 @@ +import APIRoute from "../APIRoute.js"; + +export default class UsersAPI extends APIRoute { + constructor() { + super('/recipes'); + + this.addSubRoute('/create', 'post', createRecipe); + } + + async get(req, res) { + res.send('GET request'); + } + + async post(req, res) { + res.send('POST request'); + } + + async createRecipe(req, res) { + let recipe = req.body; + + let db = req.app.get('mongo').recipes; + + let result = await db.create({ + userID: recipe.userID, + ingredients: recipe.ingredients, + productName: recipe.productName, + nutritionFacts: recipe.nutritionFacts, + rating: recipe.rating, + cuisine: recipe.cuisine, + expense: recipe.expense, + mealType: recipe.mealType + }); + + } +} \ No newline at end of file