MCPcopy Create free account
hub / github.com/CloudBoost/cloudboost / _rollBack

Function _rollBack

services/cloudObjects.js:1229–1267  ·  view source on GitHub ↗
(appId, status, docsArray, oldDocs)

Source from the content-addressed store, hash-verified

1227}
1228
1229function _rollBack(appId, status, docsArray, oldDocs) {
1230 const deferred = q.defer();
1231
1232 try {
1233 oldDocs = _attachSchema(docsArray, oldDocs);
1234 const promises = [];
1235 const arr = [];
1236 if (status[0].state === 'fulfilled') {
1237 if (oldDocs) promises.push(mongoService.document.save(appId, oldDocs));
1238 else {
1239 for (let i = 0; i < docsArray.length; i++) {
1240 promises.push(mongoService.delete(appId, docsArray[i]._tableName, docsArray[i]));
1241 }
1242 }
1243 arr.push('Mongo');
1244 }
1245
1246 q.allSettled(promises).then((res) => {
1247 let status = true;
1248 for (let i = 0; i < res.length; i++) {
1249 if (res[i].state !== 'fulfilled') {
1250 status = false;
1251 deferred.reject();
1252 break;
1253 }
1254 }
1255 if (status === true) {
1256 deferred.resolve();
1257 }
1258 });
1259 } catch (err) {
1260 winston.log('error', {
1261 error: String(err),
1262 stack: new Error().stack,
1263 });
1264 deferred.reject(err);
1265 }
1266 return deferred.promise;
1267}
1268
1269function _seperateDocs(listOfDocs) {
1270 try {

Callers 1

_saveFunction · 0.85

Calls 3

_attachSchemaFunction · 0.85
saveMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected