feat: ensures you can query on blocks via specifying locale or not specifying locale
This commit is contained in:
@@ -142,7 +142,7 @@ class ParamParser {
|
||||
},
|
||||
];
|
||||
|
||||
pathSegments.forEach((segment, i) => {
|
||||
pathSegments.every((segment, i) => {
|
||||
const lastIncompletePath = paths.find(({ complete }) => !complete);
|
||||
const { path } = lastIncompletePath;
|
||||
|
||||
@@ -152,7 +152,7 @@ class ParamParser {
|
||||
|
||||
if (currentSchemaPathType === 'nested') {
|
||||
lastIncompletePath.path = currentPath;
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
const upcomingSegment = pathSegments[i + 1];
|
||||
@@ -161,25 +161,25 @@ class ParamParser {
|
||||
const currentSchemaTypeOptions = getSchemaTypeOptions(currentSchemaType);
|
||||
|
||||
if (currentSchemaTypeOptions.localized) {
|
||||
const upcomingLocalizedPath = `${currentPath}.${upcomingSegment}`;
|
||||
const upcomingSchemaTypeWithLocale = schema.path(upcomingLocalizedPath);
|
||||
|
||||
if (upcomingSchemaTypeWithLocale) {
|
||||
lastIncompletePath.path = currentPath;
|
||||
return true;
|
||||
}
|
||||
|
||||
const localePath = `${currentPath}.${this.locale}`;
|
||||
const localizedSchemaType = schema.path(localePath);
|
||||
|
||||
if (localizedSchemaType || operator === 'near') {
|
||||
lastIncompletePath.path = localePath;
|
||||
return;
|
||||
}
|
||||
|
||||
const upcomingPathWithLocale = `${currentPath}.${this.locale}.${upcomingSegment}`;
|
||||
const upcomingSchemaTypeWithLocale = schema.path(upcomingPathWithLocale);
|
||||
|
||||
if (upcomingSchemaTypeWithLocale) {
|
||||
lastIncompletePath.path = upcomingPathWithLocale;
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lastIncompletePath.path = currentPath;
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
const priorSchemaType = schema.path(path);
|
||||
@@ -197,19 +197,16 @@ class ParamParser {
|
||||
...paths,
|
||||
...this.getLocalizedPaths(RefModel, remainingPath, operator),
|
||||
];
|
||||
return;
|
||||
}
|
||||
|
||||
if (priorSchemaType.instance === 'Mixed' || priorSchemaType.instance === 'Array') {
|
||||
lastIncompletePath.path = currentPath;
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
|
||||
if (operator === 'near' || currentSchemaPathType === 'adhocOrUndefined') {
|
||||
lastIncompletePath.path = currentPath;
|
||||
}
|
||||
|
||||
if (operator === 'near') {
|
||||
lastIncompletePath.path = currentPath;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
return paths;
|
||||
|
||||
@@ -334,19 +334,9 @@ const fieldToSchemaMap: Record<string, FieldSchemaGenerator> = {
|
||||
},
|
||||
blocks: (field: BlockField, schema: Schema, config: SanitizedConfig, buildSchemaOptions: BuildSchemaOptions): void => {
|
||||
const fieldSchema = [new Schema({}, { _id: false, discriminatorKey: 'blockType' })];
|
||||
let schemaToReturn;
|
||||
|
||||
if (field.localized && config.localization) {
|
||||
schemaToReturn = config.localization.locales.reduce((localeSchema, locale) => ({
|
||||
...localeSchema,
|
||||
[locale]: fieldSchema,
|
||||
}), {});
|
||||
} else {
|
||||
schemaToReturn = fieldSchema;
|
||||
}
|
||||
|
||||
schema.add({
|
||||
[field.name]: schemaToReturn,
|
||||
[field.name]: localizeSchema(field, fieldSchema, config.localization),
|
||||
});
|
||||
|
||||
field.blocks.forEach((blockItem: Block) => {
|
||||
|
||||
Reference in New Issue
Block a user