2023-01-26 13:58:25 -06:00
|
|
|
/**
|
|
|
|
|
* @class ApiResponse - A generic response object for API requests.
|
|
|
|
|
*/
|
2023-01-25 22:28:45 -06:00
|
|
|
export class ApiResponse<T> {
|
2023-01-26 13:58:25 -06:00
|
|
|
/**
|
|
|
|
|
* @property {number} statusCode - The status code of the response.
|
|
|
|
|
*/
|
2023-01-25 22:28:45 -06:00
|
|
|
readonly statusCode: number;
|
2023-01-26 13:58:25 -06:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @property {boolean} isSuccessful - True if the status code is less than 400; otherwise, false.
|
|
|
|
|
*/
|
2023-01-25 22:28:45 -06:00
|
|
|
readonly isSuccessful: boolean;
|
2023-01-26 13:58:25 -06:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @property {string} message - The message of the response.
|
|
|
|
|
*/
|
2023-01-25 22:28:45 -06:00
|
|
|
readonly message: string;
|
2023-01-26 13:58:25 -06:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @property {T} data - The data of the response.
|
|
|
|
|
*/
|
2023-01-25 22:28:45 -06:00
|
|
|
readonly data: T;
|
|
|
|
|
|
2023-01-26 13:58:25 -06:00
|
|
|
/**
|
|
|
|
|
* @constructor - Creates a new instance of the ApiResponse class.
|
|
|
|
|
* @param {number} statusCode - The status code of the response.
|
|
|
|
|
* @param {string} message - The message of the response.
|
|
|
|
|
* @param {T} data - The data of the response.
|
|
|
|
|
* @returns {ApiResponse<T>} - A new instance of the ApiResponse class.
|
|
|
|
|
*/
|
|
|
|
|
constructor(statusCode: number, message: string, data: T) {
|
2023-01-25 22:28:45 -06:00
|
|
|
this.statusCode = statusCode;
|
|
|
|
|
this.isSuccessful = statusCode < 400;
|
|
|
|
|
this.message = message;
|
|
|
|
|
this.data = data;
|
|
|
|
|
}
|
2023-01-26 13:58:25 -06:00
|
|
|
}
|