1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-24 15:49:46 +02:00

ref: Remove board types, refactoring

This commit is contained in:
Maksim Eltyshev 2022-12-26 21:10:50 +01:00
parent 2b131f76c1
commit 6ffa817b53
182 changed files with 1573 additions and 1239 deletions

View file

@ -1,26 +1,42 @@
const valuesValidator = (value) => {
if (!_.isPlainObject(value)) {
return false;
}
if (!_.isPlainObject(value.user) && !_.isString(value.userId)) {
return false;
}
if (!_.isPlainObject(value.action)) {
return false;
}
return true;
};
module.exports = {
inputs: {
userOrId: {
type: 'ref',
custom: (value) => _.isObjectLike(value) || _.isString(value),
required: true,
},
action: {
values: {
type: 'ref',
custom: valuesValidator,
required: true,
},
},
async fn(inputs) {
const { userId = inputs.userOrId } = inputs.userOrId;
const { values } = inputs;
if (values.user) {
values.userId = values.user.id;
}
const notification = await Notification.create({
userId,
actionId: inputs.action.id,
cardId: inputs.action.cardId,
...values,
actionId: values.action.id,
cardId: values.action.cardId,
}).fetch();
sails.sockets.broadcast(`user:${userId}`, 'notificationCreate', {
sails.sockets.broadcast(`user:${notification.userId}`, 'notificationCreate', {
item: notification,
});

View file

@ -1,8 +1,10 @@
const criteriaValidator = (value) => _.isArray(value) || _.isPlainObject(value);
module.exports = {
inputs: {
criteria: {
type: 'json',
custom: (value) => _.isArray(value) || _.isPlainObject(value),
custom: criteriaValidator,
},
},

View file

@ -1,8 +1,11 @@
const recordsOrIdsValidator = (value) =>
_.every(value, _.isPlainObject) || _.every(value, _.isString);
module.exports = {
inputs: {
recordsOrIds: {
type: 'json',
custom: (value) => _.every(value, _.isObjectLike) || _.every(value, _.isString),
custom: recordsOrIdsValidator,
required: true,
},
values: {
@ -18,9 +21,11 @@ module.exports = {
},
async fn(inputs) {
const { values } = inputs;
const criteria = {};
if (_.every(inputs.recordsOrIds, _.isObjectLike)) {
if (_.every(inputs.recordsOrIds, _.isPlainObject)) {
criteria.id = sails.helpers.utils.mapRecords(inputs.recordsOrIds);
} else if (_.every(inputs.recordsOrIds, _.isString)) {
criteria.id = inputs.recordsOrIds;
@ -30,7 +35,9 @@ module.exports = {
criteria.userId = inputs.user.id;
}
const notifications = await Notification.update(criteria).set(inputs.values).fetch();
const notifications = await Notification.update(criteria)
.set({ ...values })
.fetch();
notifications.forEach((notification) => {
sails.sockets.broadcast(