Skip to content
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

Return true/false result for destroyById/prototype.destroy #521

Closed
wants to merge 2 commits into from

Conversation

fabien
Copy link
Contributor

@fabien fabien commented Mar 20, 2015

See also: #321 - note that the memory connector has been fixed to have destroy also return { count: 1 } feedback - this should also be done with the other connectors.

/cc @raymondfeng @bajtos @superkhau

if ('function' === typeof cb) {
cb(err);
if (options.reportFailureAsError && !err && !deleted) {
Copy link
Member

Choose a reason for hiding this comment

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

Can we come up with a better name please? count === 0 is not a failure, it just mean that the record has been already deleted by somebody else before us.

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps options.failWhenNotFound, options.mustExist or options.strict.

Another approach is to use a property with true as a default value, e.g. options.ignoreMissing, options.lenient.

Copy link
Member

Choose a reason for hiding this comment

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

Also note that !deleted will be triggered also in the case when the connector does not report back the number of deleted records. You should use deleted === false instead.

@bajtos
Copy link
Member

bajtos commented Mar 20, 2015

The implementation looks good in general, I left a bunch of comments regarding details that I'd like to improve. @raymondfeng PTAL too.

@fabien
Copy link
Contributor Author

fabien commented Mar 20, 2015

@bajtos the flag I propose: strict

if ('function' === typeof cb) {
cb(err);
if (options.reportFailureAsError && !err && !deleted) {
err = new Error('No instance with id ' + id + ' found for ' + Model.modelName);
Copy link
Member

Choose a reason for hiding this comment

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

Please set an appropriate http status code via err.statusCode, e.g. "404 Not Found". This needs to be fixed in other places too.

@raymondfeng
Copy link
Contributor

Naming wise, I'm fine with with strict (default to false) or force (default to true).

@bajtos
Copy link
Member

bajtos commented Mar 20, 2015

@fabien the flag I propose: strict
@raymondfeng Naming wise, I'm fine with with strict (default to false) or force (default to true).

Let's go with strict (default to false) then.

@fabien
Copy link
Contributor Author

fabien commented Mar 20, 2015

@bajtos let me know if you want those commits squashed

@raymondfeng
Copy link
Contributor

Yes, please squash the commits.

BTW, do the tests have dependencies on connector implementations? Some of the tests from this module are also run with connectors.

@bajtos
Copy link
Member

bajtos commented Mar 24, 2015

Things to address:

  • the error objects should have a reasonable HTTP statusCode property and ideally also a machine-readable code. E.g. statusCode: 404, code: 'NOT_FOUND'
  • the callback argument should be an object ({ deleted: false }) for future extensibility as discussed in the comments above

I am not happy about the should.not.exist(err); pattern, but I am not going to repeat myself.

@bajtos
Copy link
Member

bajtos commented Mar 24, 2015

Note that some of the PRs that @superkhau is working on are changing the callback arguments from err, data to err, data, info. This patch may need to reflect that.

@raymondfeng
Copy link
Contributor

Now we settle the callback for updateAll and deleteAll to be cb(err, info).

if ('function' === typeof cb) {
cb(err);
if (options.strict && !err && !deleted) {
err = new Error('No instance with id ' + id + ' found for ' + Model.modelName);
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's do err.statusCode = 404.

@raymondfeng
Copy link
Contributor

@fabien ping.

@fabien
Copy link
Contributor Author

fabien commented Mar 30, 2015

@raymondfeng I'll see if I can work on this later.

@bajtos bajtos self-assigned this Apr 1, 2015
@bajtos bajtos added the waiting label Apr 9, 2015
@bajtos
Copy link
Member

bajtos commented Apr 16, 2015

@fabien I'll see if I can work on this later.

Ping, what's the status of this work? If you won't have time to work on this in the next few weeks, then I am proposing to close this pull request for now. You can always reopen it when you get more time.

@bajtos
Copy link
Member

bajtos commented May 29, 2015

Ping, what's the status of this work? If you won't have time to work on this in the next few weeks, then I am proposing to close this pull request for now. You can always reopen it when you get more time.

@fabien ping again. Would you mind if I close this pull request, since it seems to be abandoned?

/cc @raymondfeng

@bajtos
Copy link
Member

bajtos commented Aug 4, 2015

Closing in favour of #679.

@bajtos bajtos closed this Aug 4, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants