UNPKG

paradigm-core

Version:
37 lines (22 loc) 649 B
module.exports = function schemaBulkUpdate(req, res, next) { try { const pkgs = req.body const bulkPkgs = [] for(let i = 0, l = pkgs.length; i < l; i++) { const pkg = pkgs[i] if(Object.keys(pkg).length > 0) { // Delete items that are joined keys, or keys that are created on a join delete pkg.categories delete pkg.featuredImage delete pkg.fields // This should not be sent via bulk delete pkg.user bulkPkgs.push(pkg) } } // Only worry about pkgs that have keys; skip blank pkgs req.body = bulkPkgs next() } catch(e) { next(e) } }