diff options
author | Lauri Ojansivu <x@xet7.org> | 2019-06-27 15:27:14 -0400 |
---|---|---|
committer | Lauri Ojansivu <x@xet7.org> | 2019-06-27 15:27:14 -0400 |
commit | a0a482aa8efb3255a523de4524c8e09453d5571f (patch) | |
tree | ef64c00f146add91a484f7f6b27a40a785f459a0 /models/unsavedEdits.js | |
parent | fb728baf0c87bae5fa39d92089b667ff1ed69fa6 (diff) | |
parent | 3d63b6006b13942a887bbeddebb055d697451223 (diff) | |
download | wekan-a0a482aa8efb3255a523de4524c8e09453d5571f.tar.gz wekan-a0a482aa8efb3255a523de4524c8e09453d5571f.tar.bz2 wekan-a0a482aa8efb3255a523de4524c8e09453d5571f.zip |
Merge branch 'justinr1234-created-modified' into meteor-1.8
Diffstat (limited to 'models/unsavedEdits.js')
-rw-r--r-- | models/unsavedEdits.js | 73 |
1 files changed, 55 insertions, 18 deletions
diff --git a/models/unsavedEdits.js b/models/unsavedEdits.js index d4f3616a..122b2cd2 100644 --- a/models/unsavedEdits.js +++ b/models/unsavedEdits.js @@ -2,31 +2,66 @@ // `UnsavedEdits` API on the client. UnsavedEditCollection = new Mongo.Collection('unsaved-edits'); -UnsavedEditCollection.attachSchema(new SimpleSchema({ - fieldName: { - type: String, - }, - docId: { - type: String, - }, - value: { - type: String, - }, - userId: { - type: String, - autoValue() { // eslint-disable-line consistent-return - if (this.isInsert && !this.isSet) { - return this.userId; - } +UnsavedEditCollection.attachSchema( + new SimpleSchema({ + fieldName: { + type: String, }, - }, -})); + docId: { + type: String, + }, + value: { + type: String, + }, + userId: { + type: String, + // eslint-disable-next-line consistent-return + autoValue() { + if (this.isInsert && !this.isSet) { + return this.userId; + } + }, + }, + createdAt: { + type: Date, + optional: true, + // eslint-disable-next-line consistent-return + autoValue() { + if (this.isInsert) { + return new Date(); + } else { + this.unset(); + } + }, + }, + modifiedAt: { + type: Date, + denyUpdate: false, + // eslint-disable-next-line consistent-return + autoValue() { + if (this.isInsert || this.isUpsert || this.isUpdate) { + return new Date(); + } else { + this.unset(); + } + }, + }, + }) +); + +UnsavedEditCollection.before.update( + (userId, doc, fieldNames, modifier, options) => { + modifier.$set = modifier.$set || {}; + modifier.$set.modifiedAt = Date.now(); + } +); if (Meteor.isServer) { function isAuthor(userId, doc, fieldNames = []) { return userId === doc.userId && fieldNames.indexOf('userId') === -1; } Meteor.startup(() => { + UnsavedEditCollection._collection._ensureIndex({ modifiedAt: -1 }); UnsavedEditCollection._collection._ensureIndex({ userId: 1 }); }); UnsavedEditCollection.allow({ @@ -36,3 +71,5 @@ if (Meteor.isServer) { fetch: ['userId'], }); } + +export default UnsavedEditCollection; |