Commit d914427a authored by Samir Sadyhov's avatar Samir Sadyhov 🤔

appAPI - add sendNotification

parent 92108633
...@@ -607,5 +607,30 @@ this.appAPI = { ...@@ -607,5 +607,30 @@ this.appAPI = {
resolve(null); resolve(null);
}); });
}); });
},
sendNotification: async function(body) {
return new Promise(async resolve => {
try {
const {defaultUser, defaultUserPassword} = Cons.getCurrentApp();
const auth = "Basic " + btoa(unescape(encodeURIComponent(`${defaultUser}:${defaultUserPassword}`)));
const url = `../Synergy/rest/api/notifications/send`;
const response = await fetch(url, {
method: 'POST',
headers: {"Authorization": auth, "Content-Type": "application/json; charset=UTF-8"},
body: JSON.stringify(body)
});
if(!response.ok) {
let rt = await response.text();
rt = JSON.parse(rt);
throw new Error(`http: ${response.status}, message: ${response.statusText}, errorMessage: ${rt.errorMessage}`);
}
resolve(response.json());
} catch (err) {
console.log(`ERROR [ sendNotification ]: ${err.message}`);
resolve(null);
}
});
} }
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment