Skip to content

Commit 6064e74

Browse files
committed
part 5d
1 parent 1fce1d0 commit 6064e74

File tree

34 files changed

+13170
-3
lines changed

34 files changed

+13170
-3
lines changed

part4/blog/app.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ app.use(
2929
app.use("/api/blogs", blogRouter);
3030
app.use("/api/users", userRouter);
3131
app.use("/api/login", loginRouter);
32+
if (process.env.NODE_ENV === "test") {
33+
const testingRouter = require("./controllers/testing");
34+
app.use("/api/testing", testingRouter);
35+
}
3236
app.use(middleware.unknownEndpoint);
3337
app.use(middleware.errorHandler);
3438

part4/blog/controllers/blog.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ blogRouter
5151
if (blog.user.toString() === user) {
5252
await Blog.findByIdAndRemove(req.params.id);
5353
res.status(204).end();
54+
} else {
55+
res.status(400).end();
5456
}
5557
})
5658
.put(async (req, res) => {

part4/blog/controllers/testing.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
var router = require("express").Router();
2+
var Blog = require("../models/blog");
3+
var User = require("../models/user");
4+
5+
router.post("/reset", async (req, res) => {
6+
await Blog.deleteMany({});
7+
await User.deleteMany({});
8+
9+
res.status(204).end();
10+
});
11+
12+
module.exports = router;

part4/blog/models/blog.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const uniqueValidator = require("mongoose-unique-validator");
44
const blogSchema = new mongoose.Schema({
55
title: { type: String },
66
author: { type: String },
7-
url: { type: String },
7+
url: String,
88
likes: { type: Number },
99
user: {
1010
type: mongoose.Schema.Types.ObjectId,

part4/blog/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"scripts": {
66
"start": "cross-env NODE_ENV=production node index.js",
77
"dev": "cross-env NODE_ENV=development nodemon index.js",
8-
"test": "cross-env NODE_ENV=test jest --verbose --runInBand"
8+
"test": "cross-env NODE_ENV=test jest --verbose --runInBand",
9+
"start:test": "cross-env NODE_ENV=test node index.js"
910
},
1011
"author": "Joseph Odunsi",
1112
"license": "MIT",

part4/blog/utils/middleware.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ require("dotenv").config();
22
const jwt = require("jsonwebtoken");
33

44
const errorHandler = (err, req, res, next) => {
5+
console.log(err);
56
if (process.env.NODE_ENV !== "test") {
67
console.log(err.message);
78
}
89

910
if (err.name === "CastError")
10-
return res.status(400).send({ error: "err.message" });
11+
return res.status(400).send({ error: err.message });
1112

1213
if (err.name === "ValidationError") {
1314
return res.status(400).json({ error: err.message });
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/* eslint-env node */
2+
module.exports = {
3+
env: {
4+
browser: true,
5+
es6: true,
6+
"jest/globals": true,
7+
"cypress/globals": true,
8+
},
9+
extends: ["eslint:recommended", "plugin:react/recommended"],
10+
parserOptions: {
11+
ecmaFeatures: {
12+
jsx: true,
13+
},
14+
ecmaVersion: 2020,
15+
sourceType: "module",
16+
},
17+
plugins: ["react", "jest", "cypress"],
18+
rules: {
19+
"no-console": "warn",
20+
indent: ["error", 2],
21+
"linebreak-style": ["error", "unix"],
22+
quotes: ["error", "double"],
23+
semi: ["error", "always"],
24+
eqeqeq: "error",
25+
"no-trailing-spaces": "error",
26+
"object-curly-spacing": ["error", "always"],
27+
"arrow-spacing": ["error", { before: true, after: true }],
28+
"no-console": 0,
29+
"react/prop-types": 0,
30+
},
31+
settings: {
32+
react: {
33+
version: "detect",
34+
},
35+
},
36+
};

part5/bloglist-frontend/.gitignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# production
12+
/build
13+
14+
# misc
15+
.DS_Store
16+
.env.local
17+
.env.development.local
18+
.env.test.local
19+
.env.production.local
20+
21+
npm-debug.log*
22+
yarn-debug.log*
23+
yarn-error.log*
24+
.eslintcache

part5/bloglist-frontend/README.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Getting Started with Create React App
2+
3+
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
4+
5+
## Available Scripts
6+
7+
In the project directory, you can run:
8+
9+
### `npm start`
10+
11+
Runs the app in the development mode.\
12+
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
13+
14+
The page will reload if you make edits.\
15+
You will also see any lint errors in the console.
16+
17+
### `npm test`
18+
19+
Launches the test runner in the interactive watch mode.\
20+
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
21+
22+
### `npm run build`
23+
24+
Builds the app for production to the `build` folder.\
25+
It correctly bundles React in production mode and optimizes the build for the best performance.
26+
27+
The build is minified and the filenames include the hashes.\
28+
Your app is ready to be deployed!
29+
30+
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
31+
32+
### `npm run eject`
33+
34+
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
35+
36+
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
37+
38+
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
39+
40+
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
41+
42+
## Learn More
43+
44+
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
45+
46+
To learn React, check out the [React documentation](https://reactjs.org/).
47+
48+
### Code Splitting
49+
50+
This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)
51+
52+
### Analyzing the Bundle Size
53+
54+
This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)
55+
56+
### Making a Progressive Web App
57+
58+
This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)
59+
60+
### Advanced Configuration
61+
62+
This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)
63+
64+
### Deployment
65+
66+
This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
67+
68+
### `npm run build` fails to minify
69+
70+
This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

0 commit comments

Comments
 (0)