mirror of
https://github.com/wekan/wekan.git
synced 2025-12-16 15:30:13 +01:00
Fix problem with dates in selector being unpickled as a String
This commit is contained in:
parent
223cc07139
commit
a63a61e7fc
3 changed files with 61 additions and 24 deletions
|
|
@ -363,13 +363,13 @@ BlazeComponent.extendComponent({
|
|||
if (date) {
|
||||
value = {
|
||||
operator: '$lt',
|
||||
value: date.format(),
|
||||
value: date.format('YYYY-MM-DD'),
|
||||
};
|
||||
}
|
||||
} else if (operator === 'dueAt' && value === 'overdue') {
|
||||
value = {
|
||||
operator: '$lt',
|
||||
value: moment(moment().format('YYYY-MM-DD')).format(),
|
||||
value: moment().format('YYYY-MM-DD'),
|
||||
};
|
||||
} else {
|
||||
this.parsingErrors.push({
|
||||
|
|
|
|||
|
|
@ -143,36 +143,73 @@ SessionData.helpers({
|
|||
|
||||
SessionData.unpickle = pickle => {
|
||||
return JSON.parse(pickle, (key, value) => {
|
||||
if (value === null) {
|
||||
return null;
|
||||
} else if (typeof value === 'object') {
|
||||
// eslint-disable-next-line no-prototype-builtins
|
||||
if (value.hasOwnProperty('$$class')) {
|
||||
if (value.$$class === 'RegExp') {
|
||||
return new RegExp(value.source, value.flags);
|
||||
}
|
||||
}
|
||||
}
|
||||
return value;
|
||||
return unpickleValue(value);
|
||||
});
|
||||
};
|
||||
|
||||
function unpickleValue(value) {
|
||||
if (value === null) {
|
||||
return null;
|
||||
} else if (typeof value === 'object') {
|
||||
// eslint-disable-next-line no-prototype-builtins
|
||||
if (value.hasOwnProperty('$$class')) {
|
||||
switch (value.$$class) {
|
||||
case 'RegExp':
|
||||
return new RegExp(value.source, value.flags);
|
||||
case 'Date':
|
||||
return new Date(value.stringValue);
|
||||
case 'Object':
|
||||
return unpickleObject(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
function unpickleObject(obj) {
|
||||
const newObject = {};
|
||||
Object.entries(obj).forEach(([key, value]) => {
|
||||
newObject[key] = unpickleValue(value);
|
||||
});
|
||||
return newObject;
|
||||
}
|
||||
|
||||
SessionData.pickle = value => {
|
||||
return JSON.stringify(value, (key, value) => {
|
||||
if (value === null) {
|
||||
return null;
|
||||
} else if (typeof value === 'object') {
|
||||
if (value.constructor.name === 'RegExp') {
|
||||
return pickleValue(value);
|
||||
});
|
||||
};
|
||||
|
||||
function pickleValue(value) {
|
||||
if (value === null) {
|
||||
return null;
|
||||
} else if (typeof value === 'object') {
|
||||
switch(value.constructor.name) {
|
||||
case 'RegExp':
|
||||
return {
|
||||
$$class: 'RegExp',
|
||||
source: value.source,
|
||||
flags: value.flags,
|
||||
};
|
||||
}
|
||||
case 'Date':
|
||||
return {
|
||||
$$class: 'Date',
|
||||
stringValue: String(value),
|
||||
};
|
||||
case 'Object':
|
||||
return pickleObject(value);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
function pickleObject(obj) {
|
||||
const newObject = {};
|
||||
Object.entries(obj).forEach(([key, value]) => {
|
||||
newObject[key] = pickleValue(value);
|
||||
});
|
||||
};
|
||||
return newObject;
|
||||
}
|
||||
|
||||
if (!Meteor.isServer) {
|
||||
SessionData.getSessionId = () => {
|
||||
|
|
|
|||
|
|
@ -751,19 +751,19 @@ Meteor.publish('previousPage', function(sessionId) {
|
|||
});
|
||||
|
||||
function findCards(sessionId, selector, projection, errors = null) {
|
||||
// check(selector, Object);
|
||||
// check(projection, Object);
|
||||
const userId = Meteor.userId();
|
||||
|
||||
console.log('selector:', selector);
|
||||
console.log('projection:', projection);
|
||||
|
||||
// if (selector.dueAt) {
|
||||
// console.log('dueAt:', typeof selector.dueAt.$lt, selector.dueAt.$lt.constructor.name, selector.dueAt.$lt);
|
||||
// }
|
||||
let cards;
|
||||
if (!errors || !errors.hasErrors()) {
|
||||
cards = Cards.find(selector, projection);
|
||||
}
|
||||
|
||||
console.log('count:', cards.count());
|
||||
|
||||
const update = {
|
||||
$set: {
|
||||
totalHits: 0,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue