Source: functions/registrants.js

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Registrants = void 0;
const logger_1 = require("../utils/logger");
/**
 * Class for adding, updating and getting meeting registrants
 */
class Registrants {
    /**
     * Create a Registrants instance
     * @param {AxiosInstance} http - axios instance to handle requests with zoom api
     * @member getListMeetingRegistrants
     * @member addMeetingRegistrant
     * @member updateMeetingRegistrantsStatus
     */
    constructor(http) {
        this.http = http;
    }
    /**
     * @async
     * Get list of meeting registrants
     * @param {GetListMeetingRegistrantsParams} params - parameters requires to get a list of meeting registrants
     * @returns {Promise<GetMeetingRegistrantListResponse>} - returns a list of meeting registrants or throws an error
     */
    async getListMeetingRegistrants(params) {
        try {
            logger_1.logger().debug('Getting a registrants list', params);
            const response = await this.http.get(`/meetings/${params.meetingId}/registrants`, {
                params: params.queryParams,
            });
            if (response.status === 200) {
                logger_1.logger().info('Getting meeting registrants successful', response.data);
                return response.data;
            }
            if (response.status === 300) {
                logger_1.logger().error('Getting meeting registrants failed with an error code 300', response.data);
                throw new Error('Getting meeting registrants failed with an error code 300');
            }
            if (response.status === 400) {
                logger_1.logger().error('Getting meeting registrants failed with an error code 400', response.data);
                throw new Error('Getting meeting registrats failed with an error code 400');
            }
            if (response.status === 404) {
                logger_1.logger().error('Getting meeting registrants failed with an error code 404', response.data);
                throw new Error('Getting meeting registrants failed with an error code 404');
            }
            logger_1.logger().error('Unexpected Beavior', response.data);
            throw new Error('Unexpected Behavior!');
        }
        catch (error) {
            throw error;
        }
    }
    /**
     * @async
     * Add meeting registrant
     * @param {AddMeetingRegistratParams} params - parameters requires to add a meeting registrat
     * @returns {Promise<AddMeetingRegistrantResponse>} - returns a meeting registrant or throws an error
     */
    async addMeetingRegistrant(params) {
        try {
            logger_1.logger().debug('Adding Meeting Registrant', params);
            const response = await this.http.post(`/meetings/${params.meetingId}/registrants`, {
                params: { occurence_ids: params.occurence_ids },
                ...params.requestBody,
            });
            if (response.status === 201) {
                logger_1.logger().info('Adding meeting registrant successful', response.data);
                return response.data;
            }
            if (response.status === 300) {
                logger_1.logger().error('Meeting registrant addtion failed with an error code 300', response.data);
                throw new Error('Meeting registrant addtion failed with an error code 300');
            }
            if (response.status === 400) {
                logger_1.logger().error('Meeting registrant addtion failed with an error code 400', response.data);
                throw new Error('Meeting registrant addtion failed with an error code 400');
            }
            if (response.status === 404) {
                logger_1.logger().error('Meeting registrant addtion failed with an error code 404', response.data);
                throw new Error('Meeting registrant addtion failed with an error code 404');
            }
            logger_1.logger().error('Unexpected Behavior', response.data);
            throw new Error('Unexpected behavior');
        }
        catch (error) {
            throw error;
        }
    }
    /**
     * @async
     * updates meeting registrants status
     * @param {UpdateRegistrantStatusParams} params - parameters requires to update registrant statuses
     * @returns {Promise<string>} - returns a success message or throws an error
     */
    async updateMeetingRegistrantsStatus(params) {
        try {
            if (params.requestBody.registrants.length > 30) {
                logger_1.logger().error('Maximum updatable registrant count exceeded');
                throw new Error('Maximum updatable registrant count exceeded');
            }
            logger_1.logger().debug('Updating meeting registrants', params);
            const response = await this.http.put(`/meetings/${params.meetingId}/registrants/status`, {
                params: { occurence_ids: params.occurrence_id },
                action: params.requestBody.action,
                registrants: params.requestBody.registrants,
            });
            if (response.status === 204) {
                logger_1.logger().info('Updating meeting registrants successful', response.data);
                return response.data;
            }
            if (response.status === 300) {
                logger_1.logger().error('Updating Registrants statuses failed with an error code 300', response.data);
                throw new Error('Updating Registrants statuses failed with an error code 300');
            }
            if (response.status === 400) {
                logger_1.logger().error('Updating Registrants statuses failed with an error code 400', response.data);
                throw new Error('Updating Registrants statuses failed with an error code 400');
            }
            if (response.status === 404) {
                logger_1.logger().error('Updating Registrants statuses failed with an error code 404', response.data);
                throw new Error('Updating Registrants statuses failed with an error code 404');
            }
            logger_1.logger().error('Unexpected behavior', response.data);
            throw new Error('Unexpected Behavior!');
        }
        catch (error) {
            throw error;
        }
    }
}
exports.Registrants = Registrants;