Skip to content

Implementation of add project functionality #85

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from

Conversation

JanviMahajan14
Copy link

fixes #80

@codecov
Copy link

codecov bot commented Mar 25, 2020

Codecov Report

Merging #85 into development will decrease coverage by 2.75%.
The diff coverage is 25.49%.

Impacted file tree graph

@@               Coverage Diff               @@
##           development      #85      +/-   ##
===============================================
- Coverage        55.07%   52.32%   -2.76%     
===============================================
  Files               16       17       +1     
  Lines              345      323      -22     
  Branches            41       45       +4     
===============================================
- Hits               190      169      -21     
+ Misses             131      123       -8     
- Partials            24       31       +7     
Impacted Files Coverage Δ
app/models/Project.js 23.80% <0.00%> (ø)
app/models/User.js 77.77% <ø> (ø)
app/controllers/project.js 5.12% <5.12%> (ø)
app.js 85.29% <100.00%> (+5.29%) ⬆️
app/routes/project.js 100.00% <100.00%> (ø)
app/models/Comment.js
app/models/Post.js
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 98ce23e...e15e017. Read the comment docs.

res.status(404).json({ error: error })
}
},
projectInfoUpdate: async (req, res, next) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its okay for crud update, but this is not how update works in realworld.

@@ -27,7 +27,7 @@ const projectSchema = new Schema({
if (validator.isEmpty(short)) {
throw new Error('Short description for the project is required!')
}
if (!validator.isLength(short)) {
if (!validator.isLength(short, { min: 10, max: undefined })) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

define max in constant and use here

},
projectDelete: async (req, res, next) => {
try {
const project = await Project.findByIdAndDelete({ _id: req.params.id })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets not delete and archive it

const router = express.Router()
const projectController = require('../controllers/project')

// create a project
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we know what get post put delete does here
comments are redundant

})

if (!isValidOperation) {
return res.status(400).json({ error: 'invalid update' })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use http status codes

await project.save()
res.send(project)
} catch (error) {
console.log(error)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JanviMahajan14 console.log only in env other than production environment.
So add if(process.env.NODE_ENV !== 'production'){ conso..... }

@vaibhavdaren
Copy link
Member

To do write unit tests for your api

Copy link
Member

@Rupeshiya Rupeshiya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JanviMahajan14 Please check comments

res.send(projects)
}
} catch (error) {
console.log(error)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same .

res.send(project)
}
} catch (error) {
console.log(error)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same .

try {
const project = await Project.findByIdAndDelete({ _id: req.params.id })
if (!project) {
throw new Error('No such project exists')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return res with status 404 and message

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rupeshiya Actually when I throw error it will move into the catch block and with return the status 404 and message also.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, yeah, I see

res.send(project)
}
} catch (error) {
console.log(error)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same .


// update a particular project info
router.patch(
'/:id',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change it to /update/:id


// delete a particular project
router.delete(
'/:id',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/delete/:id

@JanviMahajan14
Copy link
Author

@Rupeshiya @vaibhavdaren I have updated the changes. Pls have a look and let me know if any more changes are required

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implementing the add new project functionality
4 participants