projects/i-components/src/lib/components/rad-upload/rad-uag.ts
Represents the response from RadUAG service.
Properties |
JSONData |
JSONData:
|
Type : literal type[]
|
Response data: an array of Key-Value pairs.
}[]} |
export const RadUAGPrefix = 'RadUAG_';
/**
* Represents the response from RadUAG service.
*
* @interface RadUAGResponse
*/
export interface RadUAGResponse {
/**
* Response data: an array of Key-Value pairs.
*
* @type {{
* Key: string;
* Value: any;
* }[]}
* @memberof RadUAGResponse
*/
JSONData: {
/**
* Key.
*
* @type {string}
*/
Key: string;
/**
* Value.
*
* @type {*}
*/
Value: any;
}[];
}
/**
* Extract the value corresponding to the given key.
*
* @template T
* @param {RadUAGResponse} response
* @param {string} key
* @return {*} {T}
*/
export function getRadUAGValue<T>(response: RadUAGResponse, key: string): T {
const postfix = `_${RadUAGPrefix}${key}`;
return response.JSONData.find((x) => x.Key.endsWith(postfix))?.Value;
}
/**
* Get the 'Success' value from a response.
*
* @param {RadUAGResponse} response
* @return {*} {boolean}
*/
export function getRadUAGSuccess(response: RadUAGResponse): boolean {
return getRadUAGValue(response, 'success');
}
/**
* Get the 'Message' value from a response.
*
* @param {RadUAGResponse} response
* @return {*} {string}
*/
export function getRadUAGMessage(response: RadUAGResponse): string {
return getRadUAGValue(response, 'message');
}