Skip to content

Commit

Permalink
refactor: create separate helper to get strictQuery re: code review c…
Browse files Browse the repository at this point in the history
…omments
  • Loading branch information
vkarpov15 committed Oct 20, 2022
1 parent 6f16056 commit d595544
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions lib/cast.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,15 +264,7 @@ module.exports = function cast(schema, obj, options, context) {
}

const strict = 'strict' in options ? options.strict : schema.options.strict;
const strictQuery = 'strictQuery' in options ?
options.strictQuery :
'strict' in options ?
options.strict :
'strictQuery' in schema._userProvidedOptions ?
schema._userProvidedOptions.strictQuery :
'strict' in schema._userProvidedOptions ?
schema._userProvidedOptions.strict :
schema.options.strictQuery;
const strictQuery = getStrictQuery(options, schema._userProvidedOptions, schema.options);
if (options.upsert && strict) {
if (strict === 'throw') {
throw new StrictModeError(path);
Expand Down Expand Up @@ -381,3 +373,19 @@ function _cast(val, numbertype, context) {
}
}
}

function getStrictQuery(queryOptions, schemaUserProvidedOptions, schemaOptions) {
if ('strictQuery' in queryOptions) {
return queryOptions.strictQuery;
}
if ('strict' in queryOptions) {
return queryOptions.strict;
}
if ('strictQuery' in schemaUserProvidedOptions) {
return schemaUserProvidedOptions.strictQuery;
}
if ('strict' in schemaUserProvidedOptions) {
return schemaUserProvidedOptions.strict;
}
return schemaOptions.strictQuery;
}

0 comments on commit d595544

Please sign in to comment.