lucis-api-query
Advanced tools
Comparing version 0.1.0 to 0.5.1
28
index.js
@@ -0,1 +1,3 @@ | ||
const jsonpatch = require('fast-json-patch'); | ||
function pluginMongoose (schema) { | ||
@@ -245,2 +247,28 @@ | ||
}; | ||
/** | ||
* Be careful: some patches may not be applied to mongoose model (deleting stuff, e.g) | ||
*/ | ||
schema.statics.findByIdAndPatch = function(entidadeId, patches, callback){ | ||
this.findById(entidadeId) | ||
.exec((err, entidade)=>{ | ||
if (err){ | ||
return callback(err); | ||
} | ||
jsonpatch.apply(entidade,patches); | ||
const validacao = entidade.validateSync(); | ||
if (validacao){ | ||
const erro = Object.values(validacao.errors)[0]; | ||
return callback(erro); | ||
} | ||
entidade.save((err)=>{ | ||
if (err){ | ||
return callback(err); | ||
} | ||
return callback | ||
}); | ||
}); | ||
}; | ||
}; | ||
@@ -247,0 +275,0 @@ |
{ | ||
"name": "lucis-api-query", | ||
"version": "0.1.0", | ||
"version": "0.5.1", | ||
"description": "Adaptação do mongoose-api-query para necessidades mais comuns", | ||
@@ -10,3 +10,6 @@ "main": "index.js", | ||
"author": "Luciano Júnior <luciannojunior@gmail.com> (http://juniorluciano.com)", | ||
"license": "ISC" | ||
"license": "ISC", | ||
"dependencies": { | ||
"fast-json-patch": "^2.0.6" | ||
} | ||
} |
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
15412
286
1
+ Addedfast-json-patch@^2.0.6
+ Addedfast-deep-equal@2.0.1(transitive)
+ Addedfast-json-patch@2.2.1(transitive)