-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Convert js(x) -> ts(x) + add types
- Loading branch information
1 parent
4fd42b5
commit fd13676
Showing
9 changed files
with
119 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { camelCaseObject, snakeCaseObject, getConfig } from '@edx/frontend-platform'; | ||
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth'; | ||
|
||
export const getApiBaseUrl = () => getConfig().STUDIO_BASE_URL; | ||
|
||
export interface LibraryV2 { | ||
id: string, | ||
Check failure on line 7 in src/library/data/api.ts GitHub Actions / tests
|
||
type: string, | ||
Check failure on line 8 in src/library/data/api.ts GitHub Actions / tests
|
||
org: string, | ||
Check failure on line 9 in src/library/data/api.ts GitHub Actions / tests
|
||
slug: string, | ||
Check failure on line 10 in src/library/data/api.ts GitHub Actions / tests
|
||
title: string, | ||
Check failure on line 11 in src/library/data/api.ts GitHub Actions / tests
|
||
description: string, | ||
numBlocks: number, | ||
version: number, | ||
lastPublished: string | null, | ||
allowLti: boolean, | ||
allowPublicLearning: boolean, | ||
allowPublicRead: boolean, | ||
hasUnpublishedChanges: boolean, | ||
hasUnpublishedDeletes: boolean, | ||
license: string, | ||
}; | ||
|
||
export interface LibrariesV2Response { | ||
next: string|null, | ||
previous: string|null, | ||
count: number, | ||
numPages: number, | ||
currentPage: number, | ||
start: number, | ||
results: LibraryV2[], | ||
}; | ||
|
||
/* Additional custom parameters for the API request. */ | ||
export interface GetLibrariesV2CustomParams { | ||
/* (optional) Library type, default `complex` */ | ||
type?: string, | ||
/* (optional) Page number of results */ | ||
page?: number, | ||
/* (optional) The number of results on each page, default `50` */ | ||
pageSize?: number, | ||
/* (optional) Whether pagination is supported, default `true` */ | ||
pagination?: boolean, | ||
/* (optional) Library field to order results by. Prefix with '-' for descending */ | ||
order?: string, | ||
/* (optional) Search query to filter v2 Libraries by */ | ||
search?: string, | ||
}; | ||
|
||
/** | ||
* Get's studio home v2 Libraries. | ||
*/ | ||
export async function getStudioHomeLibrariesV2(customParams: GetLibrariesV2CustomParams): Promise<LibrariesV2Response> { | ||
// Set default params if not passed in | ||
const customParamsDefaults = { | ||
type: customParams.type || 'complex', | ||
page: customParams.page || 1, | ||
pageSize: customParams.pageSize || 50, | ||
pagination: customParams.pagination !== undefined ? customParams.pagination : true, | ||
order: customParams.order || 'title', | ||
textSearch: customParams.search, | ||
}; | ||
const customParamsFormat = snakeCaseObject(customParamsDefaults); | ||
const { data } = await getAuthenticatedHttpClient().get(`${getApiBaseUrl()}/api/libraries/v2/`, { params: customParamsFormat }); | ||
return camelCaseObject(data); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.