Skip to content

Commit 52e37bf

Browse files
committed
initial
0 parents  commit 52e37bf

24 files changed

+10617
-0
lines changed

.eslintrc.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"env": {
3+
"commonjs": true,
4+
"es2021": true,
5+
"node": true,
6+
"jest": true
7+
},
8+
"extends": "eslint:recommended",
9+
"parserOptions": {
10+
"ecmaVersion": "latest"
11+
},
12+
"rules": {
13+
}
14+
}

.github/lockdown.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# PLEASE DO NOT REMOVE THIS FILE
2+
3+
# Configuration for Repo Lockdown - https://github.com/dessant/repo-lockdown
4+
5+
# Skip issues and pull requests created before a given timestamp. Timestamp must
6+
# follow ISO 8601 (`YYYY-MM-DD`). Set to `false` to disable
7+
skipCreatedBefore: false
8+
9+
# Issues and pull requests with these labels will be ignored. Set to `[]` to disable
10+
exemptLabels: []
11+
12+
# Comment to post before closing or locking. Set to `false` to disable
13+
comment: false
14+
15+
# Label to add before closing or locking. Set to `false` to disable
16+
label: false
17+
18+
# Close issues and pull requests
19+
close: true
20+
21+
# Lock issues and pull requests
22+
lock: true
23+
24+
# Limit to only `issues` or `pulls`
25+
only: pulls
26+
# Optionally, specify configuration settings just for `issues` or `pulls`
27+
# issues:
28+
# label: wontfix
29+
30+
# pulls:
31+
# comment: >
32+
# This repository does not accept pull requests, see the README for details.
33+
# lock: false
34+
35+
# Repository to extend settings from
36+
# _extends: repo

.gitignore

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Mac files
2+
.DS_Store
3+
4+
# VSCode settings
5+
.vscode/
6+
7+
# Logs
8+
logs
9+
*.log
10+
npm-debug.log*
11+
yarn-debug.log*
12+
yarn-error.log*
13+
lerna-debug.log*
14+
15+
# Diagnostic reports (https://nodejs.org/api/report.html)
16+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
17+
18+
# Runtime data
19+
pids
20+
*.pid
21+
*.seed
22+
*.pid.lock
23+
24+
# Directory for instrumented libs generated by jscoverage/JSCover
25+
lib-cov
26+
27+
# Coverage directory used by tools like istanbul
28+
coverage
29+
30+
# nyc test coverage
31+
.nyc_output
32+
33+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
34+
.grunt
35+
36+
# Bower dependency directory (https://bower.io/)
37+
bower_components
38+
39+
# node-waf configuration
40+
.lock-wscript
41+
42+
# Compiled binary addons (https://nodejs.org/api/addons.html)
43+
build/Release
44+
45+
# Dependency directories
46+
node_modules/
47+
jspm_packages/
48+
49+
# TypeScript v1 declaration files
50+
typings/
51+
52+
# Optional npm cache directory
53+
.npm
54+
55+
# Optional eslint cache
56+
.eslintcache
57+
58+
# Optional REPL history
59+
.node_repl_history
60+
61+
# Output of 'npm pack'
62+
*.tgz
63+
64+
# Yarn Integrity file
65+
.yarn-integrity
66+
67+
# dotenv environment variables file
68+
.env
69+
.env.test
70+
71+
# parcel-bundler cache (https://parceljs.org/)
72+
.cache
73+
74+
# next.js build output
75+
.next
76+
77+
# nuxt.js build output
78+
.nuxt
79+
80+
# vuepress build output
81+
.vuepress/dist
82+
83+
# Serverless directories
84+
.serverless/
85+
86+
# FuseBox cache
87+
.fusebox/
88+
89+
# DynamoDB Local files
90+
.dynamodb/
91+
92+
# databases
93+
*.db3

README.md

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
# Sprint Challenge Instructions
2+
3+
**Read these instructions carefully. Understand exactly what is expected _before_ starting this Sprint Challenge.**
4+
5+
This challenge allows you to practice the concepts and techniques learned over the past sprint and apply them in a concrete project. This sprint explored **how to build web services based on the REST (REpresentational State Transfer) architectural style**. During this sprint, you studied **Node.js and Express, server side routing, how to write Express middleware and how to deploy an API to Heroku**.
6+
7+
In your challenge this week, you will demonstrate your mastery of these skills by designing and creating a web API to manage the following resources: `Projects` and `Actions`.
8+
9+
This is an individual assessment. All work must be your own. All projects will be submitted to Codegrade for automated review. You will also be given feedback by code reviewers the Monday after challenge submissions. For more information on the review process [click here](https://www.notion.so/bloomtech/How-to-View-Feedback-in-CodeGrade-c5147cee220c4044a25de28bcb6bb54a).
10+
11+
You are not allowed to collaborate during the sprint challenge.
12+
13+
## Introduction
14+
15+
In meeting the minimum viable product (MVP) specifications listed below, your project should provide an API that has Create, Read, Update and Delete (CRUD) functionality for both `projects` and `actions`.
16+
17+
## Instructions
18+
19+
### Task 1: Project Set Up
20+
21+
- [ ] Run `npm install` to install your dependencies.
22+
- [ ] Run tests locally executing `npm test`.
23+
- [ ] Reset the database to its original state executing `npm run resetdb`.
24+
25+
### Task 2: Project Requirements (MVP)
26+
27+
Your finished project must include all of the following requirements:
28+
29+
#### NPM Scripts
30+
31+
A _"test"_ script already exists you can use to run tests against your code.
32+
A _"resetdb"_ script exists that allows you to reset the database to its original state.
33+
34+
- [ ] Write an _npm script_ named _"start"_ that uses `node` to run the API server.
35+
- [ ] Write an _npm script_ named _"server"_ that uses `nodemon` to run the API server.
36+
- [ ] Install _nodemon_ as a development dependency that would not be used in production.
37+
38+
#### Environment Variables
39+
40+
- [ ] Bring the port number from the `process.env` variable, falling back to `9000` if `process.env.PORT` is undefined **!!!**
41+
42+
#### Endpoints
43+
44+
Inside `api/projects/projects-router.js` build the following endpoints:
45+
46+
- [ ] `[GET] /api/projects`
47+
- Returns an array of projects as the body of the response.
48+
- If there are no projects it responds with an empty array.
49+
- [ ] `[GET] /api/projects/:id`
50+
- Returns a project with the given `id` as the body of the response.
51+
- If there is no project with the given `id` it responds with a status code 404.
52+
- [ ] `[POST] /api/projects`
53+
- Returns the newly created project as the body of the response.
54+
- If the request body is missing any of the required fields it responds with a status code 400.
55+
- [ ] `[PUT] /api/projects/:id`
56+
- Returns the updated project as the body of the response.
57+
- If there is no project with the given `id` it responds with a status code 404.
58+
- If the request body is missing any of the required fields it responds with a status code 400.
59+
- [ ] `[DELETE] /api/projects/:id`
60+
- Returns no response body.
61+
- If there is no project with the given `id` it responds with a status code 404.
62+
- [ ] `[GET] /api/projects/:id/actions`
63+
- Returns an array of actions (could be empty) belonging to a project with the given `id`.
64+
- If there is no project with the given `id` it responds with a status code 404.
65+
66+
Inside `api/actions/actions-router.js` build endpoints for performing CRUD operations on _actions_:
67+
68+
- [ ] `[GET] /api/actions`
69+
- Returns an array of actions (or an empty array) as the body of the response.
70+
- [ ] `[GET] /api/actions/:id`
71+
- Returns an action with the given `id` as the body of the response.
72+
- If there is no action with the given `id` it responds with a status code 404.
73+
- [ ] `[POST] /api/actions`
74+
- Returns the newly created action as the body of the response.
75+
- If the request body is missing any of the required fields it responds with a status code 400.
76+
- When adding an action make sure the `project_id` provided belongs to an existing `project`.
77+
- [ ] `[PUT] /api/actions/:id`
78+
- Returns the updated action as the body of the response.
79+
- If there is no action with the given `id` it responds with a status code 404.
80+
- If the request body is missing any of the required fields it responds with a status code 400.
81+
- [ ] `[DELETE] /api/actions/:id`
82+
- Returns no response body.
83+
- If there is no action with the given `id` it responds with a status code 404.
84+
85+
#### Middleware functions
86+
87+
- [ ] Write at least two middleware functions for this API, and consume them in the proper places of your code.
88+
89+
### Database Schemas
90+
91+
The description of the structure and extra information about each _resource_ stored in the included database (`./data/database.db3`) is listed below.
92+
93+
#### Projects
94+
95+
| Field | Data Type | Metadata |
96+
| ----------- | --------- | --------------------------------------------------------------------------- |
97+
| id | number | do not provide it when creating projects, the database will generate it |
98+
| name | string | required |
99+
| description | string | required |
100+
| completed | boolean | not required, defaults to false when creating projects |
101+
102+
#### Actions
103+
104+
| Field | Data Type | Metadata |
105+
| ----------- | --------- | ------------------------------------------------------------------------------------------------ |
106+
| id | number | do not provide it when creating actions, the database will generate it |
107+
| project_id | number | required, must be the id of an existing project |
108+
| description | string | required, up to 128 characters long |
109+
| notes | string | required, no size limit. Used to record additional notes or requirements to complete the action |
110+
| completed | boolean | not required, defaults to false when creating actions |
111+
112+
### Database Persistence Helpers
113+
114+
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:
115+
116+
**All these helper methods return a promise. Remember to use .then().catch() or async/await.**
117+
118+
- `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.
119+
- `insert()`: calling insert passing it a resource object will add it to the database and return the newly created resource.
120+
- `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`.
121+
- `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.
122+
123+
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_.
124+
125+
We have provided test data for all the resources.
126+
127+
**Important Notes:**
128+
129+
- Do not make changes to your `package.json` except to add **additional** dependencies and scripts. Do not update existing packages.
130+
- Your app must be able to run in Node v.12. Do not use newer features of Node (e.g.: optional chaining and nullish coalescing NOT supported).
131+
- Use an HTTP client like `HTTPie`, `Postman` or `Insomnia` to manually test the API's endpoints.
132+
- Use Express Routers to organize your endpoints.
133+
- Even though you are only required to write two middleware functions, it is advised that you leverage middlewares as much as possible.
134+
- You are welcome to create additional files, but **do not move or rename existing files** or folders.
135+
- In your solution, it is essential that you follow best practices and produce clean and professional results.
136+
- Schedule time to review, refine, and assess your work and perform basic professional polishing including spell-checking and grammar-checking on your work.
137+
138+
## Submission format
139+
140+
- [ ] Submit via Codegrade by pushing commits to your `main` branch.
141+
- [ ] Check Codegrade before the deadline to compare its results against your local tests.
142+
- [ ] Check Codegrade on the days following the Sprint Challenge for reviewer feedback.
143+
- [ ] New commits will be evaluated by Codegrade if pushed _before_ the sprint challenge deadline.
144+
145+
## Interview Questions
146+
147+
Be prepared to demonstrate your understanding of this week's concepts by answering questions on the following topics. You might prepare by writing down your own answers before hand.
148+
149+
1. The core features of Node.js and Express and why they are useful.
150+
1. Understand and explain the use of Middleware.
151+
1. The basic principles of the REST architectural style.
152+
1. Understand and explain the use of Express Routers.
153+
1. Describe tooling used to manually test the correctness of an API.

api/actions/actions-middlware.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// add middlewares here related to actions

api/actions/actions-model.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// DO NOT MAKE CHANGES TO THIS FILE
2+
const db = require('../../data/dbConfig.js');
3+
const mappers = require('../../data/helpers/mappers');
4+
5+
module.exports = {
6+
get,
7+
insert,
8+
update,
9+
remove,
10+
};
11+
12+
function get(id) {
13+
let query = db('actions');
14+
15+
if (id) {
16+
return query
17+
.where('id', id)
18+
.first()
19+
.then((action) => {
20+
if (action) {
21+
return mappers.actionToBody(action);
22+
} else {
23+
return null;
24+
}
25+
});
26+
} else {
27+
return query.then((actions) => {
28+
return actions.map((action) => mappers.actionToBody(action));
29+
});
30+
}
31+
}
32+
33+
function insert(action) {
34+
return db('actions')
35+
.insert(action)
36+
.then(([id]) => get(id));
37+
}
38+
39+
function update(id, changes) {
40+
return db('actions')
41+
.where('id', id)
42+
.update(changes)
43+
.then((count) => (count > 0 ? get(id) : null));
44+
}
45+
46+
function remove(id) {
47+
return db('actions').where('id', id).del();
48+
}

api/actions/actions-router.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// Write your "actions" router here!

api/projects/projects-middleware.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// add middlewares here related to projects

0 commit comments

Comments
 (0)