-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
82 lines (61 loc) · 2.03 KB
/
Copy pathserver.js
File metadata and controls
82 lines (61 loc) · 2.03 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const csvtojson=require('csvtojson')
const MongoClient = require("mongodb");
const httpRequest = require('request-promise-native');
require("request")
const SMS_SENDER ='BVMSMS'
const SMS_API_KEY = 'nQUvI2XjO3M-W9uZ3C5SJtuSb7J0oszstuigTazIfT';
var SMS_TEST;
const sender = SMS_SENDER;
const apiKey = SMS_API_KEY;
var test = 'true';
MongoClient.connect("mongodb+srv://udaan18:udaan18@udaan18-dj1tc.mongodb.net/",(err,client)=>{
if(err){
return console.log("unable to connect")
}
var db= client.db("Udaan-19")
const data = async function() {
var res= await csvtojson().fromFile("./data.csv");
res.forEach((event)=>{
db.collection("events").findOne({eventName:event.EventName}).then((doc)=>{
var numbers=doc.participants.join(",");
doc.participants.forEach((participant)=>{
db.collection('participants').updateMany({
phone:participant,
"events.eventName": doc.eventName
},{
$inc:{
"events.$.round":1
}
},{
returnOriginal:false
}).then((individual)=>{},(err)=>{})
})
// TODO Default message
const message = `Dear Participant, Round 1 of ${doc.eventName} is on ${event.Date} ${event.Time} at ${event.Venue}. Kindly be present at the venue on time.`;
const apiRequest = {
url: 'http://api.textlocal.in/send',
form: {
apiKey,
numbers,
test,
sender,
custom: doc.eventName,
message,
// receiptUrl: 'http://udaan18-messenger.herokuapp.com/textlocal'
}
};
httpRequest.post(apiRequest).then((res)=>{
var res1=JSON.parse(res);
if (res1.status === 'success') {
console.log("success : "+doc.eventName);
} else {
console.log('error');
}
});
})
})
}
data().catch((e)=>{
console.log(e.message);
})
})