-
Notifications
You must be signed in to change notification settings - Fork 0
/
notify.js
62 lines (58 loc) · 1.58 KB
/
notify.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const axios = require('axios')
const db = require('./Database/index');
const { findOneAndUpdate } = require('./Database/Models/mark');
let PSID = 3969607053094746;
let message = "Salut Mec";
// axios
// .post('https://notif-juniapocket.herokuapp.com/messenger', {
// psid: 'PSID',
// message: message
// })
// .then(res => {
// console.log(`statusCode: ${res.statusCode}`)
// console.log(res)
// })
// .catch(error => {
// console.error(error)
// })
module.exports = async (aurionID, notifTitle, content) => {
/**
* @param {String} aurionID
* @param {String} notifTitle
* @param {String} content
* @return {Bool}
*/
let preferenceDoc = await db.search.findUserByAurionIDInCollection(aurionID, db.Models.NotifPreferences);
if (preferenceDoc.mail != '') {
axios
.post('https://notif-juniapocket.herokuapp.com/email', {
email: preferenceDoc.mail,
object: notifTitle,
content: content
})
.then(res => {
console.log(`statusCode: ${res.statusCode}`);
// console.log(res);
})
.catch(error => {
console.error(error);
return false;
})
}
if (preferenceDoc.messengerPSID != '') {
axios
.post('https://notif-juniapocket.herokuapp.com/messenger', {
psid: preferenceDoc.messengerPSID,
message: notifTitle + '\n' + content
})
.then(res => {
console.log(`statusCode: ${res.statusCode}`);
// console.log(res);
})
.catch(error => {
console.error(error);
return false;
})
}
return true;
}