UNPKG

@axway/api-builder-plugin-dc-mbs

Version:

Mobile Backend Services connector

37 lines (34 loc) 905 B
const { getTranslatedError } = require('../utils'); function deleteAll(Model, next) { this.logger.trace('MBS.deleteAll', { model: Model.name }); // MBS delete does not return the number of objects deleted, so get the // count before we delete. this.count(Model, {}, (countErr, count) => { if (countErr) { // Error is already safe return next(countErr); } if (!count) { return next(null, 0); } this.db.customObjectsBatchDelete({ classname: Model.name }, (err, response) => { if (err) { // Do not expose `err` via callback (information disclosure) return next(getTranslatedError(this, err)); } if (response.body.meta.code === 200) { // return the affected instance this.logger.trace(`MBS deleted ${count} records`); return next(null, count); } else { // not found return next(null, 0); } }); }); } module.exports = { deleteAll };