Mantle Reviews API

This server uses Node, Express, and MongoDB to run an API server; delivering data in JSON format that represents user reviews for a product.

Quickstart

After cloning the repo, create a simple .env text file at the project root and supply parameters for server port, and for your database connection, e.g.:

SERVER_PORT=8080
DB_HOST='localhost'
DB_PORT=27017
DB_NAME='MyDatabase'

Then npm i, then npm start

API Example

GET /reviews?product_id=12345&page=0&count=10

{
    "product": "12345",
    "page": 0,
    "count": 10,
    "results": [
        {
            "review_id": 720895,
            "rating": 3,
            "summary": "I'm enjoying wearing these shades",
            "recommend": true,
            "response": "",
            "body": "Comfortable and practical.",
            "date": "2019-04-14T00:00:00.000Z",
            "reviewer_name": "shortandsweeet",
            "helpfulness": 8,
            "photos": [
                {
                    "id": 1356154,
                    "url": "https://images.unsplash.com/photo-1560570803-7474c0f9af99?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=975&q=80"
                },
                {
                    "id": 1356155,
                    "url": "https://images.unsplash.com/photo-1561693532-9ff59442a7db?ixlib=rb-1.2.1&auto=format&fit=crop&w=975&q=80"
                },
                {
                    "id": 1356156,
                    "url": "https://images.unsplash.com/photo-1487349384428-12b47aca925e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1650&q=80"
                }
            ]
        },
        {
            "review_id": 841219,
            "rating": 2,
            "summary": "Disappointed",
            "recommend": false,
            "response": null,
            "body": "Same kind of quality that you'd find on Amazon from any of the generic, Chinese unknown sellers. For the price, I expected much more. Only reason why I didn't give it the lowest scores is because I'll at least get SOME use out of it... sunglasses are sunglasses. It'd be more expensive to return it at this point...",
            "date": "2021-09-19T00:00:00.000Z",
            "reviewer_name": "keepinitreal",
            "helpfulness": 1,
            "photos": []
        }
    ]
}

GET /reviews/meta?product_id=44423

{
    "product_id": "44423",
    "ratings": {
        "1": "1",
        "3": "1",
        "5": "1"
    },
    "recommended": {
        "false": "1",
        "true": "2"
    },
    "characteristics": {
        "Fit": {
            "id": 149000,
            "value": "4.0000000000000000"
        },
        "Length": {
            "id": 149001,
            "value": "3.0000000000000000"
        },
        "Comfort": {
            "id": 149002,
            "value": "4.0000000000000000"
        },
        "Quality": {
            "id": 149003,
            "value": "3.6666666666666667"
        }
    }
}

Document schema

The server will expect a reviews collection to contain documents in the following shape:

{
    _id: 21,
    photos: [],
    characteristics: [
      { characteristic_id: 43, value: 3 },
      { characteristic_id: 44, value: 5 },
      { characteristic_id: 45, value: 2 },
      { characteristic_id: 46, value: 1 }
    ],
    review_id: 21,
    product_id: 13,
    rating: 4,
    summary: 'Doloribus blanditiis fugit nihil enim eos nemo distinctio animi.',
    body: 'Reprehenderit delectus maiores voluptas eum enim recusandae quidem aut dicta. Ducimus est assumenda delectus asperiores voluptas consectetur eum labore. Temporibus qui quod delectus vel odio amet. Quod aut accusamus et ab. Ut eos nihil. Aut ut quis earum doloribus.',
    recommend: 'true',
    date: ISODate("2020-11-22T11:44:28.366Z"),
    reviewer_name: 'Kelsie_Ernser',
    reviewer_email: 'Ryan79@hotmail.test',
    response: 'null',
    helpfulness: 18
  }

It also expects a reviewsMeta collection, with documents in the shape of:

{
    _id: 26,
    ratings: [ 2, 3, 1, 1, 3 ],
    recommends: [ 'true', 'true', 'false', 'false', 'true' ],
    characteristics: [
      {
        _id: ObjectId("6154ab8311b5f884c457821f"),
        reviewCount: 5,
        average: 2.6,
        rawValues: [ 2, 4, 2, 3, 2 ],
        product_id: 26,
        name: 'Fit',
        characteristic_id: 92
      },
      {
        _id: ObjectId("6154ab8311b5f884c4578220"),
        reviewCount: 5,
        average: 4.6,
        rawValues: [ 5, 4, 5, 4, 5 ],
        product_id: 26,
        name: 'Length',
        characteristic_id: 93
      },
      {
        _id: ObjectId("6154ab8311b5f884c4578228"),
        reviewCount: 5,
        average: 3,
        rawValues: [ 2, 4, 4, 2, 3 ],
        product_id: 26,
        name: 'Comfort',
        characteristic_id: 94
      },
      {
        _id: ObjectId("6154ab8311b5f884c4578229"),
        reviewCount: 5,
        average: 3.4,
        rawValues: [ 3, 3, 5, 4, 2 ],
        product_id: 26,
        name: 'Quality',
        characteristic_id: 95
      }
    ]
  }