项目作者: vikasisme

项目描述 :
RESTful API to support NS8 user tracking.
高级语言: TypeScript
项目地址: git://github.com/vikasisme/user-tracking-service-ns8.git
创建时间: 2019-08-12T20:29:15Z
项目社区:https://github.com/vikasisme/user-tracking-service-ns8

开源协议:

下载


user-tracking-service-ns8

RESTful API to support NS8 user tracking.

Install application dependencies

npm i

Build the app and run it

tsc

node ./dist/start

API-Specification

POST /user

creates a new user

Sample request

  1. {
  2. "email": "test@ns8.com",
  3. "password": "passwordIsPizza",
  4. "phone": "333-222-1111"
  5. }

Data Definition

  • email
    • string
    • This field is required to create a new user
    • The system must only allow 1 user per unique email address
  • password
    • string
    • This field is required to create a new user
  • phone number
    • string
    • This field is optional
    • When provided, the phone number must follow this pattern ###-###-####

      Sample response

      1. {
      2. "statusCode": 201,
      3. "message": "Success: Created!",
      4. "data": {
      5. "userId": 136
      6. }
      7. }

GET /user

returns all users

Sample response

  1. {
  2. "statusCode": 200,
  3. "message": "Success: OK",
  4. "data": [
  5. {
  6. "id": 1,
  7. "email": "xy@xx.com",
  8. "password": "zxczxczxczxc"
  9. },
  10. {
  11. "id": 2,
  12. "email": "xx@xx.com",
  13. "password": "zxczxczxczxc",
  14. "phone": "954-397-1744"
  15. }
  16. ]
  17. }

GET /user/:id

return user by id

Sample response

  1. {
  2. "statusCode": 200,
  3. "message": "Success: OK",
  4. "data": {
  5. "id": 1,
  6. "email": "xx@xx.com",
  7. "password": "zxczxczxczxc",
  8. "phone": "954-397-1744"
  9. }
  10. }

POST /user/:id/event

create an event for the user id

Sample request

  1. {
  2. "type": "login",
  3. "created": "2019-13-31"
  4. }

Data definition

  • type
    • This field is required to create a new event
    • The value can be any non-empty string
  • created
    • This field is optional
    • When provided date format should be YYYY-MM-DD
    • When not provided - created timestamp is defaulted to timestamp when event data was received by the application

      Sample response

      1. {
      2. "statusCode": 201,
      3. "message": "Success: Created!",
      4. "data": {
      5. "eventId": 1
      6. }
      7. }

GET /user/:id/event

returns events for the user id

Sample response

  1. {
  2. "statusCode": 200,
  3. "message": "Success: OK",
  4. "data": [
  5. {
  6. "id": 1,
  7. "userId": 1,
  8. "type": "login",
  9. "created": "2019-12-31T00:00:00.000Z"
  10. },
  11. {
  12. "id": 2,
  13. "userId": 1,
  14. "type": "login",
  15. "created": "2019-12-31T00:00:00.000Z"
  16. }
  17. ]
  18. }

GET /event

returns all events of all users

Sample response

  1. {
  2. "statusCode": 200,
  3. "message": "Success: OK",
  4. "data": [
  5. {
  6. "id": 1,
  7. "userId": 1,
  8. "type": "login",
  9. "created": "2019-12-31T00:00:00.000Z"
  10. },
  11. {
  12. "id": 2,
  13. "userId": 1,
  14. "type": "login",
  15. "created": "2019-12-31T00:00:00.000Z"
  16. },
  17. {
  18. "id": 3,
  19. "userId": 2,
  20. "type": "created",
  21. "created": "2019-12-31T00:00:00.000Z"
  22. },
  23. {
  24. "id": 4,
  25. "userId": 2,
  26. "type": "login",
  27. "created": "2019-12-31T00:00:00.000Z"
  28. },
  29. {
  30. "id": 5,
  31. "userId": 3,
  32. "type": "deleted",
  33. "created": "2019-12-31T00:00:00.000Z"
  34. }
  35. ]
  36. }

GET /event/last-day

returns all events of all users in the last day

Sample response

  1. {
  2. "statusCode": 200,
  3. "message": "Success: OK",
  4. "data": [
  5. {
  6. "id": 1,
  7. "userId": 1,
  8. "type": "login",
  9. "created": "2019-12-31T00:00:00.000Z"
  10. },
  11. {
  12. "id": 2,
  13. "userId": 2,
  14. "type": "login",
  15. "created": "2019-12-31T00:00:00.000Z"
  16. },
  17. {
  18. "id": 3,
  19. "userId": 2,
  20. "type": "created",
  21. "created": "2019-12-31T00:00:00.000Z"
  22. }
  23. ]
  24. }

Error Responses

  1. {
  2. "statusCode": 400,
  3. "message": "Error: Bad Request",
  4. "data": {
  5. "message": "Request Error - phone format: ###-###-####"
  6. }
  7. }
  8. {
  9. "statusCode": 404,
  10. "message": "user not found"
  11. }
  12. {
  13. "statusCode": 500,
  14. "message": "Internal Server error"
  15. }

Technical Specification

  1. node
  2. express
  3. typescript

Future Enhancements

  • Add swagger open API spec document and use the same schema for request validation and replace express-validator
  • Add unit test cases
  • Add logging
  • Build a better way to map errors and error responses in error handler
  • Add more security factors to the server(X-XSS-Protection, Strict transport security, authentication etc.,)