From bf7de463f1f71f1758b62187667bf3a7e55585ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Manelli?= Date: Mon, 19 Mar 2018 00:25:19 -0300 Subject: Add checklist items model, migration and publication --- models/checklists.js | 35 +++++++++-------------------------- 1 file changed, 9 insertions(+), 26 deletions(-) (limited to 'models/checklists.js') diff --git a/models/checklists.js b/models/checklists.js index 7eb0a24f..d9b15140 100644 --- a/models/checklists.js +++ b/models/checklists.js @@ -7,24 +7,6 @@ Checklists.attachSchema(new SimpleSchema({ title: { type: String, }, - items: { - type: [Object], - defaultValue: [], - }, - 'items.$._id': { - type: String, - }, - 'items.$.title': { - type: String, - }, - 'items.$.sort': { - type: Number, - decimal: true, - }, - 'items.$.isFinished': { - type: Boolean, - defaultValue: false, - }, finishedAt: { type: Date, optional: true, @@ -46,19 +28,20 @@ Checklists.attachSchema(new SimpleSchema({ }, })); -const self = Checklists; - Checklists.helpers({ itemCount() { - return this.items.length; + return ChecklistItems.find({ checklistId: this._id }).count(); }, - getItemsSorted() { - return _.sortBy(this.items, 'sort'); + items() { + return ChecklistItems.find(Filter.mongoSelector({ + checklistId: this._id, + }), { sort: ['sort'] }); }, finishedCount() { - return this.items.filter((item) => { - return item.isFinished; - }).length; + return ChecklistItems.find({ + checklistId: this._id, + isFinished: true, + }).count(); }, isFinished() { return 0 !== this.itemCount() && this.itemCount() === this.finishedCount(); -- cgit v1.2.3-1-g7c22