UNPKG

@omegabigdata/honoplay-api-helper-node

Version:
113 lines (104 loc) 2.85 kB
'use strict'; const { axiosClient } = require('./Helpers'); /** * @param {object} contentFileModel - contentFileModel for Post * @param {!string} contentFile.name * @param {!string} contentFile.contentType * @param {!string} contentFile.data * @param {function} successCallback * @param {function} errorCallback */ const postContentFile = (contentFileModel, successCallback, errorCallback) => { if (!contentFileModel) { if (errorCallback) { errorCallback('Missing Parameters'); return; } throw new Error('Missing Parameters'); } const uri = `ContentFile`; axiosClient .post(uri, contentFileModel) .then(success => successCallback(success)) .catch(error => errorCallback(error)); }; /** * @param {object} contentFileModel - contentFileModel for Post * @param {!number} contentFile.id * @param {!string} contentFile.name * @param {!string} contentFile.contentType * @param {!string} contentFile.data * @param {function} successCallback * @param {function} errorCallback */ const putContentFile = (contentFileModel, successCallback, errorCallback) => { if (!contentFileModel) { if (errorCallback) { errorCallback('Missing Parameters'); return; } throw new Error('Missing Parameters'); } const uri = `ContentFile`; axiosClient .put(uri, contentFileModel) .then(success => successCallback(success)) .catch(error => errorCallback(error)); }; /** * @param {!number} skip * @param {!number} take * @param {function} successCallback * @param {function} errorCallback */ const getContentFiles = ( skip = null, take = null, successCallback, errorCallback ) => { if (typeof skip !== 'number' || typeof take !== 'number') { throw new Error('Values must be numeric'); } if (skip <= -1 && take <= -1) { throw new Error('Values must be positive'); } const uri = `ContentFile?Skip=${skip}&Take=${take}`; axiosClient .get(uri) .then(success => { successCallback(success); }) .catch(error => { errorCallback(error); }); }; /** * @param {!number} contentFileId - contentFile Id * @param {function} successCallback * @param {function} errorCallback */ const getContentFile = (contentFileId, successCallback, errorCallback) => { if (!contentFileId) { if (errorCallback) { errorCallback('Missing Parameters'); return; } throw new Error('Missing Parameters'); } const uri = `ContentFile/${contentFileId}`; axiosClient .get(uri) .then(success => { successCallback(success); }) .catch(error => { errorCallback(error); }); }; module.exports = { postContentFile, putContentFile, getContentFiles, getContentFile };