Skip to content

Commit

Permalink
Merge pull request #364 from sarkistlt/patch-1
Browse files Browse the repository at this point in the history
update '_remove' method
  • Loading branch information
marshallswain committed Jan 8, 2020
2 parents 7aed505 + dd5895e commit 5fbe560
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions lib/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,33 +304,32 @@ class Service extends AdapterService {
query.collation = params.collation;
}

if (id !== null) {
query.$and = (query.$and || []).concat({ [this.id]: id });

return this.Model.findOneAndDelete(query, params.mongoose).lean(this.lean)
.exec().then(result => {
if (result === null) {
throw new errors.NotFound(`No record found for id '${id}'`, query);
}

return result;
}).then(select(params, this.id)).catch(errorHandler);
}

const findParams = Object.assign({}, params, {
paginate: false,
query
});

if (id !== null) {
query.$and = (query.$and || []).concat({ [this.id]: id });
}

// NOTE (EK): First fetch the record(s) so that we can return
// it/them when we delete it/them.
return this._getOrFind(id, findParams).then(data =>
this.Model.deleteMany(query, params.mongoose)
return this._getOrFind(id, findParams).then((data) => {
if (id !== null) {
return this.Model.deleteOne(query, params.mongoose)
.lean(this.lean)
.exec()
.then(() => data)
.then(select(params, this.id));
}

return this.Model.deleteMany(query, params.mongoose)
.lean(this.lean)
.exec()
.then(() => data)
.then(select(params, this.id))
).catch(errorHandler);
.then(select(params, this.id));
}).catch(errorHandler);
}
}

Expand Down

0 comments on commit 5fbe560

Please sign in to comment.