mirror of
https://github.com/LukeHagar/idn-admin-console.git
synced 2025-12-06 04:20:02 +00:00
Add server-side code for loading sources and total count
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
import { getFilters, getLimit, getSorters, getPage } from '$lib/Utils.js';
|
||||
import { createConfiguration } from '$lib/sailpoint/sdk.js';
|
||||
import { getToken } from '$lib/utils/oauth.js';
|
||||
import { SourcesApi, type Source, type SourcesApiListSourcesRequest } from 'sailpoint-api-client';
|
||||
|
||||
export const load = async ({ cookies, url }) => {
|
||||
const session = JSON.parse(cookies.get('session')!);
|
||||
const idnSession = await getToken(cookies);
|
||||
|
||||
const config = createConfiguration(session.baseUrl, idnSession.access_token);
|
||||
const api = new SourcesApi(config);
|
||||
|
||||
const page = getPage(url);
|
||||
const filters = getFilters(url);
|
||||
const limit = getLimit(url);
|
||||
const sorters = getSorters(url);
|
||||
|
||||
const requestParams: SourcesApiListSourcesRequest = {
|
||||
filters,
|
||||
offset: Number(page) * Number(limit),
|
||||
limit: Number(limit),
|
||||
sorters,
|
||||
count: true
|
||||
};
|
||||
|
||||
const apiResponse = api.listSources(requestParams);
|
||||
|
||||
const sources = new Promise((resolve) => {
|
||||
apiResponse
|
||||
.then((response) => {
|
||||
resolve(response.data as Source[]);
|
||||
})
|
||||
.catch((err) => {
|
||||
throw err;
|
||||
});
|
||||
});
|
||||
|
||||
const totalCount = new Promise<number>((resolve) => {
|
||||
apiResponse
|
||||
.then((response) => {
|
||||
resolve(response.headers['x-total-count']);
|
||||
})
|
||||
.catch((err) => {
|
||||
throw err;
|
||||
});
|
||||
});
|
||||
|
||||
return { sources, totalCount, params: { page, limit, filters, sorters } };
|
||||
};
|
||||
Reference in New Issue
Block a user