mirror of
https://github.com/wekan/wekan.git
synced 2026-01-06 01:28:49 +01:00
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.
This commit is contained in:
parent
14e2b3c15f
commit
a2888250f4
6 changed files with 129 additions and 75 deletions
|
|
@ -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({
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue