-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds ability to request inventory report. (PP-1236) (#110)
- Loading branch information
Showing
12 changed files
with
6,194 additions
and
21,350 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Inventory Report API | ||
export type InventoryReportCollectionInfo = { | ||
id: number; | ||
name: string; | ||
}; | ||
export type InventoryReportInfo = { | ||
collections: InventoryReportCollectionInfo[]; | ||
}; | ||
export type InventoryReportRequestResponse = { | ||
message: string; | ||
}; | ||
export type InventoryReportRequestParams = { | ||
library: string; | ||
baseEndpointUrl?: string; | ||
}; | ||
|
||
export const DEFAULT_BASE_ENDPOINT_URL = "/admin/reports/inventory_report"; | ||
|
||
/** | ||
* Get information about the inventory report that would be generated for the | ||
* given library, if requested. | ||
* | ||
* @param library -- the library for which the report information is requested. | ||
* @param baseEndpointUrl -- an optional baseURL (for testing). If not provided, | ||
* the `defaultBaseEndpointUrl` will be used. | ||
* @returns an object converted from the information JSON response, if successful. | ||
* @throws an error, if the request is not successful. | ||
*/ | ||
export const getInventoryReportInfo = async ({ | ||
library, | ||
baseEndpointUrl = DEFAULT_BASE_ENDPOINT_URL, | ||
}: InventoryReportRequestParams): Promise<InventoryReportInfo> => { | ||
const endpointUrl = `${baseEndpointUrl}/${library}`; | ||
const res = await fetch(endpointUrl); | ||
if (!res.ok) { | ||
throw new Error(`Request failed with status ${res.status}: GET ${res.url}`); | ||
} | ||
return res.json(); | ||
}; | ||
|
||
/** | ||
* Request an inventory report for the given library. | ||
* | ||
* @param library -- the library for which the report information is requested. | ||
* @param baseEndpointUrl -- an optional baseURL (for testing). If not provided, | ||
* the `defaultBaseEndpointUrl` will be used. | ||
* @returns an object converted from the message JSON response, if successful. | ||
* @throws an error, if the request is not successful. | ||
*/ | ||
export const requestInventoryReport = async ({ | ||
library, | ||
baseEndpointUrl = DEFAULT_BASE_ENDPOINT_URL, | ||
}: InventoryReportRequestParams): Promise<InventoryReportRequestResponse> => { | ||
const endpointUrl = `${baseEndpointUrl}/${library}`; | ||
const res = await fetch(endpointUrl, { method: "POST" }); | ||
if (!res.ok) { | ||
throw new Error( | ||
`Request failed with status ${res.status}: POST ${res.url}` | ||
); | ||
} | ||
return res.json(); | ||
}; |
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.