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

View File

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

View File

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

View File

@@ -33,7 +33,7 @@ router.post("/", async (req, res) => {
await validateRestaurant(req.body.restaurantId);
const token = req.headers["x-auth-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 addDishToRestaurant(req.body.restaurantId, 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) {
try {
if (generateId) {
const img = await saveImage(dish.imgUrl);
const img = await handleImageUpdate(dish);
const newDish = new Dish({
_id: new mongoose.Types.ObjectId(),
restaurantId: restaurantId,
@@ -143,13 +143,14 @@ export async function createDish(dish, restaurantId, generateId) {
});
return newDish;
} else {
const img = "";
const newDish = new Dish({
restaurantId: restaurantId,
name: sanitizer.sanitize.keepUnicode(dish.name),
category: dish.category,
price: dish.price,
notes: sanitizer.sanitize.keepUnicode(dish.notes),
imgUrl: dish.imgUrl,
imgUrl: img,
weight: dish.weight,
allergens: {
gluten: dish.allergens.gluten,
@@ -169,6 +170,7 @@ export async function createDish(dish, restaurantId, generateId) {
return newDish;
}
} catch (e) {
console.log(e);
throw newError("Cannot create dish", 500);
}
}