Closed alldayalone closed 4 years ago
I think we shouldn't add application specific logic to library. Especially since you can define custom service methods and use them instead of usual methods:
// db.js
db.setServiceMethod('softRemove', (service, query) => {
return service.atomic.update(
query,
{ $set: { deletedOn: new Date() } },
{ multi: true },
);
});
db.setServiceMethod('softRestore', (service, query) => {
return service.atomic.update(
query,
{ $unset: { deletedOn: '' } },
{ multi: true },
);
});
db.setServiceMethod('softFind', (service, query) => {
return service.find({ ...query, deletedOn: { $exists: false } });
});
{ soft: bool }
(defaultfalse
) to the createService options which opts on the featureremove
document makes update{ deletedOn: new Date() }
restore
which makes update{ $unset: { deletedOn: "" } }
{ soft: bool }
(defaulttrue
) to all query methods which adds{ deletedOn: { $exists: false } }
to the queryTo discuss:
restored
and adjust eventremoved