Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed assembly logic for "$orderby" statement. #1020

Merged
merged 1 commit into from
Nov 4, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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