Feature: Delete a project
As a vision user I want to delete a project So that I can remove projects no longer in use
Let's add a test to ./test/project.js
for our feature Delete a project
. This resource will DELETE a project at route /project/:id
and return a 204 No Content
status:
describe('when deleting an existing resource /project/:id', function(){ it('should respond with 204', function(done){ request(app) .del('/project/' + id) .expect(204, done); }); });
Let's implement the Delete a project
feature ./lib/project/index.js
and add a del
function. We attempt to delete a project by calling the static function Project.findOne
. If we get an error, we return it; if we cannot find the project, we return null
. If we find the project, we delete it and return an empty response.
Project.prototype.del = function(id, callback){ var query = {'_id': id}; ProjectSchema.findOne(query, function(error, project) { if (error) return callback(error, null); if (project == null) return...