-
-
Notifications
You must be signed in to change notification settings - Fork 58
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
Conversation
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
res.status(404).json({ error: error }) | ||
} | ||
}, | ||
projectInfoUpdate: async (req, res, next) => { |
There was a problem hiding this comment.
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.
app/models/Project.js
Outdated
@@ -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 })) { |
There was a problem hiding this comment.
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 }) |
There was a problem hiding this comment.
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
app/routes/project.js
Outdated
const router = express.Router() | ||
const projectController = require('../controllers/project') | ||
|
||
// create a project |
There was a problem hiding this comment.
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' }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use http status codes
app/controllers/project.js
Outdated
await project.save() | ||
res.send(project) | ||
} catch (error) { | ||
console.log(error) |
There was a problem hiding this comment.
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..... }
To do write unit tests for your api |
There was a problem hiding this 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
app/controllers/project.js
Outdated
res.send(projects) | ||
} | ||
} catch (error) { | ||
console.log(error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same .
app/controllers/project.js
Outdated
res.send(project) | ||
} | ||
} catch (error) { | ||
console.log(error) |
There was a problem hiding this comment.
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') |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, yeah, I see
app/controllers/project.js
Outdated
res.send(project) | ||
} | ||
} catch (error) { | ||
console.log(error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same .
app/routes/project.js
Outdated
|
||
// update a particular project info | ||
router.patch( | ||
'/:id', |
There was a problem hiding this comment.
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
app/routes/project.js
Outdated
|
||
// delete a particular project | ||
router.delete( | ||
'/:id', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/delete/:id
@Rupeshiya @vaibhavdaren I have updated the changes. Pls have a look and let me know if any more changes are required |
fixes #80