server v1.0.6

This commit is contained in:
2020-09-30 21:58:26 +02:00
parent 153a1e0fd2
commit 5d6c7d5e3f
5 changed files with 29 additions and 16 deletions

View File

@@ -48,9 +48,15 @@
- ##### **subscriptionStarted**: _String_ - ##### **subscriptionStarted**: _String_
- ##### **subscriptionDue**: _String_ - ##### **subscriptionDue**: _String_
- ##### **categories**: [String] - ##### **categories**: [String]
- ##### **lunchMenu**: [*mongoose.Types.ObjectId*]
- ##### **dishes**: [*mongoose.Types.ObjectId*] - ##### **lunchHours**: String
<br> - ##### **lunchMenu**:
- ##### **lunchSetName**: _String_
- ##### **lunchSetPrice**: _String_
- ##### **lunchSetDishes**: [mongoose.Types.ObjectId]
- ##### **dishes**: [*mongoose.Types.ObjectId*]
<br>
- ### **Dish** - ### **Dish**
@@ -58,11 +64,11 @@
- ##### **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**: _Number_ (required) - ##### **price**: String (required)
- ##### **notes**: _String_ (max: 128) - ##### **notes**: _String_ (max: 128)
- ##### **imgUrl**: _String_ (required) - ##### **imgUrl**: _String_ (required)
- ##### **hidden**: _Boolean_ - ##### **hidden**: _Boolean_
- ##### **weight**: _Number_ - ##### **weight**: String
- ##### **allergens** - ##### **allergens**
- ##### **gluten**: _Boolean_ - ##### **gluten**: _Boolean_
- ##### **lactose**: _Boolean_ - ##### **lactose**: _Boolean_
@@ -71,7 +77,7 @@
- ##### **seaFood**: _Boolean_ - ##### **seaFood**: _Boolean_
- ##### **peanuts**: _Boolean_ - ##### **peanuts**: _Boolean_
- ##### **sesame**: _Boolean_ - ##### **sesame**: _Boolean_
- ##### **ingredients**: [*String*] - ##### **ingredients**: String
- ##### **glicemicIndex**: String - ##### **glicemicIndex**: String
- ##### **kCal**: String - ##### **kCal**: String
- ##### **vegan**: _Boolean_ - ##### **vegan**: _Boolean_

View File

@@ -14,19 +14,19 @@ const dishSchema = mongoose.Schema({
required: true, required: true,
}, },
price: { price: {
type: Number, type: String,
required: true, required: true,
}, },
notes: { notes: {
type: String, type: String,
maxlength: 128, maxlength: 200,
}, },
imgUrl: { imgUrl: {
type: String, type: String,
required: true, required: true,
}, },
hidden: Boolean, hidden: Boolean,
weight: Number, weight: String,
allergens: { allergens: {
gluten: Boolean, gluten: Boolean,
lactose: Boolean, lactose: Boolean,
@@ -36,9 +36,7 @@ const dishSchema = mongoose.Schema({
peanuts: Boolean, peanuts: Boolean,
sesame: Boolean, sesame: Boolean,
}, },
ingredients: { ingredients: String,
type: [String],
},
glicemicIndex: String, glicemicIndex: String,
kCal: String, kCal: String,
vegan: Boolean, vegan: Boolean,

View File

@@ -64,7 +64,14 @@ const restaurantSchema = mongoose.Schema({
subscriptionStarted: Date, subscriptionStarted: Date,
subscriptionDue: Date, subscriptionDue: Date,
categories: [String], categories: [String],
lunchMenu: [mongoose.Types.ObjectId], lunchHours: String,
lunchMenu: [
{
lunchSetName: String,
lunchSetPrice: String,
lunchSetDishes: [mongoose.Types.ObjectId],
},
],
dishes: [mongoose.Types.ObjectId], dishes: [mongoose.Types.ObjectId],
}); });

View File

@@ -33,7 +33,7 @@ router.post("/", async (req, res) => {
await validateRestaurant(req.body.restaurantId); await validateRestaurant(req.body.restaurantId);
const token = req.headers["x-auth-token"]; const token = req.headers["x-auth-token"];
validateUserToken(token); validateUserToken(token);
const dish = createDish(req.body.dish, req.body.restaurantId, true); const dish = await createDish(req.body, req.body.restaurantId, true);
await dish.save(); await dish.save();
await addDishToRestaurant(req.body.restaurantId, dish._id); await addDishToRestaurant(req.body.restaurantId, dish._id);
res.status(201).send(dish._id); res.status(201).send(dish._id);

View File

@@ -116,7 +116,7 @@ export async function prepareSafeUser(user) {
export async function createDish(dish, restaurantId, generateId) { export async function createDish(dish, restaurantId, generateId) {
try { try {
if (generateId) { if (generateId) {
const img = await saveImage(dish.imgUrl); const img = await handleImageUpdate(dish);
const newDish = new Dish({ const newDish = new Dish({
_id: new mongoose.Types.ObjectId(), _id: new mongoose.Types.ObjectId(),
restaurantId: restaurantId, restaurantId: restaurantId,
@@ -143,13 +143,14 @@ export async function createDish(dish, restaurantId, generateId) {
}); });
return newDish; return newDish;
} else { } else {
const img = "";
const newDish = new Dish({ const newDish = new Dish({
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, price: dish.price,
notes: sanitizer.sanitize.keepUnicode(dish.notes), notes: sanitizer.sanitize.keepUnicode(dish.notes),
imgUrl: dish.imgUrl, imgUrl: img,
weight: dish.weight, weight: dish.weight,
allergens: { allergens: {
gluten: dish.allergens.gluten, gluten: dish.allergens.gluten,
@@ -169,6 +170,7 @@ export async function createDish(dish, restaurantId, generateId) {
return newDish; return newDish;
} }
} catch (e) { } catch (e) {
console.log(e);
throw newError("Cannot create dish", 500); throw newError("Cannot create dish", 500);
} }
} }