This is a web API service built using node.js and express.js. The service exposes basic end points to create user and update reward points of a user and retrieve the same.
- node.js (version > 12)
- npm (version > 6.13 usually included with node.js)
- cors
- md5
- sqlite3
- express
- swagger-ui
- uuid
Install depedencies for the service. Run the following command in the project directory.
npm installNote: Only if you are using MacOS and npm install fails . Then you might probably have to delete and reinstall the (latest) xcode again. For that follow these commands
sudo rm -rf $(xcode-select -print-path)
xcode-select --install
Now install npm modules by
npm installStart the service by running the following command in the project directory.
node app.jsAfter running the above command, the service will be available at: http://localhost:3050.
The service is equipped with the swagger overlay to easily test and play around the exposed api endpoints. The swagger playground also explains each and every endpoint in detail. therefore refer the swagger after launching the service for complete API specifications.
Once the service is running follow these steps to get started.
- Create a new user by using register endpoint.
- Login to the system by using admin/admin123456. (to get the userId of this new user)
- The successful login will return a JWT token called authJwt. Pass this token in the all_users request to get a list of users. This will return a list of users with user details including userId, username and role.
- Use the userId returned in the all_users request in further operations like add_points, deduct_points, points_balance endpoints.
Note: add_points endpoint expects transactionDate in unix timestamp format. This is to store the timestamp efficiently across timezones and also a standard of communication across services.
login
The endpoint can be used to login to the system.Request Url: http://localhost:3050/login
register
The endpoint can be used to create a new user.
Request Url: http://localhost:3050/register
all_users
The endpoint returns all the users present in the system.
Request Url: http://localhost:3050/all_users
add_points
The endpoint adds reward points for a specific user and specific payer. If the points specified is positive, then the points will be added to the user for that payer. If specified points is negative, it deducts the points for the user from the specific payer from the oldest entry in the transactions table.
Request Url: http://localhost:3050/add_points
deduct_points
The endpoint deducts the specified amount of points from the user in the order of oldest reward transactions.
Request Url: http://localhost:3050/deduct_points
points_balance
The endpoint retrieves the available points balance for the user for every payer the user has ever made transactions with.
Request Url: http://localhost:3050/points_balance
You can see the JWT token (authJWT) in the response body.

You can see the userId of all users. Take the required user's userId.

Add points to user account for specific payer and date (in unix timestamp).

Deduct points from the user account. It returns a list of [payer, points deducted] for each call to spend points.

Returns points balance of the user that will list all positive points per payer.
