Final Checkpoint
This a Javascript implemented document management api with access levels, roles and priviledges.
Each document defines access rights; the document defines which roles can access it. Also, each document specifies the date it was published.
Users are categorized by roles.
Run the App on POSTMAN
.
regular
by default. admin
or regular
. public
). HTTP Verb | Endpoint | Functionality |
---|---|---|
POST | /users/login | Logs a user in and returns a token which should be subsequently used to access authenticated endpoints. request parameters include email and password |
POST | /users/logout | Logs a user out |
POST | /users/ | Creates a new user. Required attributes are firstName , lastName , email , password . If a role is not specified, a defualt role of regular is created |
GET | /users/ | Fetch all registered users (admin privilege required) |
GET | /users/:id | Fetch a user by specific id (admin privilege required). parameter: id of the particular user as url query |
PUT | /users/:id | Update a specific user (by id) attributes. parameter: id of the particular user as url query |
DELETE | /users/:id | Delete a specific user by id. (admin privilege required). parameter: id of the particular user as url query |
POST | /documents/ | Creates a new document instance. Required attributes are title , content and access . If an access is NOT specified, the document is marked public by default |
GET | /documents/ | Fetch all documents (returns all documents based on each document access right and the requesters role) |
GET | /documents/:id | Fectch a specific document by it’s id. parameter: id of the particular document as url query |
PUT | /documents/:id | Update specific document attributes by it’s id. parameter: id of the particular document as url query |
DELETE | /documents/:id | Delete a specific document by it’s id. parameter: id of the particular document as url query |
GET | /users/:id/documents | Find all documents belonging to the specified user. parameter: id of the particular user as url query to get the correponding documents belonging to that user |
POST | /roles/ | Create a new role (admin privilege required) |
GET | /roles/ | Fetches all roles (admin privilege required ) |
GET | /roles/:id | Find a role by id (admin privilege required ). parameter: id of the particular role as url query |
PUT | /roles/:id | Update role attributes (admin privilege required ). parameter: id of the particular role as url query |
DELETE | /delete/:id | Delete role (admin privilege required ). parameter: id of the particular role as url query |
Endpoints for role API
/roles
200: OK
(application/json)
[
{
"id": 1,
"title": "admin",
"createdAt": "2017-03-03T13:28:22.003Z",
"updatedAt": "2017-03-03T13:28:22.003Z"
}
{
"id": 3,
"title": "regular",
"createdAt": "2017-03-03T13:28:22.003Z",
"updatedAt": "2017-03-03T13:28:22.003Z"
}
]
/roles
(application/json)
{ "title": "supervisor" }
201: Created
(application/json)
"role": {
"id": 3,
"title": "supervisor",
"updatedAt": "2017-03-07T15:57:29.019Z",
"createdAt": "2017-03-07T15:57:29.019Z"
}
/roles/:id
200: OK
(application/json)
{
"success": true,
"message": "Role Successfully deleted from database"
}
Endpoint for Users API.
/users
(application/json)
{
"username": "uniqueuser",
"firstname": "First Name",
"lastname": "Last Name",
"email": "uniqueuser@unique.com",
"password": "password"
}
201: Created
(application/json)
{
"success": true,
"message": "User successfully signed up",
"RoleId": 2,
"token": "eyJhbGciOiJIUzI1NiIsInR5cCsdfdfdI6IkpXVCJ9.eyJpZCI6MSwidXNlcm5hbWUiOiJzdXBlcmFkbWluIiwiZmlyc3RuYW1lIjoiRGFyaXVzIiwibGFzdG5hbWUiOiJKYXN0IiwiZW1haWwiOiJvcmViYW40dUB5YWhvby5jby51ayIsImRlcGFydG1lbnRJZCI6MSwiaWF0IjoxNDg4OTA4ODczLCJleHAiOjE0ODg5MTYwNzN9.ou0fzsufXyPNojT1shLa4N2zEuV9rvtPKcrs_amlYrQ",
"expiresIn": "86400"
}
/users
200: OK
(application/json)
[
{
"id": 1,
"username": "super",
"firstname": "Sydnie",
"lastname": "Mitchell"
},
{
"id": 2,
"username": "cook",
"firstname": "Louisa",
"lastname": "Murazik"
}
]
/users/:id
200: OK
(application/json)
{
"id": 1,
"username": "super",
"firstname": "Sydnie",
"lastname": "Mitchell"
}
/users/:id
(application/json)
{
"username": "editeduser",
"firstname": "Edited User",
"lastname": "Edited User",
"email": "editeduser@unique.com",
"password": "password"
}
200: OK
(application/json)
{
"id": 9,
"username": "edited",
"firstname": "editeduser",
"lastname": "user",
"email": "editeduser@admin.com",
"createdAt": "2017-03-07T16:56:09.880Z",
"updatedAt": "2017-03-07T17:30:07.385Z"
}
/user/:id
200: OK
(application/json)
{
"success": true,
"message": "User Successfully deleted from database"
}
users/login
(application/json)
{
"email": "test@test.com",
"password": "test"
}
200: OK
(application/json)
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCsdfdfdI6IkpXVCJ9.eyJpZCI6MSwidXNlcm5hbWUiOiJzdXBlcmFkbWluIiwiZmlyc3RuYW1lIjoiRGFyaXVzIiwibGFzdG5hbWUiOiJKYXN0IiwiZW1haWwiOiJvcmViYW40dUB5YWhvby5jby51ayIsImRlcGFydG1lbnRJZCI6MSwiaWF0IjoxNDg4OTA4ODczLCJleHAiOjE0ODg5MTYwNzN9.ou0fzsufXyPNojT1shLa4N2zEuV9rvtPKcrs_amlYrQ",
"expiresIn": "86400"
}
users/logout
(application/json)
200: OK
(application/json)
{
"success": true,
"message": "User logged out successfully"
}
Endpoint for Documents.
/documents
(application/json)
{
"title": "readmi",
"content": "this is a demo dare to ask for the impossible.",
"access": "public",
"OwnerId": 2
}
201: Created
(application/json)
{
"success": true,
"message": "Document successfully created",
"document": {
"id": 8,
"title": "readmi",
"content": "this is a demo dare to ask for the impossible.",
"access": "public",
"OwnerId": 2,
"updatedAt": "2017-03-07T18:20:20.929Z",
"createdAt": "2017-03-07T18:20:20.929Z"
}
}
/documents
200: OK
(application/json)
{
"success": true,
"results": [
{
"id": 1,
"title": "Integrated regional info-mediaries",
"content": "Voluptas et nostrum assumenda ea velit facere molestiae reprehenderit atque. Optio laboriosam harum. Aut ut nemo tenetur. Architecto praesentium aut at. Corrupti totam quo.",
"OwnerId": 3,
"access": "public",
"createdAt": "2017-03-06T12:02:27.902Z"
},
{
"id": 2,
"title": "we worship forever",
"content": "Reiciendis voluptate error voluptatem possimus dolores provident neque aut nemo. Ab in quia ut quos ipsum veritatis consequatur alias. Quae aut facilis.",
"OwnerId": 5,
"access": "public",
"createdAt": "2017-03-06T12:02:27.902Z"
}
]
}
/documents/:id
200: OK
(application/json)
{
"success": true,
"message": "Document found",
"document": {
"id": 6,
"title": "Enhanced client-driven focus group",
"content": "Placeat aspernatur dolores corporis. Ipsum similique maiores quisquam ratione vel.",
"OwnerId": 3,
"access": "public",
"createdAt": "2017-03-06T12:02:27.902Z",
"updatedAt": "2017-03-06T12:02:27.902Z"
}
}
/documents/:id
(application/json)
{
"title": "readmi",
"content": "this is a demo dareasdfasdfsfaf to ask for the impossible.",
"access": "private"
}
200: OK
(application/json)
{
"id": 6,
"title": "readmi",
"content": "this is a demo dareasdfasdfsfaf to ask for the impossible.",
"access": "private",
"OwnerId": 3,
"createdAt": "2017-03-06T12:02:27.902Z",
"updatedAt": "2017-03-07T18:40:19.108Z"
}
/documents/:id
200: OK
(application/json)
{
"success": true,
"message": "Document has been successfully deleted"
}
/documents/?query=searchQuery
200: OK
(application/json)
{
"success": true,
"results": [{
"id": 1,
"title": "Integrated regional info-mediaries",
"content": "Voluptas et nostrum assumenda ea velit facere molestiae reprehenderit atque. Optio laboriosam harum. Aut ut nemo tenetur. Architecto praesentium aut at. Corrupti totam quo.",
"OwnerId": 3,
"access": "public",
"createdAt": "2017-03-06T12:02:27.902Z"
},
{
"id": 2,
"title": "we worship forever",
"content": "Reiciendis voluptate error voluptatem possimus dolores provident neque aut nemo. Ab in quia ut quos ipsum veritatis consequatur alias. Quae aut facilis.",
"OwnerId": 7,
"access": "public",
"createdAt": "2017-03-06T12:02:27.902Z"
}]
}
/users/:UserId/documents/
. e.g /users/2/documents
200: OK
(application/json)
[
{
"id": 1,
"title": "Integrated regional info-mediaries",
"content": "Voluptas et nostrum assumenda ea velit facere molestiae reprehenderit atque. Optio laboriosam harum. Aut ut nemo tenetur. Architecto praesentium aut at. Corrupti totam quo.",
"OwnerId": 2,
"access": "public",
"createdAt": "2017-03-06T12:02:27.902Z"
},
{
"id": 2,
"title": "we worship forever",
"content": "Reiciendis voluptate error voluptatem possimus dolores provident neque aut nemo. Ab in quia ut quos ipsum veritatis consequatur alias. Quae aut facilis.",
"OwnerId": 2,
"access": "public",
"createdAt": "2017-03-06T12:02:27.902Z"
}
]
Technologies Used in the development of this api include the following
[babel-cli]: https://babeljs.io
[babel-core]: https://babeljs.io
[babel-loader]: https://babeljs.io
[babel-preset-es2015]: https://babeljs.io
[babel-preset-react]: https://babeljs.io
[babel-preset-react-hmre]: https://babeljs.io
[babel-register]: https://babeljs.io
[eslint]: http://eslint.org
[expect]: http://chaijs.com/api/bdd
[express]: http://expressjs.com
mocha: https://mochajs.org
[webpack]: https://webpack.github.io
[webpack-dev-middleware]: https://webpack.github.io
[webpack-hot-middleware]: https://webpack.github.io
© Tomilayo Israel