diff options
author | Alexander Sulfrian <alexander.sulfrian@fu-berlin.de> | 2016-04-22 00:59:05 +0200 |
---|---|---|
committer | Alexander Sulfrian <alexander.sulfrian@fu-berlin.de> | 2016-06-03 03:56:35 +0200 |
commit | a2888250f4ab3615c1590ab3bbf90302963a7c57 (patch) | |
tree | f72abd0d33187b8240b913fdb2490d1e85fc7b6c /models/lists.js | |
parent | 14e2b3c15fdaaa7a45716041dd9e44740a747b26 (diff) | |
download | wekan-a2888250f4ab3615c1590ab3bbf90302963a7c57.tar.gz wekan-a2888250f4ab3615c1590ab3bbf90302963a7c57.tar.bz2 wekan-a2888250f4ab3615c1590ab3bbf90302963a7c57.zip |
Models: Replace before.insert with autoValues
The before.insert hooks have the problem, that they are executed in a
different order if called from the client or from the server. If called
from the client, the before.insert hook is called before validation of
the schema, but if called from the server, the validation is called
first and fails.
Diffstat (limited to 'models/lists.js')
-rw-r--r-- | models/lists.js | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/models/lists.js b/models/lists.js index 4e4a1134..a4938f67 100644 --- a/models/lists.js +++ b/models/lists.js @@ -6,13 +6,24 @@ Lists.attachSchema(new SimpleSchema({ }, archived: { type: Boolean, + autoValue() { // eslint-disable-line consistent-return + if (this.isInsert && !this.isSet) { + return false; + } + }, }, boardId: { type: String, }, createdAt: { type: Date, - denyUpdate: true, + autoValue() { // eslint-disable-line consistent-return + if (this.isInsert) { + return new Date(); + } else { + this.unset(); + } + }, }, sort: { type: Number, @@ -22,8 +33,14 @@ Lists.attachSchema(new SimpleSchema({ }, updatedAt: { type: Date, - denyInsert: true, optional: true, + autoValue() { // eslint-disable-line consistent-return + if (this.isUpdate) { + return new Date(); + } else { + this.unset(); + } + }, }, })); @@ -73,18 +90,6 @@ Lists.mutations({ Lists.hookOptions.after.update = { fetchPrevious: false }; -Lists.before.insert((userId, doc) => { - doc.createdAt = new Date(); - doc.archived = false; - if (!doc.userId) - doc.userId = userId; -}); - -Lists.before.update((userId, doc, fieldNames, modifier) => { - modifier.$set = modifier.$set || {}; - modifier.$set.modifiedAt = new Date(); -}); - if (Meteor.isServer) { Lists.after.insert((userId, doc) => { Activities.insert({ |