Created
February 20, 2017 11:48
-
-
Save s7dhansh/bf0231e319b1c607d30bf435f072b1f5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Meteor.publishComposite('visits', function(params) { | |
if (!this.userId) throw new Meteor.Error(403, 'Not authorized to do this operation'); | |
check(params, Object); | |
check(params.date, Date); | |
if (!params.date) return null; | |
let date = params.date ? params.date : new Date(); | |
let $gte = new Date(date.setHours(0, 0, 0, 0)); | |
let $lt = moment($gte).add(1, 'd').toDate(); | |
let query = {}; | |
query.start = {$gte, $lt}; | |
if ((params.assignedTo || []).length) query.assignedTo = {$in: params.assignedTo}; | |
if (params.relationship) query.relationship = params.relationship; | |
else delete query.relationship; | |
if (params.status) query.status = params.status; | |
return [ | |
{ | |
find() { | |
return Visits.find(query, {sort: {start: 1}}); | |
// return Visits.find(query, {fields: {_version: 0, removed: 0}, sort: {start: 1}}); | |
}, | |
children: [ | |
{ | |
find(visit) { | |
return Units.find({_id: visit.unitId}, {fields: unitFields}); | |
} | |
}, | |
{ | |
find(visit) { | |
return Groups.find({_id: visit.groupId}, {fields: {_id: 1, type: 1, name: 1, units: 1, identifier: 1, members: 1, 'assignedTo.userId': 1}}); | |
} | |
} | |
] | |
}, | |
{ | |
// other relationship visits for count | |
find() { | |
query.relationship = {$ne: query.relationship}; | |
return Visits.find(query, {fields: {relationship: 1, status: 1}}); | |
}, | |
} | |
]; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment