2020-12-27 16:21:26 +01:00
2020-10-07 20:17:59 +02:00
2020-11-11 19:42:22 +01:00
2020-11-29 20:23:52 +01:00
2020-12-12 15:40:30 +01:00
2020-12-27 16:21:26 +01:00
2020-08-20 20:27:14 +02:00
2020-10-08 11:56:30 +02:00
2020-08-20 11:44:32 +02:00
2020-08-19 15:31:02 +02:00
2020-11-21 19:21:41 +01:00

Menui

Usage guidelines


1. Data structures

Model schemes used in backend.


  • Restaurant

    • _id: mongoose.Types.ObjectId
    • name: String (max: 128, required)
    • city: String (max: 128, required)
    • adress: String (max: 128, required)
    • location
      • type: String (enum: ["Point"], required)
      • coordinates: [Number] required
    • placesId: String
    • imgUrl: String (required)
    • workingHours:
      • pn: String
      • wt: String
      • sr: String
      • cz: String
      • pt: String
      • sb: String
      • nd: String
    • description: String
    • tags
      • cardPayments: Boolean
      • petFriendly: Boolean*
      • glutenFree: Boolean
      • vegan: Boolean
      • vegetarian: Boolean
      • alcohol: Boolean
      • delivery: Boolean
      • facebook: String
      • instagram: String
      • www: String
    • phone: Number
    • hidden: Boolean
    • subscriptionActive: Boolean
    • subscriptionStarted: String
    • subscriptionDue: String
    • categories: [String]
  • lunchHours: String
  • lunchMenu:
    • lunchSetName: String
    • lunchSetPrice: String
    • lunchSetDishes: [{ dishId: mongoose.Types.ObjectId, quantity: String }]
  • dishes: [mongoose.Types.ObjectId]

  • Dish

    • _id: mongoose.Types.ObjectId
    • restaurantId: mongoose.Types.ObjectId
    • name: String (max: 128, required)
    • category: String (max: 64, required)
    • prices: (max elements 3)
      • priceName: String (required)
      • price: String (required)
    • notes: String (max: 128)
    • imgUrl: String (required)
    • hidden: Boolean
    • weight: String
    • allergens
      • gluten: Boolean
      • lactose: Boolean
      • soy: Boolean
      • eggs: Boolean
      • seaFood: Boolean
      • peanuts: Boolean
      • sesame: Boolean
    • ingredients: String
    • glicemicIndex: String
    • kCal: String
    • vegan: Boolean
    • vegetarian: Boolean

  • User

    • _id: mongoose.Types.ObjectId
    • email: String (required)
    • password: String (required)
    • firstname: String (required)
    • lastname: String (required)
    • billing
      • NIP: String
      • adress: String
      • companyName: String
    • restaurants: [mongoose.Types.ObjectId]
    • trialUsed: Boolean

2. API


  • /dish

    • GET

      Takes a dishId query and if dish exists in a database, returns a JSON. Else returns 404.

    • POST

      Takes in restaurantId, dish document, and a JWT token (header) as parameters and tries to create a new dish document inside a database. Returns 201 on success. Else returns 401 on bad token, or 400 on wrong restaurantId.

    • PUT

      Takes in dishId, restaurantId, dish document, and a JWT token (header) and tries to update specified document in a database. Returns 304 on success. Else returns 204 on bad document, or 401 on bad token.

    • DELETE

      Takes in dishId, and JWT token (header) and tries to remove specified dish from database. If everything goes OK, it returns 200.


  • /dish/hidden

    • POST

      Takes a dishId, visible(bool) parameters, and JWT token (header), tries to set dish visibility. Returns 200 on success.

  • /restaurant

    • GET

      Takes restaurantId query and returns a specific restaurant JSON if found. Else returns 400 if restaurantId is invalid, or 404 if specified restaurantId is not found.
    • POST

      Takes a restaurant document, and JWT token (header), tries to create new restaurant in a database, and also add it to user restaurants list. Returns 201 on success. Else returns 401 on invalid token, and 400 on general error while adding restaurant.
    • PUT

      Takes a restaurantId and updates it with a supplied document.

    • /restaurant/category

    • POST

      Takes a restaurantId, category, action (add / delete) parameters, and JWT token (header), tries to create or remove a supplied category.

    • /restaurant/lunch

    • POST

      Takes a restaurantId, dishId, action (add / delete) parameters, and JWT token (header), tries to create or remove a supplied dish from/to the lunch menu.

  • /restaurant/dishes

    • GET

      Takes a restaurantId query and returns all dishes from a restaurant in a single JSON document. If failed returns 400 on invalid restaurant ID, 404 on restaurant not found, and 500 on general server error.


  • /restaurant/delete

    • POST

      Takes a restaurantId parameter !!!should also check password!!! and a JWT token(header), and tries to remove the restaurant from the database and from user. If successfull returns 200, if failed returns error with a code.


  • /restaurant/visibility

    • POST

      Takes a restaurantId, visible parameters and a JWT token(header), and tries to set restaurant visibility.


  • /restaurant/trial

    • POST

      Takes a restaurantId parameters and a JWT token(header), and tries to activate trial (if not already used).


  • /img

    • POST

      Takes an image in the form of a multipart/form-data, a JWT token (header) and tries to save the image to the cloud. If succeeded, returns a imgURL string and a 200 response code. Else returns 401 for invalid token, 204 for no image, and 500 for unknown error.


  • /user/login

    • POST

      Takes email and password parameters and returns an JWT token and basic user data if succeeded. Else returns 404 for no such user, 401 on wrong password, and 500 on general server error.


  • /user/refreshtoken

    • POST

      Takes no parameters as it reads the refreshToken from a cookie. If refresh token is valid, then returns new auth token in a header and sets new refresh token cookie. 500 on error.


  • /user/register

    • POST

      Takes email, password, firstname, lastname parameters and tries to register the user in the database. Returns 201 if succeeded. Else returns 409 on email taken, and 500 on unknown error.


  • /user/forgotpassword

    • POST

      Takes email parameter and if it exists, generates and sends an pass reset link via the email to the owner of the account.


  • /user/resetpass

    • POST

      Takes token, email, newPass parameters and if everything checks out, changes user password to the supplied newPass.


  • /user/changepass

    • POST

      Takes token, email, newPass, pass parameters and if everything checks out, changes user password to the supplied newPass.


    • GET

      Takes a string query and returns and array of JSON documents with restaurants which names or cities contain specified string query. If nothing found returns nothing. Else returns 500 for unknown error**.


  • /search/autocomplete

    • GET

      Takes a string query and returns an array of cities and names (cities first) matching specified query. Returns nothing if nothing found.


  • /search/location

    • GET

      Takes a lon, lat, and radius query parameters and returns an array of restaurants in a specified radius from supplied location.


3. Important functions


  • newError(message, status)

    Returns an error object to be handled by "handleError" function.

  • handleError(error, responseObject)

    Takes the error message and status from the error object and sends it via the supplied express response object.

Description
Server for Menui app
Readme 8.6 MiB
Languages
JavaScript 100%