Challenge Overview
We have a nodejs API and in this challenge we want to add new set of endpoints to it.
Read specification carefully and let us know if you have any questions.
Challenge Requirements
UI Prototype
https://brilliant-careers-static.herokuapp.com/
We are building API Endpoints for the “Essential Skills” pages, it will contain:
- Set of Modules
- Each Module will contain set of Activities
- Each Activity will have one or more lessons where user need to interact and provide answers.
- User can view their progress of each Module and Activity.
Please check the UI prototype, you are welcome to propose any improvements to the API endpoints in scope.
Base Code
Base API code is provided in challenge forums as a git folder. Use it to submit a patch file.
Model Schema
You are provided with ERD in challenge forums for the models in scope.
API Endpoints
You will build the following endpoints in this challenge :
- User Essential Skills Summary
- Route: GET /ES/summary
- Used in this page https://brilliant-careers-static.herokuapp.com/Essential_Skills.html
- This is protected endpoint (means user must be logged in)
- Logic
- Should return the following user information :
- Last time user worked on the essential skills, this information is pulled by reading the last time we have a record for user_activities for this user of type ‘started_lesson’.
- Max Potential Points User can accumulate, this information by sum the ‘total_potential_points’ of all modules records.
- The badge earned when completing all modules, this is a configured badge id, we pull its information from table.
- User progress is calculated by sum number of all module activities divided by sum of user_activities#type == ‘completed_lesson’ for the user.
- GET User Activities
- Route : GET /ES/activities
- Used in this page https://brilliant-careers-static.herokuapp.com/Essential_Skills.html
- This endpoint is protected
- Retrieves latest user_activities in Essential Skills area where display is 1 (true).
- Pagination parameters are input, if not provided, default values should be use.
- Retrieve the latest user activities in descending order with pagination enforced.
- Type of user activities
- Start_lesson : when user starts a lesson (display : 0)
- Completed_lesson: when user completes a lesson in activity and earn points (display : 0)
- points_earned : when user earn new points from completing all activity lessons (display : 1)
- Badge_earned: when user earn a new badge (display : 1)
- Activity_completed: when user complete activity (display : 0)
- Essential Skills Leaderboard
- Route : GET /ES/leaderboard
- Used in this page https://brilliant-careers-static.herokuapp.com/Essential_Skills.html
- Retrieves the members leaderboard.
- This endpoint is protected
- Pagination parameters are input, if not provided, default values should be use.
- Sum the users_answer points, grouped by user_id, and ordered using aggregated points in descending order.
- Retrieve users who completed the modules using points in descending order with pagination enforced.
- User Essential Skills Modules
- Route :GET /ES/modules
- Used in this page https://brilliant-careers-static.herokuapp.com/Essential_Skills.html
- Used to retrieve list of modules
- This endpoint is protected.
- This will return the modules entries, it should include :
- Associated activities count, total potential points from all activities
- The progress user completed of each module by sum number of lessons in the module activities divided by user_activities where type is ‘lesson_completed’ of that module, so data should be grouped by module_id
- Total points earned per module for that user aggregate the points earned in user_activities of type ‘lesson_completd’ group by module_id.
- User Module Summary
- Route : GET /ES/module/{id}
- Used in this screen https://brilliant-careers-static.herokuapp.com/Essential_Skills_Module.html
- Returns module details including user progress/summary for that module
- This endpoint is protected
- The endpoint returns :
- Module fields, including badge child populated
- Last time user worked on the module, this is by return the last time user started or completed a lesson in that module, from user_activities table.
- The user progress in module by sum number of module activities / completed lessons in the module (user_activities#type == ‘lesson_completed’)
- User Module Activities Summary
- Route : GET /ES/module/{id}/activities
- Used in this screen https://brilliant-careers-static.herokuapp.com/Essential_Skills_Module.html
- This endpoint is protected
- This endpoint returns :
- Activity record fields
- Total points user earned in this activity by aggregate it from user_activities where type is ‘lesson_completed’
- Total time user spent in this activity lessons by aggregate the time from user_answers table.
- Return the first lesson ID of this activity where user has not started/completed yet, by reading activity_lessons#right_lesson_id of last completed lesson by user. If user completed all lessons this value will be first lesson id as user can redo the lessons from beginning.
- Start a lesson
- Route : POST /ES/activity{id}/start_lesson/{id}
- Used in this screen https://brilliant-careers-static.herokuapp.com/Essential_Skills_Activity.html
- We call this endpoint to track user starting to work on an activity/lesson.
- This will add new entry to user_activites of type ‘start_lesson’, it set date as current date, and set module_id and activity_id as well.
- Get Activity lessons
- Route : GET /ES/activity/{id}/lessons
- Used in this screen https://brilliant-careers-static.herokuapp.com/Essential_Skills_Activity.html
- This endpoint is protected.
- Returns list of activity_lessons with possible answers values from lesson_answers.
- If user already made answer for any question, then user response should be pulled from user_answers along with progress value (number of lessons / completed lessons), and the total time spent on the activity (aggregate user_answers#time).
- Submit Lesson Answers
- Route: POST /ES/lesson/{id}/answers
- Used in this screen https://brilliant-careers-static.herokuapp.com/Essential_Skills_Activity.html
- This endpoint is protected
- This will submit the answers selected by user, it will perform calculation for earned points by the activity. Assign badge if user completed the module activities.
- So this endpoint should do the following :
- Validate answers is within the allowed range/type.
- Insert answers in user_answers table of type ‘lesson_completed’, log time, and point earned by each answer, and date of inserted record.
- Check if lesson has a right adjacent lesson then return it, if not, then activity is completed, then :
- Insert new record in user_activities of type ‘activity_completed’,
- Get right adjacent activity id of current activity and return it in response.
- If user completed the activities of the module, then :
- Assign user module badge, and return it in response.
- Log user_activities of type ‘module_completed’ with all proper information needed.
- Return right adjacent module id.
- Response should also include :
- Total points user earned from completing the lesson
- Total points user earned from completing the activity
User Answers Validation and Points Calculation
The Angluarjs app will have the activity lessons templates created in the angularjs app as html templates. The backend in this phase only require to pull the question answers if user already done the lesson earlier, and to store user answers of the lessons.
Before storing the answers, we need to perform validation for the answers, there is no right or wrong, it is only validation that answer is valid and in range of possible answers of the lesson in scope.
After validating answers, backend will assign points to each answer and store in user_answers.
We are going to provide you with 3 sample documents of the first 3 modules, each activity in these modules has completely unique lessons. You are required to suggest a solution for how to validate the answers, assign points, and ability to retrieve these answers.
The suggested approach is to hard code the validation by implementing a custom validator for each lesson, where validator name can be configured in activity_lessons table, so when submitting the answers it will delegate to the validator class of that lesson to validate answers, and return calculated points for the answers.
Module Documents
You are provided with three documents, each represents a module with multiple activities, use them to write a realistic api tests calls. We want to see your api works with this content as it will be used in production.
Notes
- Prefix for api routes : /api/
- All api endpoints input parameters should be properly validated.
- Error messages should be in json format, with fields : message, error code, and error flag (true).
- Postman file should be updated with proper endpoints and test cases.
- Proper logging should be added for all endpoints.
- All code must be linted using eslint.com
- All code must be properly documented.
Technology Stack
- NodeJS 4.x
- Postgres 9.4
- Heroku
���
Final Submission Guidelines
Deliverables
- Git patch file that include all changes.
- Deployment guide should be the README filed updated with all required steps to deploy and test your app locally and on heroku.
- Verification document.