2019-08-31 04:07:25 +05:00
|
|
|
module.exports = {
|
|
|
|
inputs: {
|
|
|
|
record: {
|
|
|
|
type: 'ref',
|
2019-11-05 18:01:42 +05:00
|
|
|
required: true,
|
2019-08-31 04:07:25 +05:00
|
|
|
},
|
|
|
|
values: {
|
|
|
|
type: 'json',
|
2020-08-04 01:32:46 +05:00
|
|
|
custom: (value) => {
|
|
|
|
if (!_.isPlainObject(value)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!_.isUndefined(value.position) && !_.isFinite(value.position)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
},
|
2019-11-05 18:01:42 +05:00
|
|
|
required: true,
|
2019-08-31 04:07:25 +05:00
|
|
|
},
|
|
|
|
request: {
|
2019-11-05 18:01:42 +05:00
|
|
|
type: 'ref',
|
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
},
|
|
|
|
|
2019-11-05 18:01:42 +05:00
|
|
|
async fn(inputs, exits) {
|
2019-08-31 04:07:25 +05:00
|
|
|
if (!_.isUndefined(inputs.values.position)) {
|
2019-11-05 18:01:42 +05:00
|
|
|
const lists = await sails.helpers.getListsForBoard(inputs.record.boardId, inputs.record.id);
|
2019-08-31 04:07:25 +05:00
|
|
|
|
|
|
|
const { position, repositions } = sails.helpers.insertToPositionables(
|
|
|
|
inputs.values.position,
|
2019-11-05 18:01:42 +05:00
|
|
|
lists,
|
2019-08-31 04:07:25 +05:00
|
|
|
);
|
|
|
|
|
2020-02-03 18:42:31 +05:00
|
|
|
inputs.values.position = position; // eslint-disable-line no-param-reassign
|
2019-08-31 04:07:25 +05:00
|
|
|
|
2019-11-05 18:01:42 +05:00
|
|
|
repositions.forEach(async ({ id, position: nextPosition }) => {
|
2019-08-31 04:07:25 +05:00
|
|
|
await List.update({
|
|
|
|
id,
|
2019-11-05 18:01:42 +05:00
|
|
|
boardId: inputs.record.boardId,
|
2019-08-31 04:07:25 +05:00
|
|
|
}).set({
|
2019-11-05 18:01:42 +05:00
|
|
|
position: nextPosition,
|
2019-08-31 04:07:25 +05:00
|
|
|
});
|
|
|
|
|
2019-11-05 18:01:42 +05:00
|
|
|
sails.sockets.broadcast(`board:${inputs.record.boardId}`, 'listUpdate', {
|
|
|
|
item: {
|
|
|
|
id,
|
|
|
|
position: nextPosition,
|
|
|
|
},
|
|
|
|
});
|
2019-08-31 04:07:25 +05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
const list = await List.updateOne(inputs.record.id).set(inputs.values);
|
|
|
|
|
|
|
|
if (list) {
|
|
|
|
sails.sockets.broadcast(
|
|
|
|
`board:${list.boardId}`,
|
|
|
|
'listUpdate',
|
|
|
|
{
|
2019-11-05 18:01:42 +05:00
|
|
|
item: list,
|
2019-08-31 04:07:25 +05:00
|
|
|
},
|
2019-11-05 18:01:42 +05:00
|
|
|
inputs.request,
|
2019-08-31 04:07:25 +05:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return exits.success(list);
|
2019-11-05 18:01:42 +05:00
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
};
|