| Current Path : /home/deltalab/PMS/partner-manager-backend/models/indaco-modules/ |
| Current File : //home/deltalab/PMS/partner-manager-backend/models/indaco-modules/indaco-module-registration.js |
// DEPENDENCIES ==========================================
const { gql, GraphQLClient } = require('graphql-request');
// grapqhl client
const pmsClient = new GraphQLClient(process.env.PMS_REGISTRATION_URL, {
headers: { 'x-api-key': process.env.PMS_REGISTRATION_API_KEY },
});
/**
* Register the specified module on the PMS
*/
function registerIndacoModuleAsync(moduleInfo) {
const registerModuleMutation = gql`
mutation registerIndacoModule ($module: IndacoModuleInput!) {
registerIndacoModule(record: $module) {
_id
}
}
`;
moduleRegistrationParams = {
module: moduleInfo
};
return pmsClient.request(registerModuleMutation, moduleRegistrationParams)
.then(result => console.log(`Registered module with id ${result.registerIndacoModule._id}`))
.catch(err => {
// In case of an error in registering the module, try again in 10 seconds.
console.log(err);
console.log('Retrying registration again in 10 seconds');
setTimeout(() => registerIndacoModuleAsync(moduleInfo), 10000);
});;
}
// EXPORTS ===============================================
module.exports = { registerIndacoModuleAsync }