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_
- ##### **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_

View File

@@ -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", */

View File

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

View File

@@ -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);
}
}