mirror of
https://github.com/plankanban/planka.git
synced 2025-07-19 13:19:44 +02:00
Add validation to background field
This commit is contained in:
parent
ab83d7c9ab
commit
99d9ab4a9e
10 changed files with 130 additions and 25 deletions
|
@ -11,7 +11,7 @@ module.exports = {
|
|||
type: 'json',
|
||||
custom: (value) =>
|
||||
_.isPlainObject(value) &&
|
||||
/* _.isUndefined(value.background) || _.isNull(value.background) && */
|
||||
(_.isUndefined(value.background) || _.isPlainObject(value.background)) &&
|
||||
(_.isUndefined(value.backgroundImage) || _.isNull(value.backgroundImage)),
|
||||
required: true,
|
||||
},
|
||||
|
@ -20,6 +20,10 @@ module.exports = {
|
|||
},
|
||||
},
|
||||
|
||||
exits: {
|
||||
invalidParams: {},
|
||||
},
|
||||
|
||||
async fn(inputs, exits) {
|
||||
if (!_.isUndefined(inputs.values.backgroundImage)) {
|
||||
/* eslint-disable no-param-reassign */
|
||||
|
@ -33,9 +37,37 @@ module.exports = {
|
|||
inputs.values.background = {
|
||||
type: 'image',
|
||||
};
|
||||
} else if (
|
||||
_.isNull(inputs.values.backgroundImageDirname) &&
|
||||
inputs.record.background &&
|
||||
inputs.record.background.type === 'image'
|
||||
) {
|
||||
inputs.values.background = null; // eslint-disable-line no-param-reassign
|
||||
}
|
||||
|
||||
const project = await Project.updateOne(inputs.record.id).set(inputs.values);
|
||||
let project;
|
||||
if (inputs.values.background && inputs.values.background.type === 'image') {
|
||||
if (_.isNull(inputs.values.backgroundImageDirname)) {
|
||||
throw 'invalidParams';
|
||||
}
|
||||
|
||||
if (_.isUndefined(inputs.values.backgroundImageDirname)) {
|
||||
project = await Project.updateOne({
|
||||
id: inputs.record.id,
|
||||
backgroundImageDirname: {
|
||||
'!=': null,
|
||||
},
|
||||
}).set(inputs.values);
|
||||
|
||||
if (!project) {
|
||||
delete inputs.values.background; // eslint-disable-line no-param-reassign
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!project) {
|
||||
project = await Project.updateOne(inputs.record.id).set(inputs.values);
|
||||
}
|
||||
|
||||
if (project) {
|
||||
if (
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue