mirror of
https://github.com/plankanban/planka.git
synced 2025-12-17 09:13:23 +03:00
ref: Remove board types, refactoring
This commit is contained in:
@@ -1,6 +1,22 @@
|
||||
const path = require('path');
|
||||
const rimraf = require('rimraf');
|
||||
|
||||
const valuesValidator = (value) => {
|
||||
if (!_.isPlainObject(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (value.background && !_.isPlainObject(value.background)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (value.backgroundImage && !_.isPlainObject(value.backgroundImage)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
record: {
|
||||
@@ -9,21 +25,7 @@ module.exports = {
|
||||
},
|
||||
values: {
|
||||
type: 'json',
|
||||
custom: (value) => {
|
||||
if (!_.isPlainObject(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (value.background && !_.isPlainObject(value.background)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (value.backgroundImage && !_.isPlainObject(value.backgroundImage)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
custom: valuesValidator,
|
||||
required: true,
|
||||
},
|
||||
request: {
|
||||
@@ -32,45 +34,46 @@ module.exports = {
|
||||
},
|
||||
|
||||
exits: {
|
||||
backgroundImageMustBeNotNullInValues: {},
|
||||
backgroundImageInValuesMustNotBeNull: {},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
if (inputs.values.backgroundImage) {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
inputs.values.background = {
|
||||
const { values } = inputs;
|
||||
|
||||
if (values.backgroundImage) {
|
||||
values.background = {
|
||||
type: 'image',
|
||||
};
|
||||
} else if (
|
||||
_.isNull(inputs.values.backgroundImage) &&
|
||||
_.isNull(values.backgroundImage) &&
|
||||
inputs.record.background &&
|
||||
inputs.record.background.type === 'image'
|
||||
) {
|
||||
inputs.values.background = null; // eslint-disable-line no-param-reassign
|
||||
values.background = null;
|
||||
}
|
||||
|
||||
let project;
|
||||
if (inputs.values.background && inputs.values.background.type === 'image') {
|
||||
if (_.isNull(inputs.values.backgroundImage)) {
|
||||
throw 'backgroundImageMustBeNotNullInValues';
|
||||
if (values.background && values.background.type === 'image') {
|
||||
if (_.isNull(values.backgroundImage)) {
|
||||
throw 'backgroundImageInValuesMustNotBeNull';
|
||||
}
|
||||
|
||||
if (_.isUndefined(inputs.values.backgroundImage)) {
|
||||
if (_.isUndefined(values.backgroundImage)) {
|
||||
project = await Project.updateOne({
|
||||
id: inputs.record.id,
|
||||
backgroundImage: {
|
||||
'!=': null,
|
||||
},
|
||||
}).set(inputs.values);
|
||||
}).set({ ...values });
|
||||
|
||||
if (!project) {
|
||||
delete inputs.values.background; // eslint-disable-line no-param-reassign
|
||||
delete values.background;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!project) {
|
||||
project = await Project.updateOne(inputs.record.id).set(inputs.values);
|
||||
project = await Project.updateOne(inputs.record.id).set({ ...values });
|
||||
}
|
||||
|
||||
if (project) {
|
||||
@@ -91,9 +94,11 @@ module.exports = {
|
||||
}
|
||||
}
|
||||
|
||||
const userIds = await sails.helpers.projects.getManagerAndBoardMemberUserIds(project.id);
|
||||
const projectRelatedUserIds = await sails.helpers.projects.getManagerAndBoardMemberUserIds(
|
||||
project.id,
|
||||
);
|
||||
|
||||
userIds.forEach((userId) => {
|
||||
projectRelatedUserIds.forEach((userId) => {
|
||||
sails.sockets.broadcast(
|
||||
`user:${userId}`,
|
||||
'projectUpdate',
|
||||
|
||||
Reference in New Issue
Block a user