From b627ced605f0ab98eb2977420da954f31df4f592 Mon Sep 17 00:00:00 2001 From: Nicu Tofan Date: Sun, 17 Jun 2018 22:55:01 +0300 Subject: Some inspiration from checklists to subtasks --- models/subtasks.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'models/subtasks.js') diff --git a/models/subtasks.js b/models/subtasks.js index 6c42072e..e842d11d 100644 --- a/models/subtasks.js +++ b/models/subtasks.js @@ -4,6 +4,29 @@ Subtasks.attachSchema(new SimpleSchema({ title: { type: String, }, + startAt: { // this is a predicted time + type: Date, + optional: true, + }, + endAt: { // this is a predicted time + type: Date, + optional: true, + }, + finishedAt: { // The date & time when it is marked as being done + type: Date, + optional: true, + }, + createdAt: { + type: Date, + denyUpdate: false, + autoValue() { // eslint-disable-line consistent-return + if (this.isInsert) { + return new Date(); + } else { + this.unset(); + } + }, + }, sort: { type: Number, decimal: true, @@ -17,6 +40,16 @@ Subtasks.attachSchema(new SimpleSchema({ }, })); +Subtasks.helpers({ + isFinished() { + return 0 !== this.itemCount() && this.itemCount() === this.finishedCount(); + }, + itemIndex(itemId) { + const items = self.findOne({_id : this._id}).items; + return _.pluck(items, '_id').indexOf(itemId); + }, +}); + Subtasks.allow({ insert(userId, doc) { return allowIsBoardMemberByCard(userId, Cards.findOne(doc.cardId)); @@ -31,6 +64,7 @@ Subtasks.allow({ }); Subtasks.before.insert((userId, doc) => { + doc.createdAt = new Date(); if (!doc.userId) { doc.userId = userId; } -- cgit v1.2.3-1-g7c22