in src/persistence/mapiObjectStorage.ts [392:458]
public async searchObjects<T>(key: string, query: Query<T>): Promise<Page<T>> {
const resource = this.paperbitsKeyToArmResource(key);
const contentType = this.getContentTypeFromResource(resource);
const isLocalized = localizedContentTypes.includes(contentType);
const localeSearchPrefix = isLocalized ? `${selectedLocaleArm}/` : "";
if (key === "locales") {
return {
value: []
};
}
try {
let filterQueryString = "";
let orderQueryString = "";
if (query?.filters.length > 0) {
const filterExpressions = [];
for (const filter of query.filters) {
const operator = filter.operator;
if (resource.startsWith("contentTypes/block/contentItems")) {
filter.left = `en_us/${filter.left}`;
}
filter.left = filter.left.replace("locales/en-us/", "en_us/");
switch (operator) {
case Operator.equals:
filterExpressions.push(`${filter.left} eq '${filter.right}'`);
break;
case Operator.contains:
if (filter.left !== "mimeType") { // Need to make this field indexable in content type first.
filterExpressions.push(`contains(${filter.left},'${filter.right}')`);
}
break;
default:
throw new AppError(`Cannot translate operator into OData query.`);
}
}
if (filterExpressions.length > 0) {
filterQueryString = `&$filter=${filterExpressions.join(" and ")}`;
}
}
if (query?.orderingBy) {
query.orderingBy = query.orderingBy.replace("locales/en-us/", localeSearchPrefix);
orderQueryString = `&$orderby=${query.orderingBy}`;
}
if (key.includes("navigationItems")) {
const armContract = await this.apiClient.get<any>(`${resource}?$orderby=${localeSearchPrefix}title${filterQueryString}`, [await this.apiClient.getPortalHeader("searchObjects")]);
const paperbitsContract = this.convertArmContractToPaperbitsContract(armContract, isLocalized);
return paperbitsContract.nodes;
}
return await this.loadNextPage(resource, localeSearchPrefix, filterQueryString, orderQueryString, 0, isLocalized);
}
catch (error) {
throw new AppError(`Could not search object '${key}'. Error: ${error.message}`, error);
}
}