back to Mongo Atlas | price -> prices

This commit is contained in:
2020-11-07 11:23:23 +01:00
parent 05f9e17d64
commit 18f3dd3fdb
4 changed files with 33 additions and 22 deletions

View File

@@ -64,7 +64,9 @@
- ##### **restaurantId**: _mongoose.Types.ObjectId_ - ##### **restaurantId**: _mongoose.Types.ObjectId_
- ##### **name**: _String_ (max: 128, required) - ##### **name**: _String_ (max: 128, required)
- ##### **category**: _String_ (max: 64, required) - ##### **category**: _String_ (max: 64, required)
- ##### **price**: String (required) - ##### **prices**: (max elements 3)
- ##### **priceName**: _String_ (required)
- ##### **price**: _String_ (required)
- ##### **notes**: _String_ (max: 128) - ##### **notes**: _String_ (max: 128)
- ##### **imgUrl**: _String_ (required) - ##### **imgUrl**: _String_ (required)
- ##### **hidden**: _Boolean_ - ##### **hidden**: _Boolean_

View File

@@ -1,29 +1,18 @@
const mongoose = require("mongoose"); const mongoose = require("mongoose");
const { const {
dbPass, dbPass,
dbUser, /* dbUser,
dbHost, dbHost,
dbPort, dbPort, */
dbName, dbName,
} = require("../config/index.js"); } = require("../config/index.js");
const loadMongoose = async () => { const loadMongoose = async () => {
const connection = await mongoose.connect( const connection = await mongoose.connect(
"mongodb://" + `mongodb+srv://menui_db_user:${dbPass}@menui-database.9quwf.mongodb.net/${dbName}?retryWrites=true&w=majority`,
dbHost +
":" +
dbPort +
"/" +
dbName +
"?ssl=true&replicaSet=globaldb",
{ {
auth: {
user: dbUser,
password: dbPass,
},
useNewUrlParser: true, useNewUrlParser: true,
useUnifiedTopology: true, useUnifiedTopology: true,
retryWrites: false,
}, },
(err) => { (err) => {
if (err) console.log("Unable to connect :("); if (err) console.log("Unable to connect :(");
@@ -33,3 +22,13 @@ const loadMongoose = async () => {
}; };
module.exports = loadMongoose; module.exports = loadMongoose;
// AZURE
/* "mongodb://" +
dbHost +
":" +
dbPort +
"/" +
dbName +
"?ssl=true&replicaSet=globaldb", */

View File

@@ -13,10 +13,20 @@ const dishSchema = mongoose.Schema({
maxlength: 64, maxlength: 64,
required: true, required: true,
}, },
prices: [
{
priceName: {
type: String,
maxlength: 60,
required: true
},
price: { price: {
type: String, type: String,
required: true, maxlength: 20,
required: true
}
}, },
],
notes: { notes: {
type: String, type: String,
maxlength: 200, maxlength: 200,

View File

@@ -131,7 +131,7 @@ async function createDish(dish, restaurantId, oldDish) {
restaurantId: restaurantId, restaurantId: restaurantId,
name: sanitizer.sanitize.keepUnicode(dish.name), name: sanitizer.sanitize.keepUnicode(dish.name),
category: dish.category, category: dish.category,
price: dish.price, prices: dish.prices,
notes: sanitizer.sanitize.keepUnicode(dish.notes), notes: sanitizer.sanitize.keepUnicode(dish.notes),
imgUrl: img, imgUrl: img,
weight: dish.weight, weight: dish.weight,
@@ -149,7 +149,7 @@ async function createDish(dish, restaurantId, oldDish) {
restaurantId: oldDish.restaurantId, restaurantId: oldDish.restaurantId,
name: sanitizer.sanitize.keepUnicode(dish.name), name: sanitizer.sanitize.keepUnicode(dish.name),
category: dish.category, category: dish.category,
price: dish.price, prices: dish.prices,
notes: sanitizer.sanitize.keepUnicode(dish.notes), notes: sanitizer.sanitize.keepUnicode(dish.notes),
imgUrl: img, imgUrl: img,
weight: dish.weight, weight: dish.weight,
@@ -164,7 +164,7 @@ async function createDish(dish, restaurantId, oldDish) {
} }
} catch (e) { } catch (e) {
console.log(e); console.log(e);
throw newError("Cannot create dish", 500); throw newError("Cannot create dish because: " + e, 500);
} }
} }