you can use the beforeFind () life cycle function to filter soft deleted records
model: parrot js
module.exports = { attributes: { // eg, "Polly" name: { type: 'string' }, // eg, 3.26 wingspan: { type: 'float', required: true }, // eg, "cm" wingspanUnits: { type: 'string', enum: ['cm', 'in', 'm', 'mm'], defaultsTo: 'cm' }, // eg, [{...}, {...}, ...] knownDialects: { collection: 'Dialect' }, isDeleted:{ type:'boolean' } }, beforeFind: function(values, cb) { values.isDeleted = false; cb(); } }
ParrotController.js
module.exports = { // getting default parrots isDeleted = true list: function (req, res) { Parrot .find() .exec(function(err, parrots) { if(err) return res.send({ flag:false, data:[], message:"Error." }); if(parrots && parrots.length){ return res.send({ flag:true, data:parrots, message:"Success." }); } else{ return res.send({ flag:false, data:[], message:"Parrot list is empty." }); } }); } };
source share