This is an API that has Create, Read, Update and Delete (CRUD) functionality for both projects
and actions
.
- Run
npm install
to install your dependencies. - Initialize the database of the project executing
npm run resetdb
. - Run tests locally executing
npm test
.
A "test" script you can use to run tests against the code. A "resetdb" that allows you to reset the database to its original state.
An npm script named "start" that uses node
to run the API server.
An npm script named "server" that uses nodemon
to run the API server.
Inside api/projects/projects-router.js
are the following endpoints:
[GET] /api/projects
- Returns an array of projects as the body of the response.
- If there are no projects it responds with an empty array.
[GET] /api/projects/:id
- Returns a project with the given
id
as the body of the response. - If there is no project with the given
id
it responds with a status code 404.
- Returns a project with the given
[POST] /api/projects
- Returns the newly created project as the body of the response.
- If the request body is missing any of the required fields it responds with a status code 400.
[PUT] /api/projects/:id
- Returns the updated project as the body of the response.
- If there is no project with the given
id
it responds with a status code 404. - If the request body is missing any of the required fields it responds with a status code 400.
[DELETE] /api/projects/:id
- Returns no response body.
- If there is no project with the given
id
it responds with a status code 404.
[GET] /api/projects/:id/actions
- Returns an array of actions (could be empty) belonging to a project with the given
id
. - If there is no project with the given
id
it responds with a status code 404.
- Returns an array of actions (could be empty) belonging to a project with the given
Inside api/actions/actions-router.js
are endpoints for performing CRUD operations on actions:
[GET] /api/actions
- Returns an array of actions (or an empty array) as the body of the response.
[GET] /api/actions/:id
- Returns an action with the given
id
as the body of the response. - If there is no action with the given
id
it responds with a status code 404.
- Returns an action with the given
[POST] /api/actions
- Returns the newly created action as the body of the response.
- If the request body is missing any of the required fields it responds with a status code 400.
- When adding an action make sure the
project_id
provided belongs to an existingproject
.
[PUT] /api/actions/:id
- Returns the updated action as the body of the response.
- If there is no action with the given
id
it responds with a status code 404. - If the request body is missing any of the required fields it responds with a status code 400.
[DELETE] /api/actions/:id
- Returns no response body.
- If there is no action with the given
id
it responds with a status code 404.
The description of the structure and extra information about each resource stored in the included database (./data/database.db3
) is listed below.
Field | Data Type | Metadata |
---|---|---|
id | number | do not provide it when creating projects, the database will generate it |
name | string | required |
description | string | required |
completed | boolean | not required, defaults to false when creating projects |
Field | Data Type | Metadata |
---|---|---|
id | number | do not provide it when creating actions, the database will generate it |
project_id | number | required, must be the id of an existing project |
description | string | required, up to 128 characters long |
notes | string | required, no size limit. Used to record additional notes or requirements to complete the action |
completed | boolean | not required, defaults to false when creating actions |
The project includes models to manage the persistence of project and action data. These files are api/projects/projects-model.js
and api/actions/actions-model.js
. Both files publish the following api, which can store, modify and retrieve each resource:
All these helper methods return a promise. Remember to use .then().catch() or async/await.
get()
: resolves to an array of all the resources contained in the database. If you pass anid
to this method it will return the resource with that id if one is found.insert()
: calling insert passing it a resource object will add it to the database and return the newly created resource.update()
: accepts two arguments, the first is theid
of the resource to update, and the second is an object with thechanges
to apply. It returns the updated resource. If a resource with the providedid
is not found, the method returnsnull
.remove()
: the remove method accepts anid
as its first parameter and, upon successfully deleting the resource from the database, returns the number of records deleted.
The projects-model.js
includes an extra method called getProjectActions()
that takes a project id as its only argument and returns a list of all the actions for the project.