-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmethods.js
161 lines (138 loc) · 4.06 KB
/
methods.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
Push.debug = true;
Push.allow({
send: function (userId, notification) {
return true; // Allow all users to send
}
});
Meteor.methods({
"makeAdmin": function (nic) {
var townsman = Meteor.users.findOne({username: nic});
Meteor.users.update({_id: townsman._id},
{$set: {"profile.userType": "admin"}})
},
"findAdminID": function () {
var adminID = Meteor.users.findOne({"profile.userType": 'admin'})._id;
console.log('admin ID is ' + adminID);
return adminID;
},
"updateTruckLocation": function (truckID, lat, lng) {
Trucks.update({_id: truckID},
{
$set: {
lat: lat,
lng: lng
}
}
);
console.log("DB Truck " + truckID + " location updated");
},
"dlNoti": function () {
Notifications.remove({});
},
"dlDrivers": function () {
Drivers.remove({});
},
"dlRoutes": function () {
Routes.remove({});
},
"dlTrucks": function () {
Trucks.remove({});
},
"saveNoti": function (notiPoints, route_id, user_id) {
console.log(notiPoints);
Notifications.insert({'points': notiPoints, 'user_id': user_id, 'route_id': route_id});
},
"setTruckOnDuty": function (truck_id) {
Trucks.update({_id: truck_id},
{
$set: {
onDuty: true
}
}
);
console.log("DB Truck " + truck_id + " set OnDuty true");
},
"setRouteActive": function (route_id) {
Routes.update({_id: route_id},
{
$set: {
active: true
}
}
);
console.log("DB Truck " + route_id + " set active true");
},
"updateMyLocation": function (user_id, pos) {
Meteor.users.update({_id: user_id},
{$set: {"profile.location": pos}})
},
"serverNotification": function (text, title) {
var badge = 1;
Push.send({
from: 'push',
title: title,
text: text,
badge: badge,
query: {
// this will send to all users
}
});
},
"occupyTime": function (startTime, day, driverNIC, truckNO) {
console.log(driverNIC);
console.log(truckNO);
console.log(startTime);
console.log(day);
// make new JSON object
var newBusyHours = {'day': day, 'startTime': startTime};
// set driver's busy time
var driver = Drivers.findOne({nic: driverNIC});
// get current busy hours if available
var currentBusyHours = driver.busyHours;
if (currentBusyHours) {
var str = JSON.parse(currentBusyHours);
str.push(newBusyHours);
Drivers.update({nic: driverNIC},
{
$set: {
busyHours: JSON.stringify(str)
}
}
);
}
else {
Drivers.update({nic: driverNIC},
{
$set: {
busyHours: '['+JSON.stringify(newBusyHours)+']'
}
}
);
}
// set truck's busy time
var truck = Trucks.findOne({license: truckNO});
console.log(truck);
// get current busy hours if available
var currentBusyHours = truck.busyHours;
if (currentBusyHours) {
var str = JSON.parse(currentBusyHours);
str.push(newBusyHours);
Trucks.update({license: truckNO},
{
$set: {
busyHours: JSON.stringify(str)
}
}
);
}
else {
Trucks.update({license: truckNO},
{
$set: {
busyHours: '['+JSON.stringify(newBusyHours)+']'
}
}
);
}
}
});