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

#1 Load all tenant options #2

Merged
merged 2 commits into from
Dec 18, 2023
Merged
Changes from 1 commit
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
37 changes: 31 additions & 6 deletions tenant-option-management/tenant-option-management.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export interface TenantOptionConfiguration extends IManagedObject {
}
@Injectable()
export class TenantOptionManagementService {
private readonly MAX_PAGE_SIZE = 2000;

constructor(private inventory: InventoryService, private tenantOption: TenantOptionsService) {}

async getConfiguration(): Promise<TenantOptionConfiguration> {
Expand Down Expand Up @@ -62,12 +64,35 @@ export class TenantOptionManagementService {
return this.tenantOption.update(option);
}

getAllOptions() {
return this.tenantOption
.list({
pageSize: 2000,
})
.then((res) => res.data.map((o) => ({ id: `${o.category}-${o.key}`, value: o.value })));
async getAllOptions(): Promise<{ id: string; value: string }[]> {
try {
const tenantOptions: ITenantOption[] = [];
const response = await this.tenantOption.list({
pageSize: this.MAX_PAGE_SIZE,
withTotalPages: true,
});

tenantOptions.push(...response.data);

for (
let currentPage = response.paging.currentPage + 1;
currentPage <= response.paging.totalPages;
currentPage++
) {
const { data } = await this.tenantOption.list({
pageSize: this.MAX_PAGE_SIZE,
currentPage: currentPage,
});

tenantOptions.push(...data);
}

return tenantOptions.map((o) => ({ id: `${o.category}-${o.key}`, value: o.value }));
} catch (error) {
console.error(error);

return undefined;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning undefined while not handling that case in the reload method of the tenant-option.component.ts will lead to an NPE when trying to call find on undefined. I would rather not want to catch it and let it bubble up the promise chain.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed it to return an empty array and create an alert if an error occurred while loading the tenant options

}
}

async deleteOption(row: TenantOptionRow) {
Expand Down