npm i -g npm
)npm install
.npm run resetdb
.npm test
.You will build an API that has Create, Read, Update and Delete (CRUD) functionality for two resources called projects
and actions
.
A "test" script already exists you can use to run tests against your code. A "resetdb" script exists that allows you to reset the database to its original state.
node
to run the API server.nodemon
to run the API server.process.env
variable, falling back to 9000
if process.env.PORT
is undefined !!!Inside api/projects/projects-router.js
build the following endpoints:
[GET] /api/projects
[GET] /api/projects/:id
id
as the body of the response.id
it responds with a status code 404.[POST] /api/projects
[PUT] /api/projects/:id
id
it responds with a status code 404.[DELETE] /api/projects/:id
id
it responds with a status code 404.[GET] /api/projects/:id/actions
id
.id
it responds with a status code 404.Inside api/actions/actions-router.js
build endpoints for performing CRUD operations on actions:
[GET] /api/actions
[GET] /api/actions/:id
id
as the body of the response.id
it responds with a status code 404.[POST] /api/actions
project_id
provided belongs to an existing project
.[PUT] /api/actions/:id
id
it responds with a status code 404.[DELETE] /api/actions/:id
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 you can use 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 you can use to 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 an id
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 the id
of the resource to update, and the second is an object with the changes
to apply. It returns the updated resource. If a resource with the provided id
is not found, the method returns null
.remove()
: the remove method accepts an id
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.
We have provided test data for all the resources.
Important Notes:
package.json
except to add additional dependencies and scripts. Do not update existing packages.HTTPie
, Postman
or Insomnia
to manually test the API's endpoints.