Document Management System API contains several APIs that allows users to create, edit, retrieve and delete documents. It also offers a way to ensure that only authroized users can perform certain operations.
The application was developed with NodeJs while using Express for routing. The Postgres database was used with sequelize as the ORM
- Ensure you have NodeJs and postgres installed
- Clone the repository
git clone git@github.com:andela-foladeji/dms-api.git - Change your directory
cd dms-api - Install all dependencies
npm install - Run tests
npm test - Start the app
npm startand use postman to consume the API
Use the postman collection above and set up your environment variables for url and token
Users
| Request type | Endpoint | Action |
|---|---|---|
| POST | /users | Create a new user |
| GET | /users | Get all users |
| GET | /users/:id | Get details of a specific user |
| PUT | /users/:id | Edit user details |
| DELETE | /users/:id | Remove a user from storage |
| POST | /users/login | To log a user in |
Roles
| Request type | Endpoint | Action |
|---|---|---|
| POST | /role | Create a new role |
| GET | /role | Get all created roles |
Documents
| Request type | Endpoint | Action |
|---|---|---|
| POST | /documents | Create a new document |
| GET | /documents | Retrieve all documents |
| GET | /documents/:id | Retrieve a specific document |
| GET | /users/:id/documents | Retrieve all documents created by a user |
| GET | /documents?page=1&limit=10 | Retrieve maximum of first 10 documents |
| PUT | /documents/:id | Update a specific document |
| DELETE | /documents/:id | Remove a specific document from storage |
To create a new user, make a POST request to /users
{
"firstName": "Jane",
"lastName": "Doe",
"username": "janedoe",
"email": "janedoe@mail.com",
"password": "secretkey",
"roleId": "1"
}
json
{
"done": true,
"user": {
"id": 1
"firstName": "Jane",
"lastName": "Doe",
"username": "janedoe",
"email": "janedoe@mail.com",
"password": "dskjslk894u8hdk993289389dkndnjeiu34348fn",
"roleId": "1",
"createdAt": "2016-12-06T09:25:29.316Z",
"updatedAt": "2016-12-06T09:25:29.316Z"
},
token: "d98whIHSKJHAKdskljEEWRjsdodsjci8943dskljEEWRjsdodsjci8943u9ru348jsdnxssSJoihs98r32u983yd98whIHSKJHAKdskljEEWRjsdodsjci8943u9ru348jsdnxssSJoihs98r32u983yd98whIHSKJHAK"
}
Fetches all users' details,
- Endpoint: GET:
/users - Requires
Authorizationheader to be set
[
{
"id": "1",
"firstName": "Jane",
"lastName": "Doe",
"username": "janedoe",
"email": "janedoe@mail.com",
"roleId": "1",
"createdAt": "2016-12-06T09:25:29.316Z",
"updatedAt": "2016-12-06T09:25:29.316Z"
}, {
"id": "2",
"firstName": "Dead",
"lastName": "Pool",
"username": "deadpool",
"email": "deadpool@mail.com",
"roleId": "2",
"createdAt": "2016-12-06T09:25:29.316Z",
"updatedAt": "2016-12-06T09:25:29.316Z"
}
]
- Endpoint: GET:
/users/:id - Requires
Authorizationheader to be set
{
"id": "1",
"firstName": "Jane",
"lastName": "Doe",
"username": "janedoe",
"email": "janedoe@mail.com",
"roleId": "1",
"createdAt": "2016-12-06T09:25:29.316Z",
"updatedAt": "2016-12-06T09:25:29.316Z"
}
- Enpoint: PUT:
/users/:id - Requires
Authorizationheader to be set
{
"firstName": "Doctor",
"lastName": "Strange",
"username": "docstrange",
"email": "doctorstrange@marvel.com",
"password": "astroprojection",
"roleId": "1"
}
Body (application/json)
{
"done": true,
"user": {
"firstName": "Doctor",
"lastName": "Strange",
"username": "docstrange",
"email": "doctorstrange@marvel.com",
"roleId": "1"
}
}
- Enpoint: DELETE:
/users/:id - Requires
Authorizationheader to be set
Body (application/json)
{
"done": true
}
- Endpoint: POST:
/users/login - Body (application/json)
{
"username": "docstrange",
"password": "astroprojection"
}
Body (application/json)
{
"done": true,
"user": {
"firstName": "Doctor",
"lastName": "Strange",
"username": "docstrange",
"email": "doctorstrange@marvel.com",
"roleId": "1"
},
token: "sdfeofJOIFiflfjKJ48lj8949fjeofJOIFiflffjKJ4848wjKJ484894NNsdfeofJOIFifUNnowIFiflfjKJ4848wesflfjKJ4848"
}
- Endpoint POST
/role - Requires
Authorizationheader to be set Body (application/json)
{
"title": "Admin"
}
Body (application/json)
{
"done": true
}
- Endpoint GET
/role - Requires
Authorizationheader to be set
{
"roles": [
{
"id": 1,
"title": "Admin",
"createdAt": "2016-12-06T09:25:29.316Z",
"updatedAt": "2016-12-06T09:25:29.316Z"
},
{
"id": 1,
"title": "Regular",
"createdAt": "2016-13-06T09:25:29.316Z",
"updatedAt": "2016-13-06T09:25:29.316Z"
}
]
}
- Endpoint POST
/documents - Requires
Authorizationheader to be set
{
"title": "Marvel",
"content": "Diary of a movie addict",
"access": "role"
}
- Body
(application/json)
{
"done": true,
"doc": {
"title": "Marvel",
"content": "Diary of a movie addict",
"access": "role",
"createdAt": "2016-13-06T09:25:29.316Z",
"updatedAt": "2016-13-06T09:25:29.316Z"
}
}
- Endpoint GET
/documents - Optional queries page (for the page number) && limit (number of documents per page)
- Requires
Authorizationheader to be set
[
{
"title": "Marvel",
"content": "Diary of a movie addict",
"access": "role",
"ownerId": "1",
"createdAt": "2016-13-06T09:25:29.316Z",
"updatedAt": "2016-13-06T09:25:29.316Z"
},
{
"title": "The accountant",
"content": "J.K simmons was in the movie as well as Ben Affleck, one of my fav",
"access": "private",
"ownerId": "2",
"createdAt": "2016-13-06T09:25:29.316Z",
"updatedAt": "2016-13-06T09:25:29.316Z"
}
]
- Endpoint GET
/documents/:idwhere id is the id of the document - Requires
Authorizationheader to be set
{
"title": "Marvel",
"content": "Diary of a movie addict",
"access": "role",
"ownerId": "1",
"createdAt": "2016-13-06T09:25:29.316Z",
"updatedAt": "2016-13-06T09:25:29.316Z"
}
- Endpoint GET
/users/:id/documents/id is the id of the user - Requires
Authorizationheader to be set
[
{
"title": "The accountant",
"content": "J.K simmons was in the movie as well as Ben Affleck, one of my fav",
"access": "private",
"ownerId": "1",
"createdAt": "2016-13-06T09:25:29.316Z",
"updatedAt": "2016-13-06T09:25:29.316Z"
}
]
- Endpoint PUT
/documents/:idid is the id of the document - Requires
Authorizationheader to be set
{
"title": "The accountant",
"content": "J.K simmons was in the movie as well as Ben Affleck, one of my fav",
"access": "private",
"ownerId": "2",
}
- Endpoint DELETE
/documents/:idid of the document - Requires
Authorizationheader to be set
{
"done": true
}