RICADO Gen 4 API JS Client

RICADO Gen 4 API JS Client

source

Controllers/UserAccountActionTokenController.js

/**
 * File Auto-Generated by the RICADO Gen 4 PHP API Project
 * 
 * Do Not Edit this File Manually!
 */

import RequestHelper from '../RequestHelper';
import UserAccountActionTokenModel from '../Models/UserAccountActionTokenModel';

/**
 * Controller Class for User Account Action Tokens
 * 
 * @class
 */
class UserAccountActionTokenController
{
    /**
     * Retrieve a User Account Action Token [GET /user-action-tokens/{id}]
     * 
     * @static
     * @public
     * @param {string} id The User Account Action Token ID
     * @return {Promise<UserAccountActionTokenModel>}
     */
    static getOne(id)
    {
        return new Promise((resolve, reject) => {
            RequestHelper.getRequest(`/user-action-tokens/${id}`)
            .then((result) => {
                let resolveValue = (function(){
                    return UserAccountActionTokenModel.fromJSON(result);
                }());
                
                resolve(resolveValue);
            })
            .catch(error => reject(error));
        });
    }

    /**
     * Update a User Account Action Token [PATCH /user-action-tokens/{id}]
     * 
     * @static
     * @public
     * @param {string} id The User Account Action Token ID
     * @param {UserAccountActionTokenController.UpdateData} updateData The User Account Action Token Update Data
     * @return {Promise<UserAccountActionTokenModel>}
     */
    static update(id, updateData)
    {
        return new Promise((resolve, reject) => {
            RequestHelper.patchRequest(`/user-action-tokens/${id}`, updateData)
            .then((result) => {
                let resolveValue = (function(){
                    return UserAccountActionTokenModel.fromJSON(result);
                }());
                
                resolve(resolveValue);
            })
            .catch(error => reject(error));
        });
    }

    /**
     * Delete a User Account Action Token [DELETE /user-action-tokens/{id}]
     * 
     * @static
     * @public
     * @param {string} id The User Account Action Token ID
     * @return {Promise<boolean>}
     */
    static delete(id)
    {
        return new Promise((resolve, reject) => {
            RequestHelper.deleteRequest(`/user-action-tokens/${id}`)
            .then((result) => {
                resolve(result ?? true);
            })
            .catch(error => reject(error));
        });
    }

    /**
     * List all User Account Action Tokens [GET /user-action-tokens]
     * 
     * @static
     * @public
     * @param {UserAccountActionTokenController.GetAllQueryParameters} [queryParameters] The Optional Query Parameters
     * @return {Promise<UserAccountActionTokenModel[]>}
     */
    static getAll(queryParameters = {})
    {
        return new Promise((resolve, reject) => {
            RequestHelper.getRequest(`/user-action-tokens`, queryParameters)
            .then((result) => {
                let resolveValue = (function(){
                    if(Array.isArray(result) !== true)
                    {
                        return [];
                    }
                
                    return result.map((resultItem) => {
                        return (function(){
                            return UserAccountActionTokenModel.fromJSON(resultItem);
                        }());
                    });
                }());
                
                resolve(resolveValue);
            })
            .catch(error => reject(error));
        });
    }

    /**
     * Create a User Account Action Token [POST /user-action-tokens]
     * 
     * @static
     * @public
     * @param {UserAccountActionTokenController.CreateData} createData The User Account Action Token Create Data
     * @return {Promise<UserAccountActionTokenModel>}
     */
    static create(createData)
    {
        return new Promise((resolve, reject) => {
            RequestHelper.postRequest(`/user-action-tokens`, createData)
            .then((result) => {
                let resolveValue = (function(){
                    return UserAccountActionTokenModel.fromJSON(result);
                }());
                
                resolve(resolveValue);
            })
            .catch(error => reject(error));
        });
    }

    /**
     * Generate a new Action Token [POST /user-action-tokens/new]
     * 
     * This method is used to generate a new JWT to be used for a User Action (e.g. to Reset a User's Password). The JWT is sent to the User's Email Address in a formatted Email in the form of a Link.
     * 
     * @static
     * @public
     * @param {string} email A User Account's Email Address
     * @param {string} action The Action that will be performed
     * @param {string} providerId The Platform Provider ID
     * @return {Promise<boolean>}
     */
    static createToken(email, action, providerId)
    {
        return new Promise((resolve, reject) => {
            RequestHelper.postRequest(`/user-action-tokens/new`, {email, action, providerId})
            .then((result) => {
                resolve(result ?? true);
            })
            .catch(error => reject(error));
        });
    }

    /**
     * Verify an existing Action Token [POST /user-action-tokens/verify]
     * 
     * This method is used to verify an existing JWT and confirm it is valid for the specified Action.
     * 
     * @static
     * @public
     * @param {string} token The JWT Token that was provided in the form of a Link to the User's Email Address
     * @param {string} action The Action that will be performed
     * @return {Promise<boolean>}
     */
    static verifyToken(token, action)
    {
        return new Promise((resolve, reject) => {
            RequestHelper.postRequest(`/user-action-tokens/verify`, {token, action})
            .then((result) => {
                resolve(result ?? true);
            })
            .catch(error => reject(error));
        });
    }

    /**
     * Activate a User's Account [POST /user-action-tokens/actions/activate]
     * 
     * This method is used to Activate a User's Account
     * 
     * @static
     * @public
     * @param {string} token The JWT Token that was provided in the form of a Link to the User's Email Address
     * @param {string} email The User's Email Address
     * @param {string} password The User's Chosen Password
     * @param {string} firstName The User's First Name
     * @param {string} lastName The User's Last Name
     * @return {Promise<{email: string, firstName: string, lastName: string}>}
     */
    static activateAction(token, email, password, firstName, lastName)
    {
        return new Promise((resolve, reject) => {
            RequestHelper.postRequest(`/user-action-tokens/actions/activate`, {token, email, password, firstName, lastName})
            .then((result) => {
                let resolveValue = (function(){
                    let resultObject = {};
                    
                    if(typeof result === 'object' && 'email' in result)
                    {
                        resultObject.email = (function(){
                            if(typeof result.email !== 'string')
                            {
                                return String(result.email);
                            }
                
                            return result.email;
                        }());
                    }
                    else
                    {
                        resultObject.email = "";
                    }
                    
                    if(typeof result === 'object' && 'firstName' in result)
                    {
                        resultObject.firstName = (function(){
                            if(typeof result.firstName !== 'string')
                            {
                                return String(result.firstName);
                            }
                
                            return result.firstName;
                        }());
                    }
                    else
                    {
                        resultObject.firstName = "";
                    }
                    
                    if(typeof result === 'object' && 'lastName' in result)
                    {
                        resultObject.lastName = (function(){
                            if(typeof result.lastName !== 'string')
                            {
                                return String(result.lastName);
                            }
                
                            return result.lastName;
                        }());
                    }
                    else
                    {
                        resultObject.lastName = "";
                    }
                
                    return resultObject;
                }());
                
                resolve(resolveValue);
            })
            .catch(error => reject(error));
        });
    }

    /**
     * Retrieve a User's Details for Activation [GET /user-action-tokens/actions/activate]
     * 
     * This method is used to Request a User's Details which can be used to populate fields required for Account Activation
     * 
     * @static
     * @public
     * @param {string} token The JWT Token that was provided in the form of a Link to the User's Email Address
     * @return {Promise<{email: string, firstName: string, lastName: string}>}
     */
    static getActivateActionDetails(token)
    {
        return new Promise((resolve, reject) => {
            let queryParameters = {};
            
            RequestHelper.getRequest(`/user-action-tokens/actions/activate`, Object.assign(queryParameters, {token}))
            .then((result) => {
                let resolveValue = (function(){
                    let resultObject = {};
                    
                    if(typeof result === 'object' && 'email' in result)
                    {
                        resultObject.email = (function(){
                            if(typeof result.email !== 'string')
                            {
                                return String(result.email);
                            }
                
                            return result.email;
                        }());
                    }
                    else
                    {
                        resultObject.email = "";
                    }
                    
                    if(typeof result === 'object' && 'firstName' in result)
                    {
                        resultObject.firstName = (function(){
                            if(typeof result.firstName !== 'string')
                            {
                                return String(result.firstName);
                            }
                
                            return result.firstName;
                        }());
                    }
                    else
                    {
                        resultObject.firstName = "";
                    }
                    
                    if(typeof result === 'object' && 'lastName' in result)
                    {
                        resultObject.lastName = (function(){
                            if(typeof result.lastName !== 'string')
                            {
                                return String(result.lastName);
                            }
                
                            return result.lastName;
                        }());
                    }
                    else
                    {
                        resultObject.lastName = "";
                    }
                
                    return resultObject;
                }());
                
                resolve(resolveValue);
            })
            .catch(error => reject(error));
        });
    }

    /**
     * Reset a User's Password [POST /user-action-tokens/actions/reset-password]
     * 
     * This method is used to Reset a User's Password
     * 
     * @static
     * @public
     * @param {string} token The JWT Token that was provided in the form of a Link to the User's Email Address
     * @param {string} newPassword The New Password
     * @return {Promise<boolean>}
     */
    static resetPasswordAction(token, newPassword)
    {
        return new Promise((resolve, reject) => {
            RequestHelper.postRequest(`/user-action-tokens/actions/reset-password`, {token, newPassword})
            .then((result) => {
                resolve(result ?? true);
            })
            .catch(error => reject(error));
        });
    }

    /**
     * Reset a User's Pin Code [POST /user-action-tokens/actions/reset-pin-code]
     * 
     * This method is used to Reset a User's Pin Code
     * 
     * @static
     * @public
     * @param {string} token The JWT Token that was provided in the form of a Link to the User's Email Address
     * @param {string} newPinCode The New Pin Code
     * @return {Promise<boolean>}
     */
    static resetPinCodeAction(token, newPinCode)
    {
        return new Promise((resolve, reject) => {
            RequestHelper.postRequest(`/user-action-tokens/actions/reset-pin-code`, {token, newPinCode})
            .then((result) => {
                resolve(result ?? true);
            })
            .catch(error => reject(error));
        });
    }
}

export default UserAccountActionTokenController;

/**
 * The Optional Query Parameters for the getAll Function
 * 
 * @typedef {Object} UserAccountActionTokenController.GetAllQueryParameters
 * @property {string} [accountId] The Account this Action Token belongs to
 * @property {string} [companyId] The Company this Action Token belongs to
 * @property {string} [action] The Action that can be Performed using this Action Token
 * @property {Date} [issueTimestamp] When the Action Token was issued
 * @property {Date} [expireTimestamp] When the Action Token will expire
 * @memberof Controllers
 */

/**
 * The Create Data for a User Account Action Token
 * 
 * @typedef {Object} UserAccountActionTokenController.CreateData
 * @property {string} accountId The Account this Action Token belongs to
 * @property {string} companyId The Company this Action Token belongs to
 * @property {string} action The Action that can be Performed using this Action Token
 * @property {Date} issueTimestamp When the Action Token was issued
 * @property {Date} expireTimestamp When the Action Token will expire
 * @property {?Date} [activityTimestamp] When the last API call using this Action Token was made
 * @property {?Date} [completedTimestamp] When the Action was Completed
 * @property {?Date} [emailTimestamp] When the Action Email was Sent
 * @memberof Controllers
 */

/**
 * The Update Data for a User Account Action Token
 * 
 * @typedef {Object} UserAccountActionTokenController.UpdateData
 * @property {?Date} [activityTimestamp] When the last API call using this Action Token was made
 * @property {?Date} [completedTimestamp] When the Action was Completed
 * @property {?Date} [emailTimestamp] When the Action Email was Sent
 * @memberof Controllers
 */