Skip to content

Commit

Permalink
Fixed assembly logic for "$orderby" statement. (#1020)
Browse files Browse the repository at this point in the history
  • Loading branch information
azaslonov authored Nov 4, 2020
1 parent 0b0aadd commit 281cd6e
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/persistence/mapiObjectStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ export class MapiObjectStorage implements IObjectStorage {
displayName: "English (US)"
};
}

const resource = this.paperbitsKeyToArmResource(key);
const contentType = this.getContentTypeFromResource(resource);
const isLocalized = localizedContentTypes.includes(contentType);
Expand Down Expand Up @@ -339,8 +339,8 @@ export class MapiObjectStorage implements IObjectStorage {
}
}

private async loadNextPage<T>(resource: string, localeSearchPrefix: string, filterQueryString: string, skip: number, isLocalized: boolean): Promise<Page<T>> {
const url = `${resource}?$skip=${skip}&$top=${defaultPageSize}&$orderby=${localeSearchPrefix}title${filterQueryString}`;
private async loadNextPage<T>(resource: string, localeSearchPrefix: string, filterQueryString: string, orderQueryString: string, skip: number, isLocalized: boolean): Promise<Page<T>> {
const url = `${resource}?$skip=${skip}&$top=${defaultPageSize}${filterQueryString}${orderQueryString}`;
const pageOfTs = await this.mapiClient.get<PageContract<T>>(url);
const searchResult = [];

Expand All @@ -357,11 +357,11 @@ export class MapiObjectStorage implements IObjectStorage {
const resultPage: Page<T> = {
value: searchResult,
takeNext: async (): Promise<Page<T>> => {
return await this.loadNextPage(resource, localeSearchPrefix, filterQueryString, skip + defaultPageSize, isLocalized);
return await this.loadNextPage(resource, localeSearchPrefix, filterQueryString, orderQueryString, skip + defaultPageSize, isLocalized);
}
};

if (!pageOfTs.nextLink) {
if (!pageOfTs.nextLink || pageOfTs.value.length === 0) {
resultPage.takeNext = null;
}

Expand All @@ -376,8 +376,9 @@ export class MapiObjectStorage implements IObjectStorage {

try {
let filterQueryString = "";
let orderQueryString = "";

if (query && query.filters.length > 0) {
if (query?.filters.length > 0) {
const filterExpressions = [];

for (const filter of query.filters) {
Expand Down Expand Up @@ -406,13 +407,18 @@ export class MapiObjectStorage implements IObjectStorage {
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.mapiClient.get<any>(`${resource}?$orderby=${localeSearchPrefix}title${filterQueryString}`);
const paperbitsContract = this.convertArmContractToPaperbitsContract(armContract, isLocalized);
return paperbitsContract.nodes;
}
else {
return await this.loadNextPage(resource, localeSearchPrefix, filterQueryString, 0, isLocalized);
return await this.loadNextPage(resource, localeSearchPrefix, filterQueryString, orderQueryString, 0, isLocalized);

}
}
Expand Down

0 comments on commit 281cd6e

Please sign in to comment.