Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<span class="badge-travisci"><a href="http://travis-ci.org/jouke/loopback-auditz" title="Check this project's build status on TravisCI"><img src="https://img.shields.io/travis/jouke/loopback-auditz/master.svg" alt="Travis CI Build Status" /></a></span>
<span class="badge-npmversion"><a href="https://npmjs.org/package/loopback-auditz" title="View this project on NPM"><img src="https://img.shields.io/npm/v/loopback-auditz.svg" alt="NPM version" /></a></span>
<span class="badge-npmdownloads"><a href="https://npmjs.org/package/loopback-auditz" title="View this project on NPM"><img src="https://img.shields.io/npm/dm/loopback-auditz.svg" alt="NPM downloads" /></a></span>
<span class="badge-coveralls"><a href="https://coveralls.io/r/jouke/loopback-auditz" title="View this project's coverage on Coveralls"><img src="https://img.shields.io/coveralls/jouke/loopback-auditz.svg" alt="Coverage Status" /></a></span>
<span class="badge-coveralls"><a href="https://coveralls.io/r/jouke/loopback-auditz" title="View this project's coverage on Coveralls"><img src="https://img.shields.io/coveralls/jouke/loopback-auditz.svg" alt="Coveralls Coverage Status" /></a></span>
<span class="badge-daviddm"><a href="https://david-dm.org/jouke/loopback-auditz" title="View the status of this project's dependencies on DavidDM"><img src="https://img.shields.io/david/jouke/loopback-auditz.svg" alt="Dependency Status" /></a></span>
<span class="badge-daviddmdev"><a href="https://david-dm.org/jouke/loopback-auditz#info=devDependencies" title="View the status of this project's development dependencies on DavidDM"><img src="https://img.shields.io/david/dev/jouke/loopback-auditz.svg" alt="Dev Dependency Status" /></a></span>

Expand Down
32 changes: 18 additions & 14 deletions src/auditz.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import _debug from './debug';

import loopackUtils from 'loopback/lib/utils';
const debug = _debug();
const warn = (options, ...rest) => {
if (!options.silenceWarnings) {
Expand Down Expand Up @@ -319,40 +319,44 @@ export default (Model, bootOptions = {}) => {
if (options.softDelete) {
Model.destroyAll = function softDestroyAll(where, cb) {
let query = where || {};
let callback = cb;
let callback = cb || loopackUtils.createPromiseCallback();
if (typeof where === 'function') {
callback = where;
query = {};
}
return Model.updateAll(query, { ...scrubbed }, {delete: true})
.then(result => (typeof callback === 'function') ? callback(null, result) : result)
.catch(error => (typeof callback === 'function') ? callback(error) : Promise.reject(error));
Model.updateAll(query, { ...scrubbed }, {delete: true})
.then(result => callback(null, result))
.catch(error => callback(error));
return callback.promise;
};

Model.remove = Model.destroyAll;
Model.deleteAll = Model.destroyAll;

Model.destroyById = function softDestroyById(id, opt, cb) {
const callback = (cb === undefined && typeof opt === 'function') ? opt : cb;
let callback = (cb === undefined && typeof opt === 'function') ? opt : cb;
callback = callback || loopackUtils.createPromiseCallback();
let newOpt = {delete: true};
if (typeof opt === 'object') {
newOpt.remoteCtx = opt.remoteCtx;
}

return Model.updateAll({ [idName]: id }, { ...scrubbed}, newOpt)
.then(result => (typeof callback === 'function') ? callback(null, result) : result)
.catch(error => (typeof callback === 'function') ? callback(error) : Promise.reject(error));
Model.updateAll({ [idName]: id }, { ...scrubbed}, newOpt)
.then(result => callback(null, result))
.catch(error => callback(error));
return callback.promise;
};

Model.removeById = Model.destroyById;
Model.deleteById = Model.destroyById;

Model.prototype.destroy = function softDestroy(opt, cb) {
const callback = (cb === undefined && typeof opt === 'function') ? opt : cb;

return this.updateAttributes({ ...scrubbed }, {delete: true})
.then(result => (typeof cb === 'function') ? callback(null, result) : result)
.catch(error => (typeof cb === 'function') ? callback(error) : Promise.reject(error));
let callback = (cb === undefined && typeof opt === 'function') ? opt : cb;
callback = callback || loopackUtils.createPromiseCallback();
this.updateAttributes({ ...scrubbed }, {delete: true})
.then(result => callback(null, result))
.catch(error => callback(error));
return callback.promise;
};

Model.prototype.remove = Model.prototype.destroy;
Expand Down