Challenge Overview

Project Overview

The goal of this project is build a cloud-based web application that end-users will access within a web browser. The application will allow users to routinely log time based on predetermined categories, as well as the creation of ad-hoc categories.

These categories can include tasks such as: breaks, lunch, training, problem resolution, documentation management, company & client meetings.

Challenge Overview

The main task of this challenge is to build the backend REST API for the web application.

Technology Stack

- NodeJS 4.x

- ExpressJS 4.x

- Gulp

- Heroku

- MongoDB 3.x

- Bower

Web app interface

In the forums we have shared with you the design screens of the application, you are welcome to discuss in forums an improvement to the API endpoints.

Mongo Collections/Model

 

This is suggested model based on the information we have in the UI prototype. You are encouraged to propose an improvements to the model as performance of pulling reports are major requirement. This will count to the extra features in the review scorecard.

User

- ID (number - auto increment)

- Email

- Password

- First Name

- Last Name

- Employee ID #

- Industrialized Center

- Account

- Function

- Role (admin, user)

- AuthTokens

- AuthToken

- Date

- Expired (flag)

TimeTracker

- ID (auto generated)

- Date (represent the date only without time)

- Running (flag indicate if the time tracker is ON or OFF)

- Current activity (represents the currently selected category ID, if not set, then no selected category)

- User#Id

- Timeline : represents an array of JSON objects, each object has the following attributes:

- Start_time : always required when adding a new object, this is time only, no date

- End_time : optional, only set, when user toggle current activity/time. this is time only, no date.

- Category_id : optional, if not set, then it represents a production time entry.

- Auditing fields (created at, updated at, createdBy, updatedBy)

API Endpoints

Notes

- Response and request will be in json format.

- You will use ExpressJS.

- Use the provided application structure/setup.

- When error occurred in any api endpoint, it should be error json with friendly message and code attribute.

Register

- Route: POST /api/register

- Input

- Email

- Password

- First name

- Last name

- Employee ID

- Industrialized center

- Specific Account

- Specific Function

- Logic

- Validate input parameters.

- Validate user not already exists, if exists, return proper error message.

- Create new User using the information provided, and return valid auth token (so user get logged in immediately).

- Response:

- Success json message.

Login

- Route: POST /api/login

- Input

- Email

- Password

- Logic

- Validate input parameters

- Validate user exists with provided information.

- Create auth token, store it in user document.

- Response

- Success json message with auth token.

Logout

- Route: GET /api/logout

- Input

- Header: Auth token

- Logic

- Destroy the auth token

- Response

- Return success message in json format.

My Info

- Route: GET /api/me

- Input

- Header : Auth token

- Logic

- Validate the auth token is valid and belongs to existing user.

- Return user information, that include the name and photo.

- Response

- The user information in json.

Start Time Tracker

- This endpoint to start time tracker for current date

- Route: POST /api/tracker

- Input

- Header: Auth token

- Logic

- Validate auth token

- Start time tracker of current date by creating new time tracker record :

- Running : true

- Timeline : has one object with start_time  equals current time.

- Current activity is set to null.

- If already started - meaning there is already an entry for current date - then check if the tracker is stopped (running = false), if not stopped return error, otherwise, toggle running flag and add new record to timeline attribute with start_time  equals current time.

- Response

- The time tracker record of current date

Update Time Tracker

- This endpoint to add activities to the time tracker or to stop time tracker for current date.

- Route: PUT /api/tracker

- Input:

- Header: Auth token

- Category_id (optional)

- Logic

- Validate auth token

- If time tracker record is already stopped and current activity is not set OR the tracker record not exist, then return error message.

- If category id is provided, then

- Validate it exists.

- If time tracker has different current activity set, then :

- Stop the current activity by updating the timeline#object#end_time attribute

- Add new timeline#object with start_time equals current time

- Set the new category id as current activity.

- If category id is the current activity in the current time tracker, then set current activity to null, update timeline object end_time to current time, and return the record.

- If category id is used to disable production time, then toggle the running flag.

- If category id not provided, then stop the time tracker.

- Response

- The time tracker record.

Get Current Time Tracker

- Route: GET /api/tracker

- Input

- Header: Auth token

- Logic

- Authorize the token

- Return the user current time tracker of current date.

- Response

- The time tracker record.

Categories List

- Route: GET /api/categories

- Input

- Header: Auth token

- Logic

- Authorize auth token

- Pull categories list

- Response

- Return the categories list

Report Filter

- Route: GET /api/report/filters/{field-name}

- This endpoint will return the list of possible values for the given name

- The filter options are related to user fields, so we are passing field name which is used to pull the possible values for that field.

- Input:

- Header: Auth token

- Pagination field (offset and size)

- Logic

- Validate user is an admin

- For the provided field name, pull all possible values from table with pagination enforced.

- Response

- Return array of responses.

Get Report

- Route : GET /api/report/{report-type}?{fitler-parameter-name}={filter-parameter-value}

- This endpoint used to aggregate report data

- We have 4 report types : table, stacked bar chart, line chart, and column chart.

- Input:

- Header: Auth token

- Filter parameters, represent the user field name and possible values (can be one or more values)

- Report type

- Logic

- Authorize the access token belongs to an admin

- Write an aggregation function against the collection to pull report data based on the report type, it is up to you to come up with single query if that addresses all report types.

- A suggestion that we have exactly single collection that store the user information + daily trackers so aggregation can be more effecient.

- Response

-  Array of report data points.

- Filter parameters should be part of the response

Export Report

- Route: GET /api/report/export/csv?fitler-parameter-name}={filter-parameter-value}

- This endpoint will export the report data in csv format.

- Same logic as done in Get Report except that the data are returned in csv format to be downloaded.

- Filter parameters should be part of the exported csv file.

Other Notes

- Create unit tests using mocha for the api endpoints.

- Provide a postman file for all api endpoints

- Provide test data script.

- All code must be properly documented.

- All code must pass lint checker.
- Deployment script to Heroku.
- Gulp script for build, deploy, and test.

- README.md - Basic markdown deployment documentation in the readme.md

- Use the Readme.md in the forum

- Required tools and Environment Setup

- How to run tests and deploy a working app locally and in production



Final Submission Guidelines

Deliverable

- All files that address the requirements

- README file

REVIEW STYLE:

Final Review:

Community Review Board

Approval:

User Sign-Off

SHARE:

ID: 30054761