-
Notifications
You must be signed in to change notification settings - Fork 12
/
models.js
executable file
·63 lines (56 loc) · 1.56 KB
/
models.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
/*jshint esversion: 6 */
import _ from 'lodash';
Globals = new Mongo.Collection('globals');
Orders = new Mongo.Collection('orders');
Contacts = new Mongo.Collection('contacts');
PickupDocs = new Mongo.Collection('PickupDocs');
PODDocs = new Mongo.Collection('PODDocs');
Drivers = new Mongo.Collection('Drivers');
Deliveries = new Mongo.Collection('deliveries');
if (Meteor.isCordova) {
Ground.Collection(Deliveries);
Ground.Collection(Meteor.users);
}
if (Meteor.isServer) {
Deliveries._ensureIndex({ "changed": 1 });
Deliveries._ensureIndex({ "driver_details.name": 1 });
Deliveries._ensureIndex({ "driver_details.Uid": 1 });
Meteor.publish("deliveries", function (options = { limit: 5 }) {
_.defaults(options, {limit:20, sort: { changed: -1 } });
if (this.userId) {
var account = Accounts.users.findOne(this.userId);
if (account.username == "admin") {
return Deliveries.find({}, options);
} else {
return Deliveries.find(
{
$and:
[
{ "driver_details.Uid": account.Uid },
/*{
"changed": { $gt:
look ar using session variables to set delivery limits
} */
]
}, options
);
}
}
});
}
Deliveries.allow({
update: function (userId, delivery, fields, modifier) {
if (userId) {
return true;
} else {
return false;
}
}
});
if (Meteor.isClient) {
Session.set('jobLimit', Meteor.settings.public.jobLimit || 5);
Tracker.autorun(function () {
Meteor.subscribe("deliveries", { limit: Session.get('jobLimit')});
});
}
Depots = new Mongo.Collection('Depots');