Snapshot before refactoring the rule settings to a separate component
This commit is contained in:
parent
6fbbe9a497
commit
d0a714b3d4
6 changed files with 474 additions and 149 deletions
|
@ -20,11 +20,7 @@ exports.up = (knex, Promise) => (async() => {
|
|||
settings.groupTemplate = field.group_template;
|
||||
}
|
||||
|
||||
if (type === 'checkbox') {
|
||||
settings.groupTemplate = field.group_template;
|
||||
}
|
||||
|
||||
if (['dropdown', 'radio'].includes(type)) {
|
||||
if (['checkbox', 'dropdown', 'radio'].includes(type)) {
|
||||
settings.groupTemplate = field.group_template;
|
||||
type = type + '-grouped';
|
||||
}
|
||||
|
|
|
@ -40,19 +40,17 @@ exports.up = (knex, Promise) => (async() => {
|
|||
if (oldRule.column in predefColumns) {
|
||||
fieldType = predefColumns[oldRule.column];
|
||||
} else {
|
||||
const field = await knex('custom_fields').where({list: segment.list, type: 'like', column: oldRule.column}).select(['type']).first();
|
||||
const field = await knex('custom_fields').where({list: segment.list, column: oldRule.column}).select(['type']).first();
|
||||
if (field) {
|
||||
fieldType = field.type;
|
||||
}
|
||||
}
|
||||
|
||||
switch (fieldType) {
|
||||
case 'string':
|
||||
case 'text':
|
||||
case 'website':
|
||||
rules.push({ column: oldRule.column, value: oldSettings.value });
|
||||
break;
|
||||
case 'boolean':
|
||||
rules.push({ type: 'eq', column: oldRule.column, value: oldSettings.value });
|
||||
break;
|
||||
case 'number':
|
||||
if (oldSettings.range) {
|
||||
if (oldSettings.start && oldSettings.end) {
|
||||
|
@ -79,75 +77,54 @@ exports.up = (knex, Promise) => (async() => {
|
|||
}
|
||||
break;
|
||||
case 'birthday':
|
||||
if (oldSettings.range) {
|
||||
if (oldSettings.start && oldSettings.end) {
|
||||
if (type === 'all') {
|
||||
rules.push({ type: 'birthdayGe', column: oldRule.column, value: oldSettings.start});
|
||||
rules.push({ type: 'birthdayLe', column: oldRule.column, value: oldSettings.end});
|
||||
} else {
|
||||
rules.push({
|
||||
type: 'all',
|
||||
rules: [
|
||||
{ type: 'birthdayGe', column: oldRule.column, value: oldSettings.start},
|
||||
{ type: 'birthdayLe', column: oldRule.column, value: oldSettings.end}
|
||||
]
|
||||
});
|
||||
}
|
||||
} else if (oldSettings.start) {
|
||||
rules.push({ type: 'birthdayGe', column: oldRule.column, value: oldSettings.start });
|
||||
}
|
||||
if (oldSettings.end) {
|
||||
rules.push({ type: 'birthdayLe', column: oldRule.column, value: oldSettings.end });
|
||||
}
|
||||
} else {
|
||||
rules.push({ type: 'birthdayEq', column: oldRule.column, value: oldSettings.value });
|
||||
}
|
||||
break;
|
||||
case 'date':
|
||||
if (oldSettings.relativeRange) {
|
||||
if (oldSettings.start && oldSettings.end) {
|
||||
if (type === 'all') {
|
||||
rules.push({ type: 'dateGeNowPlusDays', column: oldRule.column, value: oldSettings.start});
|
||||
rules.push({ type: 'dateLeNowPlusDays', column: oldRule.column, value: oldSettings.end});
|
||||
rules.push({ type: 'geNowPlusDays', column: oldRule.column, value: oldSettings.start});
|
||||
rules.push({ type: 'leNowPlusDays', column: oldRule.column, value: oldSettings.end});
|
||||
} else {
|
||||
rules.push({
|
||||
type: 'all',
|
||||
rules: [
|
||||
{ type: 'dateGeNowPlusDays', column: oldRule.column, value: oldSettings.start},
|
||||
{ type: 'dateLeNowPlusDays', column: oldRule.column, value: oldSettings.end}
|
||||
{ type: 'geNowPlusDays', column: oldRule.column, value: oldSettings.start},
|
||||
{ type: 'leNowPlusDays', column: oldRule.column, value: oldSettings.end}
|
||||
]
|
||||
});
|
||||
}
|
||||
} else if (oldSettings.start) {
|
||||
rules.push({ type: 'dateGeNowPlusDays', column: oldRule.column, value: oldSettings.startDirection ? oldSettings.start : -oldSettings.start });
|
||||
rules.push({ type: 'geNowPlusDays', column: oldRule.column, value: oldSettings.startDirection ? oldSettings.start : -oldSettings.start });
|
||||
}
|
||||
if (oldSettings.end) {
|
||||
rules.push({ type: 'dateLeNowPlusDays', column: oldRule.column, value: oldSettings.endDirection ? oldSettings.end : -oldSettings.end });
|
||||
rules.push({ type: 'leNowPlusDays', column: oldRule.column, value: oldSettings.endDirection ? oldSettings.end : -oldSettings.end });
|
||||
}
|
||||
} else if (oldSettings.range) {
|
||||
if (oldSettings.start && oldSettings.end) {
|
||||
if (type === 'all') {
|
||||
rules.push({ type: 'dateGe', column: oldRule.column, value: oldSettings.start});
|
||||
rules.push({ type: 'dateLe', column: oldRule.column, value: oldSettings.end});
|
||||
rules.push({ type: 'ge', column: oldRule.column, value: oldSettings.start});
|
||||
rules.push({ type: 'le', column: oldRule.column, value: oldSettings.end});
|
||||
} else {
|
||||
rules.push({
|
||||
type: 'all',
|
||||
rules: [
|
||||
{ type: 'dateGe', column: oldRule.column, value: oldSettings.start},
|
||||
{ type: 'dateLe', column: oldRule.column, value: oldSettings.end}
|
||||
{ type: 'ge', column: oldRule.column, value: oldSettings.start},
|
||||
{ type: 'le', column: oldRule.column, value: oldSettings.end}
|
||||
]
|
||||
});
|
||||
}
|
||||
} else if (oldSettings.start) {
|
||||
rules.push({ type: 'dateGe', column: oldRule.column, value: oldSettings.start });
|
||||
rules.push({ type: 'ge', column: oldRule.column, value: oldSettings.start });
|
||||
}
|
||||
if (oldSettings.end) {
|
||||
rules.push({ type: 'dateLe', column: oldRule.column, value: oldSettings.end });
|
||||
rules.push({ type: 'le', column: oldRule.column, value: oldSettings.end });
|
||||
}
|
||||
} else {
|
||||
rules.push({ type: 'dateEq', column: oldRule.column, value: oldSettings.value });
|
||||
rules.push({ type: 'eq', column: oldRule.column, value: oldSettings.value });
|
||||
}
|
||||
break;
|
||||
case 'option':
|
||||
rules.push({ type: 'eq', column: oldRule.column, value: oldSettings.value });
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Unknown rule for column ${oldRule.column} with field type ${fieldType}`);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue