@coolgk/mongo
Advanced tools
Comparing version 1.0.11 to 1.0.12
/*! | ||
* @package @coolgk/mongo | ||
* @version 1.0.11 | ||
* @version 1.0.12 | ||
* @link https://coolgk.github.io/mongodb-orm.html | ||
@@ -79,5 +79,2 @@ * @license MIT | ||
}; | ||
error?: { | ||
[action: string]: any; | ||
}; | ||
} | ||
@@ -84,0 +81,0 @@ export interface IUpdateOption extends FindOneAndReplaceOption { |
16
mongo.js
/*! | ||
* @package @coolgk/mongo | ||
* @version 1.0.11 | ||
* @version 1.0.12 | ||
* @link https://coolgk.github.io/mongodb-orm.html | ||
@@ -116,2 +116,3 @@ * @license MIT | ||
const dataBeforeUpdate = options.revertOnError ? yield this._collection.findOne({ _id: data._id }) : false; | ||
const errors = {}; | ||
for (const action of ['$set', '$push', '$pull']) { | ||
@@ -126,6 +127,3 @@ if (!queries[action]) { | ||
}, Object.assign({}, options, { arrayFilters: queries[action].arrayFilters })).catch((error) => { | ||
if (!results.error) { | ||
results.error = {}; | ||
} | ||
results.error[action] = error; | ||
errors[action] = error; | ||
})) || {}; | ||
@@ -141,10 +139,10 @@ if (options.returnOriginal) { | ||
} | ||
if (results.error) { | ||
if (Object.keys(errors).length) { | ||
if (options.revertOnError) { | ||
const revertResult = yield this._collection.findOneAndReplace({ _id: dataBeforeUpdate._id }, dataBeforeUpdate).catch((revertError) => { | ||
results.error.$revert = revertError; | ||
errors.$revert = revertError; | ||
}); | ||
} | ||
const error = new MongoError('UpdateOne Error: ' + JSON.stringify(results.error)); | ||
error.data = results; | ||
const error = new MongoError('UpdateOne Error: ' + JSON.stringify(errors)); | ||
error.data = Object.assign({}, results, { error: errors }); | ||
throw error; | ||
@@ -151,0 +149,0 @@ } |
@@ -1,1 +0,1 @@ | ||
{"name":"@coolgk/mongo","version":"1.0.11","description":"A javascript / typescript MongoDB modelling library which enables joins in collections, simplifies CRUD operations for sub / nested documents and implements schema based data validation","main":"./mongo.js","types":"./mongo.d.ts","dependencies":{"@coolgk/array":"^2.0.4","mongodb":"^3.0.3"},"author":"Daniel Gong <daniel.k.gong@gmail.com>","license":"MIT","bugs":{"url":"https://github.com/coolgk/node-mongo/issues"},"homepage":"https://coolgk.github.io/mongodb-orm.html","keywords":["mongo","MongoDB","orm","odm","relational","data validation","join"]} | ||
{"name":"@coolgk/mongo","version":"1.0.12","description":"A javascript / typescript MongoDB modelling library which enables joins in collections, simplifies CRUD operations for sub / nested documents and implements schema based data validation","main":"./mongo.js","types":"./mongo.d.ts","dependencies":{"@coolgk/array":"^2.0.4","mongodb":"^3.0.4"},"author":"Daniel Gong <daniel.k.gong@gmail.com>","license":"MIT","bugs":{"url":"https://github.com/coolgk/node-mongo/issues"},"homepage":"https://coolgk.github.io/mongodb-orm.html","keywords":["mongo","MongoDB","orm","odm","relational","data validation","join"]} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
61419
721
Updatedmongodb@^3.0.4