-
Notifications
You must be signed in to change notification settings - Fork 362
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
Conversation
if ('function' === typeof cb) { | ||
cb(err); | ||
if (options.reportFailureAsError && !err && !deleted) { |
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.
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.
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.
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
.
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.
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.
The implementation looks good in general, I left a bunch of comments regarding details that I'd like to improve. @raymondfeng PTAL too. |
@bajtos the flag I propose: |
if ('function' === typeof cb) { | ||
cb(err); | ||
if (options.reportFailureAsError && !err && !deleted) { | ||
err = new Error('No instance with id ' + id + ' found for ' + Model.modelName); |
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.
Please set an appropriate http status code via err.statusCode
, e.g. "404 Not Found". This needs to be fixed in other places too.
Naming wise, I'm fine with with |
Let's go with |
@bajtos let me know if you want those commits squashed |
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. |
Things to address:
I am not happy about the |
Note that some of the PRs that @superkhau is working on are changing the callback arguments from |
Now we settle the callback for |
if ('function' === typeof cb) { | ||
cb(err); | ||
if (options.strict && !err && !deleted) { | ||
err = new Error('No instance with id ' + id + ' found for ' + Model.modelName); |
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.
Let's do err.statusCode = 404
.
@fabien ping. |
@raymondfeng 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. |
@fabien ping again. Would you mind if I close this pull request, since it seems to be abandoned? /cc @raymondfeng |
Closing in favour of #679. |
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