server v1.0.6
This commit is contained in:
18
README.md
18
README.md
@@ -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_
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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],
|
||||
});
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user