Refactoring day1

This commit is contained in:
2020-08-20 20:27:14 +02:00
parent 6aceefeb2f
commit b907489a75
481 changed files with 5321 additions and 5616 deletions

View File

@@ -37,12 +37,8 @@ module.exports = function castBulkWrite(originalModel, op, options) {
} else if (op['updateOne']) {
return (callback) => {
try {
if (!op['updateOne']['filter']) {
throw new Error('Must provide a filter object.');
}
if (!op['updateOne']['update']) {
throw new Error('Must provide an update object.');
}
if (!op['updateOne']['filter']) throw new Error('Must provide a filter object.');
if (!op['updateOne']['update']) throw new Error('Must provide an update object.');
const model = decideModelByObject(originalModel, op['updateOne']['filter']);
const schema = model.schema;
@@ -58,6 +54,7 @@ module.exports = function castBulkWrite(originalModel, op, options) {
applyTimestampsToChildren(now, op['updateOne']['update'], model.schema);
if (op['updateOne'].setDefaultsOnInsert) {
setDefaultsOnInsert(op['updateOne']['filter'], model.schema, op['updateOne']['update'], {
setDefaultsOnInsert: true,
@@ -74,7 +71,8 @@ module.exports = function castBulkWrite(originalModel, op, options) {
strict: strict,
overwrite: false,
upsert: op['updateOne'].upsert
}, model, op['updateOne']['filter']);
});
} catch (error) {
return callback(error, null);
}
@@ -84,12 +82,8 @@ module.exports = function castBulkWrite(originalModel, op, options) {
} else if (op['updateMany']) {
return (callback) => {
try {
if (!op['updateMany']['filter']) {
throw new Error('Must provide a filter object.');
}
if (!op['updateMany']['update']) {
throw new Error('Must provide an update object.');
}
if (!op['updateMany']['filter']) throw new Error('Must provide a filter object.');
if (!op['updateMany']['update']) throw new Error('Must provide an update object.');
const model = decideModelByObject(originalModel, op['updateMany']['filter']);
const schema = model.schema;
@@ -121,7 +115,7 @@ module.exports = function castBulkWrite(originalModel, op, options) {
strict: strict,
overwrite: false,
upsert: op['updateMany'].upsert
}, model, op['updateMany']['filter']);
});
} catch (error) {
return callback(error, null);
@@ -159,7 +153,6 @@ module.exports = function castBulkWrite(originalModel, op, options) {
if (error) {
return callback(error, null);
}
op['replaceOne']['replacement'] = op['replaceOne']['replacement'].toBSON();
callback(null);
});
};

View File

@@ -149,17 +149,11 @@ module.exports = function discriminator(model, name, schema, tiedValue, applyPlu
for (const _key of keys) {
if (!CUSTOMIZABLE_DISCRIMINATOR_OPTIONS[_key]) {
// Special case: compiling a model sets `pluralization = true` by default. Avoid throwing an error
// for that case. See gh-9238
if (_key === 'pluralization' && schema.options[_key] == true && baseSchema.options[_key] == null) {
continue;
}
if (!utils.deepEqual(schema.options[_key], baseSchema.options[_key])) {
throw new Error('Can\'t customize discriminator option ' + _key +
' (can only modify ' +
Object.keys(CUSTOMIZABLE_DISCRIMINATOR_OPTIONS).join(', ') +
')');
' (can only modify ' +
Object.keys(CUSTOMIZABLE_DISCRIMINATOR_OPTIONS).join(', ') +
')');
}
}
}