mirror of
https://github.com/wekan/wekan.git
synced 2025-12-16 15:30:13 +01:00
Fixes #2596 incorrect date types for created & updated
This commit is contained in:
parent
2c78aab3dc
commit
3b9f2ca7c2
22 changed files with 103 additions and 33 deletions
|
|
@ -20,6 +20,8 @@ AccountSettings.attachSchema(
|
||||||
autoValue() {
|
autoValue() {
|
||||||
if (this.isInsert) {
|
if (this.isInsert) {
|
||||||
return new Date();
|
return new Date();
|
||||||
|
} else if (this.isUpsert) {
|
||||||
|
return { $setOnInsert: new Date() };
|
||||||
} else {
|
} else {
|
||||||
this.unset();
|
this.unset();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,16 @@ Actions.allow({
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Actions.before.insert((userId, doc) => {
|
||||||
|
doc.createdAt = new Date();
|
||||||
|
doc.modifiedAt = doc.createdAt;
|
||||||
|
});
|
||||||
|
|
||||||
|
Actions.before.update((userId, doc, fieldNames, modifier) => {
|
||||||
|
modifier.$set = modifier.$set || {};
|
||||||
|
modifier.$set.modifiedAt = new Date();
|
||||||
|
});
|
||||||
|
|
||||||
Actions.helpers({
|
Actions.helpers({
|
||||||
description() {
|
description() {
|
||||||
return this.desc;
|
return this.desc;
|
||||||
|
|
|
||||||
|
|
@ -62,8 +62,14 @@ Activities.helpers({
|
||||||
//},
|
//},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Activities.before.update((userId, doc, fieldNames, modifier) => {
|
||||||
|
modifier.$set = modifier.$set || {};
|
||||||
|
modifier.$set.modifiedAt = new Date();
|
||||||
|
});
|
||||||
|
|
||||||
Activities.before.insert((userId, doc) => {
|
Activities.before.insert((userId, doc) => {
|
||||||
doc.createdAt = new Date();
|
doc.createdAt = new Date();
|
||||||
|
doc.modifiedAt = doc.createdAt;
|
||||||
});
|
});
|
||||||
|
|
||||||
Activities.after.insert((userId, doc) => {
|
Activities.after.insert((userId, doc) => {
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,8 @@ Announcements.attachSchema(
|
||||||
autoValue() {
|
autoValue() {
|
||||||
if (this.isInsert) {
|
if (this.isInsert) {
|
||||||
return new Date();
|
return new Date();
|
||||||
|
} else if (this.isUpsert) {
|
||||||
|
return { $setOnInsert: new Date() };
|
||||||
} else {
|
} else {
|
||||||
this.unset();
|
this.unset();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,8 @@ Boards.attachSchema(
|
||||||
autoValue() {
|
autoValue() {
|
||||||
if (this.isInsert) {
|
if (this.isInsert) {
|
||||||
return new Date();
|
return new Date();
|
||||||
|
} else if (this.isUpsert) {
|
||||||
|
return { $setOnInsert: new Date() };
|
||||||
} else {
|
} else {
|
||||||
this.unset();
|
this.unset();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,8 @@ CardComments.attachSchema(
|
||||||
autoValue() {
|
autoValue() {
|
||||||
if (this.isInsert) {
|
if (this.isInsert) {
|
||||||
return new Date();
|
return new Date();
|
||||||
|
} else if (this.isUpsert) {
|
||||||
|
return { $setOnInsert: new Date() };
|
||||||
} else {
|
} else {
|
||||||
this.unset();
|
this.unset();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -107,6 +107,8 @@ Cards.attachSchema(
|
||||||
autoValue() {
|
autoValue() {
|
||||||
if (this.isInsert) {
|
if (this.isInsert) {
|
||||||
return new Date();
|
return new Date();
|
||||||
|
} else if (this.isUpsert) {
|
||||||
|
return { $setOnInsert: new Date() };
|
||||||
} else {
|
} else {
|
||||||
this.unset();
|
this.unset();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,8 @@ ChecklistItems.attachSchema(
|
||||||
autoValue() {
|
autoValue() {
|
||||||
if (this.isInsert) {
|
if (this.isInsert) {
|
||||||
return new Date();
|
return new Date();
|
||||||
|
} else if (this.isUpsert) {
|
||||||
|
return { $setOnInsert: new Date() };
|
||||||
} else {
|
} else {
|
||||||
this.unset();
|
this.unset();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,8 @@ Checklists.attachSchema(
|
||||||
autoValue() {
|
autoValue() {
|
||||||
if (this.isInsert) {
|
if (this.isInsert) {
|
||||||
return new Date();
|
return new Date();
|
||||||
|
} else if (this.isUpsert) {
|
||||||
|
return { $setOnInsert: new Date() };
|
||||||
} else {
|
} else {
|
||||||
this.unset();
|
this.unset();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -78,6 +78,8 @@ CustomFields.attachSchema(
|
||||||
autoValue() {
|
autoValue() {
|
||||||
if (this.isInsert) {
|
if (this.isInsert) {
|
||||||
return new Date();
|
return new Date();
|
||||||
|
} else if (this.isUpsert) {
|
||||||
|
return { $setOnInsert: new Date() };
|
||||||
} else {
|
} else {
|
||||||
this.unset();
|
this.unset();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,8 @@ Integrations.attachSchema(
|
||||||
autoValue() {
|
autoValue() {
|
||||||
if (this.isInsert) {
|
if (this.isInsert) {
|
||||||
return new Date();
|
return new Date();
|
||||||
|
} else if (this.isUpsert) {
|
||||||
|
return { $setOnInsert: new Date() };
|
||||||
} else {
|
} else {
|
||||||
this.unset();
|
this.unset();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,8 @@ InvitationCodes.attachSchema(
|
||||||
autoValue() {
|
autoValue() {
|
||||||
if (this.isInsert) {
|
if (this.isInsert) {
|
||||||
return new Date();
|
return new Date();
|
||||||
|
} else if (this.isUpsert) {
|
||||||
|
return { $setOnInsert: new Date() };
|
||||||
} else {
|
} else {
|
||||||
this.unset();
|
this.unset();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,8 @@ Lists.attachSchema(
|
||||||
autoValue() {
|
autoValue() {
|
||||||
if (this.isInsert) {
|
if (this.isInsert) {
|
||||||
return new Date();
|
return new Date();
|
||||||
|
} else if (this.isUpsert) {
|
||||||
|
return { $setOnInsert: new Date() };
|
||||||
} else {
|
} else {
|
||||||
this.unset();
|
this.unset();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -98,6 +98,8 @@ Org.attachSchema(
|
||||||
autoValue() {
|
autoValue() {
|
||||||
if (this.isInsert) {
|
if (this.isInsert) {
|
||||||
return new Date();
|
return new Date();
|
||||||
|
} else if (this.isUpsert) {
|
||||||
|
return { $setOnInsert: new Date() };
|
||||||
} else {
|
} else {
|
||||||
this.unset();
|
this.unset();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,8 @@ OrgUser.attachSchema(
|
||||||
autoValue() {
|
autoValue() {
|
||||||
if (this.isInsert) {
|
if (this.isInsert) {
|
||||||
return new Date();
|
return new Date();
|
||||||
|
} else if (this.isUpsert) {
|
||||||
|
return { $setOnInsert: new Date() };
|
||||||
} else {
|
} else {
|
||||||
this.unset();
|
this.unset();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,8 @@ Rules.attachSchema(
|
||||||
autoValue() {
|
autoValue() {
|
||||||
if (this.isInsert) {
|
if (this.isInsert) {
|
||||||
return new Date();
|
return new Date();
|
||||||
|
} else if (this.isUpsert) {
|
||||||
|
return { $setOnInsert: new Date() };
|
||||||
} else {
|
} else {
|
||||||
this.unset();
|
this.unset();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,8 @@ Settings.attachSchema(
|
||||||
autoValue() {
|
autoValue() {
|
||||||
if (this.isInsert) {
|
if (this.isInsert) {
|
||||||
return new Date();
|
return new Date();
|
||||||
|
} else if (this.isUpsert) {
|
||||||
|
return { $setOnInsert: new Date() };
|
||||||
} else {
|
} else {
|
||||||
this.unset();
|
this.unset();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,8 @@ Swimlanes.attachSchema(
|
||||||
autoValue() {
|
autoValue() {
|
||||||
if (this.isInsert) {
|
if (this.isInsert) {
|
||||||
return new Date();
|
return new Date();
|
||||||
|
} else if (this.isUpsert) {
|
||||||
|
return { $setOnInsert: new Date() };
|
||||||
} else {
|
} else {
|
||||||
this.unset();
|
this.unset();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,16 @@ Triggers.mutations({
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Triggers.before.insert((userId, doc) => {
|
||||||
|
doc.createdAt = new Date();
|
||||||
|
doc.updatedAt = doc.createdAt;
|
||||||
|
});
|
||||||
|
|
||||||
|
Triggers.before.update((userId, doc, fieldNames, modifier) => {
|
||||||
|
modifier.$set = modifier.$set || {};
|
||||||
|
modifier.$set.updatedAt = new Date();
|
||||||
|
});
|
||||||
|
|
||||||
Triggers.allow({
|
Triggers.allow({
|
||||||
insert(userId, doc) {
|
insert(userId, doc) {
|
||||||
return allowIsBoardAdmin(userId, Boards.findOne(doc.boardId));
|
return allowIsBoardAdmin(userId, Boards.findOne(doc.boardId));
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,8 @@ UnsavedEditCollection.attachSchema(
|
||||||
autoValue() {
|
autoValue() {
|
||||||
if (this.isInsert) {
|
if (this.isInsert) {
|
||||||
return new Date();
|
return new Date();
|
||||||
|
} else if (this.isUpsert) {
|
||||||
|
return { $setOnInsert: new Date() };
|
||||||
} else {
|
} else {
|
||||||
this.unset();
|
this.unset();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,8 @@ Users.attachSchema(
|
||||||
autoValue() {
|
autoValue() {
|
||||||
if (this.isInsert) {
|
if (this.isInsert) {
|
||||||
return new Date();
|
return new Date();
|
||||||
|
} else if (this.isUpsert) {
|
||||||
|
return { $setOnInsert: new Date() };
|
||||||
} else {
|
} else {
|
||||||
this.unset();
|
this.unset();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -684,39 +684,6 @@ Migrations.add('mutate-boardIds-in-customfields', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
const firstBatchOfDbsToAddCreatedAndUpdated = [
|
|
||||||
AccountSettings,
|
|
||||||
Actions,
|
|
||||||
Activities,
|
|
||||||
Announcements,
|
|
||||||
Boards,
|
|
||||||
CardComments,
|
|
||||||
Cards,
|
|
||||||
ChecklistItems,
|
|
||||||
Checklists,
|
|
||||||
CustomFields,
|
|
||||||
Integrations,
|
|
||||||
InvitationCodes,
|
|
||||||
Lists,
|
|
||||||
Rules,
|
|
||||||
Settings,
|
|
||||||
Swimlanes,
|
|
||||||
Triggers,
|
|
||||||
UnsavedEdits,
|
|
||||||
];
|
|
||||||
|
|
||||||
firstBatchOfDbsToAddCreatedAndUpdated.forEach(db => {
|
|
||||||
db.before.insert((userId, doc) => {
|
|
||||||
doc.createdAt = Date.now();
|
|
||||||
doc.updatedAt = doc.createdAt;
|
|
||||||
});
|
|
||||||
|
|
||||||
db.before.update((userId, doc, fieldNames, modifier) => {
|
|
||||||
modifier.$set = modifier.$set || {};
|
|
||||||
modifier.$set.updatedAt = new Date();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
const modifiedAtTables = [
|
const modifiedAtTables = [
|
||||||
AccountSettings,
|
AccountSettings,
|
||||||
Actions,
|
Actions,
|
||||||
|
|
@ -769,3 +736,44 @@ Migrations.add('add-missing-created-and-modified', () => {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Migrations.add('fix-incorrect-dates', () => {
|
||||||
|
const tables = [
|
||||||
|
AccountSettings,
|
||||||
|
Actions,
|
||||||
|
Activities,
|
||||||
|
Announcements,
|
||||||
|
Boards,
|
||||||
|
CardComments,
|
||||||
|
Cards,
|
||||||
|
ChecklistItems,
|
||||||
|
Checklists,
|
||||||
|
CustomFields,
|
||||||
|
Integrations,
|
||||||
|
InvitationCodes,
|
||||||
|
Lists,
|
||||||
|
Rules,
|
||||||
|
Settings,
|
||||||
|
Swimlanes,
|
||||||
|
Triggers,
|
||||||
|
UnsavedEdits,
|
||||||
|
];
|
||||||
|
|
||||||
|
// Dates were previously created with Date.now() which is a number, not a date
|
||||||
|
tables.forEach(t =>
|
||||||
|
t
|
||||||
|
.rawCollection()
|
||||||
|
.find({ $or: [{ createdAt: { $type: 1 } }, { updatedAt: { $type: 1 } }] })
|
||||||
|
.forEach(({ _id, createdAt, updatedAt }) => {
|
||||||
|
t.rawCollection().update(
|
||||||
|
{ _id },
|
||||||
|
{
|
||||||
|
$set: {
|
||||||
|
createdAt: new Date(createdAt),
|
||||||
|
updatedAt: new Date(updatedAt),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue