@dhyasama/totem-models 11.79.0 → 11.81.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/Organization.js +52 -0
- package/package.json +1 -1
package/lib/Organization.js
CHANGED
|
@@ -1721,6 +1721,58 @@ module.exports = function(mongoose, config) {
|
|
|
1721
1721
|
|
|
1722
1722
|
};
|
|
1723
1723
|
|
|
1724
|
+
Organization.statics.getNotesForOrgs = function getNotesForOrgs(orgIds, customerId, startDate, endDate, options, cb) {
|
|
1725
|
+
|
|
1726
|
+
const self = this;
|
|
1727
|
+
|
|
1728
|
+
if (!cb) {
|
|
1729
|
+
throw new Error('cb is required');
|
|
1730
|
+
}
|
|
1731
|
+
if (!orgIds) {
|
|
1732
|
+
return cb(new Error('orgIds is required'), null);
|
|
1733
|
+
}
|
|
1734
|
+
if (!options) {
|
|
1735
|
+
return cb(new Error('options is required'), null);
|
|
1736
|
+
}
|
|
1737
|
+
if (!customerId) {
|
|
1738
|
+
return cb(new Error('customerId is required'), null);
|
|
1739
|
+
}
|
|
1740
|
+
if (!startDate) {
|
|
1741
|
+
return cb(new Error('startDate is required'), null);
|
|
1742
|
+
}
|
|
1743
|
+
if (!endDate) {
|
|
1744
|
+
return cb(new Error('endDate is required'), null);
|
|
1745
|
+
}
|
|
1746
|
+
|
|
1747
|
+
let query = self
|
|
1748
|
+
.find( {'_id': { $in : orgIds } } )
|
|
1749
|
+
.select('_id notes')
|
|
1750
|
+
.populate({
|
|
1751
|
+
path: 'notes',
|
|
1752
|
+
match: {
|
|
1753
|
+
customer: customerId,
|
|
1754
|
+
createdOn: { $gte: startDate, $lte: endDate }
|
|
1755
|
+
},
|
|
1756
|
+
populate: {
|
|
1757
|
+
path: 'createdBy',
|
|
1758
|
+
select: 'name avatarUrl'
|
|
1759
|
+
}
|
|
1760
|
+
})
|
|
1761
|
+
|
|
1762
|
+
query.exec(function(err, result) {
|
|
1763
|
+
|
|
1764
|
+
if (err) { return cb(err, null); }
|
|
1765
|
+
|
|
1766
|
+
result = _.filter(result, function(org) {
|
|
1767
|
+
return org.notes.length > 0;
|
|
1768
|
+
});
|
|
1769
|
+
|
|
1770
|
+
return cb(null, result);
|
|
1771
|
+
|
|
1772
|
+
});
|
|
1773
|
+
|
|
1774
|
+
};
|
|
1775
|
+
|
|
1724
1776
|
Organization.statics.getList = function getList(cb) {
|
|
1725
1777
|
|
|
1726
1778
|
const self = this;
|