@omegabigdata/honoplay-api-helper-node
Version:
125 lines (113 loc) • 3.11 kB
JavaScript
;
const { axiosClient, trainerAxiosClient } = require("./Helpers");
/**
* @param {!number} skip
* @param {!number} take
* @param {function} successCallback
* @param {function} errorCallback
*/
const getTrainers = (skip, take, successCallback, errorCallback) => {
if (typeof skip !== "number" || typeof skip !== "number") {
throw new Error("Values must be numeric");
}
if (skip < 0 || take < 0) {
throw new Error("Values must be positive");
}
let uri = `Traineruser`;
if (skip) {
uri += `?Skip=${skip}`;
}
if (skip && take) {
uri += `&Take=${take}`;
}
if (!skip && take) {
uri += `?Take=${take}`;
}
axiosClient
.get(uri)
.then(success => {
successCallback(success);
})
.catch(error => {
errorCallback(error);
});
};
/**
* @param {!number} trainerId
* @param {function} successCallback
* @param {function} errorCallback
*/
const getTrainer = (trainerId, successCallback, errorCallback) => {
if (trainerId == null || trainerId == undefined) {
if (errorCallback) {
errorCallback("Missing Parameters");
}
throw new Error("Missing Parameters");
}
if (trainerId <= 0) {
throw new Error("Value must be greater than zero");
}
let uri = `Traineruser/${trainerId}`;
axiosClient
.get(uri)
.then(success => {
successCallback(success);
})
.catch(error => {
errorCallback(error);
});
};
/**
* @param {!string} trainerModel.name
* @param {!string} trainerModel.surname
* @param {!string} trainerModel.email
* @param {!string} trainerModel.phoneNumber
* @param {!number} trainerModel.departmentId
* @param {!number} trainerModel.professionId
* @param {function} successCallback
* @param {function} errorCallback
*/
const postTrainer = (trainerModel, successCallback, errorCallback) => {
if (!trainerModel) {
if (errorCallback) {
errorCallback("Missing Parameters");
return;
}
throw new Error("Missing Parameters");
}
const uri = `Traineruser`;
axiosClient
.post(uri, trainerModel)
.then(success => successCallback(success))
.catch(error => errorCallback(error));
};
/**
* @param {!string} trainerModel.name
* @param {!string} trainerModel.surname
* @param {!string} trainerModel.email
* @param {!string} trainerModel.phoneNumber
* @param {!number} trainerModel.departmentId
* @param {!number} trainerModel.professionId
* @param {function} successCallback
* @param {function} errorCallback
*/
const putTrainer = (trainerModel, successCallback, errorCallback) => {
if (!trainerModel) {
if (errorCallback) {
errorCallback("Missing Parameters");
return;
}
throw new Error("Missing Parameters");
}
const uri = `Traineruser`;
axiosClient
.put(uri, trainerModel)
.then(success => successCallback(success))
.catch(error => errorCallback(error));
};
module.exports = {
getTrainers,
getTrainer,
postTrainer,
putTrainer
};