From 18f3dd3fdb86634e72bf4946dd71101c8198acd7 Mon Sep 17 00:00:00 2001 From: Jonasz Bigda Date: Sat, 7 Nov 2020 11:23:23 +0100 Subject: [PATCH] back to Mongo Atlas | price -> prices --- README.md | 4 +++- loaders/mongoose.js | 27 +++++++++++++-------------- models/dish.js | 18 ++++++++++++++---- services/dataPrepServices.js | 6 +++--- 4 files changed, 33 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 55f5215..cfb201b 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,9 @@ - ##### **restaurantId**: _mongoose.Types.ObjectId_ - ##### **name**: _String_ (max: 128, required) - ##### **category**: _String_ (max: 64, required) - - ##### **price**: String (required) + - ##### **prices**: (max elements 3) + - ##### **priceName**: _String_ (required) + - ##### **price**: _String_ (required) - ##### **notes**: _String_ (max: 128) - ##### **imgUrl**: _String_ (required) - ##### **hidden**: _Boolean_ diff --git a/loaders/mongoose.js b/loaders/mongoose.js index ffb8339..33184a8 100644 --- a/loaders/mongoose.js +++ b/loaders/mongoose.js @@ -1,29 +1,18 @@ const mongoose = require("mongoose"); const { dbPass, - dbUser, +/* dbUser, dbHost, - dbPort, + dbPort, */ dbName, } = require("../config/index.js"); const loadMongoose = async () => { const connection = await mongoose.connect( - "mongodb://" + - dbHost + - ":" + - dbPort + - "/" + - dbName + - "?ssl=true&replicaSet=globaldb", + `mongodb+srv://menui_db_user:${dbPass}@menui-database.9quwf.mongodb.net/${dbName}?retryWrites=true&w=majority`, { - auth: { - user: dbUser, - password: dbPass, - }, useNewUrlParser: true, useUnifiedTopology: true, - retryWrites: false, }, (err) => { if (err) console.log("Unable to connect :("); @@ -33,3 +22,13 @@ const loadMongoose = async () => { }; module.exports = loadMongoose; + + +// AZURE +/* "mongodb://" + + dbHost + + ":" + + dbPort + + "/" + + dbName + + "?ssl=true&replicaSet=globaldb", */ \ No newline at end of file diff --git a/models/dish.js b/models/dish.js index e66c43e..c52d678 100644 --- a/models/dish.js +++ b/models/dish.js @@ -13,10 +13,20 @@ const dishSchema = mongoose.Schema({ maxlength: 64, required: true, }, - price: { - type: String, - required: true, - }, + prices: [ + { + priceName: { + type: String, + maxlength: 60, + required: true + }, + price: { + type: String, + maxlength: 20, + required: true + } + }, + ], notes: { type: String, maxlength: 200, diff --git a/services/dataPrepServices.js b/services/dataPrepServices.js index d8c8a0c..311ceb3 100644 --- a/services/dataPrepServices.js +++ b/services/dataPrepServices.js @@ -131,7 +131,7 @@ async function createDish(dish, restaurantId, oldDish) { restaurantId: restaurantId, name: sanitizer.sanitize.keepUnicode(dish.name), category: dish.category, - price: dish.price, + prices: dish.prices, notes: sanitizer.sanitize.keepUnicode(dish.notes), imgUrl: img, weight: dish.weight, @@ -149,7 +149,7 @@ async function createDish(dish, restaurantId, oldDish) { restaurantId: oldDish.restaurantId, name: sanitizer.sanitize.keepUnicode(dish.name), category: dish.category, - price: dish.price, + prices: dish.prices, notes: sanitizer.sanitize.keepUnicode(dish.notes), imgUrl: img, weight: dish.weight, @@ -164,7 +164,7 @@ async function createDish(dish, restaurantId, oldDish) { } } catch (e) { console.log(e); - throw newError("Cannot create dish", 500); + throw newError("Cannot create dish because: " + e, 500); } }