/**
* File Auto-Generated by the RICADO Gen 4 PHP API Project
*
* Do Not Edit this File Manually!
*/
import RequestHelper from '../RequestHelper';
import AccountPolicyModel from '../Models/AccountPolicyModel';
/**
* Controller Class for Account Policies
*
* @class
*/
class AccountPolicyController
{
/**
* Retrieve a Account Policy [GET /account-policies/{id}]
*
* @static
* @public
* @param {string} id The Account Policy ID
* @return {Promise<AccountPolicyModel>}
*/
static getOne(id)
{
return new Promise((resolve, reject) => {
RequestHelper.getRequest(`/account-policies/${id}`)
.then((result) => {
let resolveValue = (function(){
return AccountPolicyModel.fromJSON(result);
}());
resolve(resolveValue);
})
.catch(error => reject(error));
});
}
/**
* Update a Account Policy [PATCH /account-policies/{id}]
*
* @static
* @public
* @param {string} id The Account Policy ID
* @param {AccountPolicyController.UpdateData} updateData The Account Policy Update Data
* @return {Promise<AccountPolicyModel>}
*/
static update(id, updateData)
{
return new Promise((resolve, reject) => {
RequestHelper.patchRequest(`/account-policies/${id}`, updateData)
.then((result) => {
let resolveValue = (function(){
return AccountPolicyModel.fromJSON(result);
}());
resolve(resolveValue);
})
.catch(error => reject(error));
});
}
/**
* Delete a Account Policy [DELETE /account-policies/{id}]
*
* @static
* @public
* @param {string} id The Account Policy ID
* @return {Promise<boolean>}
*/
static delete(id)
{
return new Promise((resolve, reject) => {
RequestHelper.deleteRequest(`/account-policies/${id}`)
.then((result) => {
resolve(result ?? true);
})
.catch(error => reject(error));
});
}
/**
* List all Account Policies [GET /account-policies]
*
* @static
* @public
* @param {AccountPolicyController.GetAllQueryParameters} [queryParameters] The Optional Query Parameters
* @return {Promise<AccountPolicyModel[]>}
*/
static getAll(queryParameters = {})
{
return new Promise((resolve, reject) => {
RequestHelper.getRequest(`/account-policies`, queryParameters)
.then((result) => {
let resolveValue = (function(){
if(Array.isArray(result) !== true)
{
return [];
}
return result.map((resultItem) => {
return (function(){
return AccountPolicyModel.fromJSON(resultItem);
}());
});
}());
resolve(resolveValue);
})
.catch(error => reject(error));
});
}
/**
* Create a Account Policy [POST /account-policies]
*
* @static
* @public
* @param {AccountPolicyController.CreateData} createData The Account Policy Create Data
* @return {Promise<AccountPolicyModel>}
*/
static create(createData)
{
return new Promise((resolve, reject) => {
RequestHelper.postRequest(`/account-policies`, createData)
.then((result) => {
let resolveValue = (function(){
return AccountPolicyModel.fromJSON(result);
}());
resolve(resolveValue);
})
.catch(error => reject(error));
});
}
}
export default AccountPolicyController;
/**
* The Optional Query Parameters for the getAll Function
*
* @typedef {Object} AccountPolicyController.GetAllQueryParameters
* @property {string} [name] The Policy Name
* @property {string} [companyId] The Company this Policy belongs to
* @memberof Controllers
*/
/**
* The Create Data for a Account Policy
*
* @typedef {Object} AccountPolicyController.CreateData
* @property {string} name The Policy Name
* @property {string} companyId The Company this Policy belongs to
* @property {Array<AccountPolicyController.Resource>} [resources] The Resources this Policy provides
* @property {Object[]} [rules] The Rules this Policy provides
* @memberof Controllers
*/
/**
* The Update Data for a Account Policy
*
* @typedef {Object} AccountPolicyController.UpdateData
* @property {string} [name] The Policy Name
* @property {string} [companyId] The Company this Policy belongs to
* @property {Array<AccountPolicyController.Resource>} [resources] The Resources this Policy provides
* @property {Object[]} [rules] The Rules this Policy provides
* @memberof Controllers
*/
/**
* A **Resource** Type
*
* @typedef {Object} AccountPolicyController.Resource
* @property {any} id The Resource ID. Supports * as a Wildcard
* @property {string} type The Resource Type
* @property {string[]} actions An Array of Actions that can be performed on the Resource
* @property {string} permission Whether the Actions should be Allowed or Denied for the Resource
* @memberof Controllers
*/
source