summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornztqa <nztqa@users.noreply.github.com>2017-06-28 15:19:53 +0900
committernztqa <nztqa@users.noreply.github.com>2017-06-28 15:19:53 +0900
commite03c69ab8febc6093d092221724b3190a2da351d (patch)
tree4c9e354b1578273555dcdc68dd3b94bd2be0c827
parent60495e4765363b95e8e1859406d80c5588062e14 (diff)
downloadwekan-e03c69ab8febc6093d092221724b3190a2da351d.tar.gz
wekan-e03c69ab8febc6093d092221724b3190a2da351d.tar.bz2
wekan-e03c69ab8febc6093d092221724b3190a2da351d.zip
Fix: id generation
-rw-r--r--models/checklists.js8
1 files changed, 7 insertions, 1 deletions
diff --git a/models/checklists.js b/models/checklists.js
index 537aecb0..0ee62fa2 100644
--- a/models/checklists.js
+++ b/models/checklists.js
@@ -86,7 +86,13 @@ Checklists.mutations({
//for items in checklist
addItem(title) {
const itemCount = this.itemCount();
- const _id = `${this._id}${itemCount}`;
+ let idx = 0;
+ if (itemCount > 0) {
+ const lastId = this.items[itemCount - 1]._id;
+ const lastIdSuffix = lastId.substr(this._id.length);
+ idx = parseInt(lastIdSuffix, 10) + 1;
+ }
+ const _id = `${this._id}${idx}`;
return { $addToSet: { items: { _id, title, isFinished: false } } };
},
removeItem(itemId) {