|
|
@@ -2,6 +2,7 @@ const axios = require("axios");
|
|
|
|
|
|
const Merchant = require("../models/merchant");
|
|
|
const Ingredient = require("../models/ingredient");
|
|
|
+const Recipe = require("../models/recipe");
|
|
|
|
|
|
const merchantId = "HCVKASXH94531";
|
|
|
const token = "f1c88a69-e3e4-059a-da06-8858d0636e82";
|
|
|
@@ -28,6 +29,7 @@ module.exports = {
|
|
|
.then((ingredients)=>{
|
|
|
axios.get(`https://apisandbox.dev.clover.com/v3/merchants/${merchantId}/items?access_token=${token}`)
|
|
|
.then((recipes)=>{
|
|
|
+ console.log(recipes);
|
|
|
return res.render("merchantSetupPage/merchantSetup", {ingredients: ingredients, recipes: recipes.data});
|
|
|
})
|
|
|
.catch((err)=>{
|
|
|
@@ -50,5 +52,59 @@ module.exports = {
|
|
|
.catch((err)=>{
|
|
|
return res.json(err);
|
|
|
});
|
|
|
+ },
|
|
|
+
|
|
|
+ createMerchant: (req, res)=>{
|
|
|
+ let newIngredient = [];
|
|
|
+ let data = JSON.parse(req.body.data);
|
|
|
+ for(let ingredient of data.new){
|
|
|
+ newIngredient.push({
|
|
|
+ name: ingredient.name,
|
|
|
+ category: ingredient.category,
|
|
|
+ unitType: ingredient.unitType
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ Ingredient.create(newIngredient)
|
|
|
+ .then((ingredients)=>{
|
|
|
+ ingredientIds = [];
|
|
|
+ for(let i = 0; i < ingredients.length; i++){
|
|
|
+ data.existing.push({
|
|
|
+ id: ingredient[i]._id,
|
|
|
+ quantity: data.new[i].quantity
|
|
|
+ });
|
|
|
+ ingredientIds.push({
|
|
|
+ tempId: data.new[i].id,
|
|
|
+ permId: ingredients[i]._id
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ Recipe.create()
|
|
|
+ axios.get(`https://apisandbox.dev.clover.com/v3/merchants/${merchantId}?access_token=${token}`)
|
|
|
+ .then((merchant)=>{
|
|
|
+ Merchant.create({
|
|
|
+ cloverId: merchant._id,
|
|
|
+ lastUpdateTime: Date.now,
|
|
|
+ ingredients: data.existing
|
|
|
+ })
|
|
|
+ .then((merchant)=>{
|
|
|
+ console.log(merchant);
|
|
|
+ })
|
|
|
+ .catch((err)=>{
|
|
|
+ console.log(err);
|
|
|
+ return res.render("error");
|
|
|
+ });
|
|
|
+ })
|
|
|
+ .catch((err)=>{
|
|
|
+ console.log(err);
|
|
|
+ return res.render("error");
|
|
|
+ })
|
|
|
+
|
|
|
+
|
|
|
+ })
|
|
|
+ .catch((err)=>{
|
|
|
+ console.log(err);
|
|
|
+ return res.render("error");
|
|
|
+ });
|
|
|
}
|
|
|
}
|