2020-09-18 18:58:55 +02:00
2020-09-12 20:47:41 +02:00
2020-08-24 21:59:37 +02:00
2020-09-18 18:58:55 +02:00
2020-09-12 20:47:41 +02:00
2020-09-18 18:58:55 +02:00
2020-09-18 18:58:55 +02:00
2020-08-20 20:27:14 +02:00
2020-07-18 20:19:57 +02:00
2020-08-20 11:44:32 +02:00
2020-08-19 15:31:02 +02:00
2020-09-16 17:34:24 +02:00
2020-09-16 17:34:24 +02:00
2020-09-16 17:34:24 +02: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
    • imgUrl: String (required)
    • workingHours: String (required)
    • description: String
    • tags
      • cardPayments: Boolean
      • petFriendly: Boolean*
      • glutenFree: Boolean
      • vegan: Boolean
      • vegetarian: Boolean
      • alcohol: Boolean
      • delivery: Boolean
      • facebook: String
      • twitter: String
      • instagram: String
      • www: String
    • phone: Number
    • hidden: Boolean
    • subscriptionActive: Boolean
    • subscriptionStarted: String
    • subscriptionDue: String
    • dishes: [mongoose.Types.ObjectId]

  • Dish

    • _id: mongoose.Types.ObjectId
    • restaurantId: mongoose.Types.ObjectId
    • name: String (max: 128, required)
    • category: String (max: 64, required)
    • price: Number (required)
    • notes: String (max: 128)
    • imgUrl: String (required)
    • hidden: Boolean
    • weight: Number
    • allergens
      • gluten: Boolean
      • lactose: Boolean
      • soy: Boolean
      • eggs: Boolean
      • seaFood: Boolean
      • peanuts: Boolean
      • sesame: Boolean
    • ingredients: [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.
  • /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/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 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.


  • /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/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.


    • 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%