mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 18:10:06 -05:00
Keep replacement trigger and action documents free of MongoDB update operators while preserving creation timestamps. Cover replacement and modifier updates independently. Thanks to xet7 !
29 lines
748 B
JavaScript
29 lines
748 B
JavaScript
import { ReactiveCache } from '/imports/reactiveCache';
|
|
import { Mongo } from 'meteor/mongo';
|
|
|
|
const Actions = new Mongo.Collection('actions');
|
|
|
|
Actions.before.insert((userId, doc) => {
|
|
doc.createdAt = new Date();
|
|
doc.modifiedAt = doc.createdAt;
|
|
});
|
|
|
|
Actions.before.update((userId, doc, fieldNames, modifier) => {
|
|
// Rule editing replaces documents; never mix replacement fields with $set.
|
|
if (Object.keys(modifier).some(key => key.startsWith('$'))) {
|
|
modifier.$set = modifier.$set || {};
|
|
modifier.$set.modifiedAt = new Date();
|
|
} else {
|
|
modifier.createdAt = doc.createdAt || new Date();
|
|
modifier.modifiedAt = new Date();
|
|
}
|
|
});
|
|
|
|
Actions.helpers({
|
|
description() {
|
|
return this.desc;
|
|
},
|
|
});
|
|
|
|
export default Actions;
|