mirror of
https://github.com/JonasunderscoreJones/jonas_jones-api.git
synced 2025-10-24 01:29:19 +02:00
some progress
This commit is contained in:
parent
aea93a5527
commit
e3c15bd288
1388 changed files with 306946 additions and 68323 deletions
52
node_modules/mongoose/lib/helpers/model/applyDefaultsToPOJO.js
generated
vendored
Normal file
52
node_modules/mongoose/lib/helpers/model/applyDefaultsToPOJO.js
generated
vendored
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
'use strict';
|
||||
|
||||
module.exports = function applyDefaultsToPOJO(doc, schema) {
|
||||
const paths = Object.keys(schema.paths);
|
||||
const plen = paths.length;
|
||||
|
||||
for (let i = 0; i < plen; ++i) {
|
||||
let curPath = '';
|
||||
const p = paths[i];
|
||||
|
||||
const type = schema.paths[p];
|
||||
const path = type.splitPath();
|
||||
const len = path.length;
|
||||
let doc_ = doc;
|
||||
for (let j = 0; j < len; ++j) {
|
||||
if (doc_ == null) {
|
||||
break;
|
||||
}
|
||||
|
||||
const piece = path[j];
|
||||
curPath += (!curPath.length ? '' : '.') + piece;
|
||||
|
||||
if (j === len - 1) {
|
||||
if (typeof doc_[piece] !== 'undefined') {
|
||||
if (type.$isSingleNested) {
|
||||
applyDefaultsToPOJO(doc_[piece], type.caster.schema);
|
||||
} else if (type.$isMongooseDocumentArray && Array.isArray(doc_[piece])) {
|
||||
doc_[piece].forEach(el => applyDefaultsToPOJO(el, type.schema));
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
const def = type.getDefault(doc, false, { skipCast: true });
|
||||
if (typeof def !== 'undefined') {
|
||||
doc_[piece] = def;
|
||||
|
||||
if (type.$isSingleNested) {
|
||||
applyDefaultsToPOJO(def, type.caster.schema);
|
||||
} else if (type.$isMongooseDocumentArray && Array.isArray(def)) {
|
||||
def.forEach(el => applyDefaultsToPOJO(el, type.schema));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (doc_[piece] == null) {
|
||||
doc_[piece] = {};
|
||||
}
|
||||
doc_ = doc_[piece];
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue