mirror of
https://github.com/plankanban/planka.git
synced 2025-07-24 15:49:46 +02:00
feat: Add ability to link tasks to cards
This commit is contained in:
parent
49203e9d56
commit
230f50e3d9
35 changed files with 761 additions and 243 deletions
|
@ -200,9 +200,69 @@ const getOneById = (id, { listId } = {}) => {
|
|||
return Card.findOne(criteria);
|
||||
};
|
||||
|
||||
const update = (criteria, values) => Card.update(criteria).set(values).fetch();
|
||||
const update = async (criteria, values) => {
|
||||
if (!_.isUndefined(values.isClosed)) {
|
||||
return sails.getDatastore().transaction(async (db) => {
|
||||
const cards = await Card.update(criteria).set(values).fetch().usingConnection(db);
|
||||
|
||||
const updateOne = (criteria, values) => Card.updateOne(criteria).set({ ...values });
|
||||
let tasks = [];
|
||||
if (card) {
|
||||
tasks = await Task.update({
|
||||
linkedCardId: sails.helpers.utils.mapRecords(cards),
|
||||
})
|
||||
.set({
|
||||
isCompleted: card.isClosed,
|
||||
})
|
||||
.fetch()
|
||||
.usingConnection(db);
|
||||
}
|
||||
|
||||
return {
|
||||
cards,
|
||||
tasks,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
const cards = await Card.update(criteria).set(values).fetch();
|
||||
|
||||
return {
|
||||
cards,
|
||||
};
|
||||
};
|
||||
|
||||
const updateOne = async (criteria, values) => {
|
||||
if (!_.isUndefined(values.isClosed)) {
|
||||
return sails.getDatastore().transaction(async (db) => {
|
||||
const card = await Card.updateOne(criteria)
|
||||
.set({ ...values })
|
||||
.usingConnection(db);
|
||||
|
||||
let tasks = [];
|
||||
if (card) {
|
||||
tasks = await Task.update({
|
||||
linkedCardId: card.id,
|
||||
})
|
||||
.set({
|
||||
isCompleted: card.isClosed,
|
||||
})
|
||||
.fetch()
|
||||
.usingConnection(db);
|
||||
}
|
||||
|
||||
return {
|
||||
card,
|
||||
tasks,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
const card = await Card.updateOne(criteria).set({ ...values });
|
||||
|
||||
return {
|
||||
card,
|
||||
};
|
||||
};
|
||||
|
||||
// eslint-disable-next-line no-underscore-dangle
|
||||
const delete_ = (criteria) => Card.destroy(criteria).fetch();
|
||||
|
|
|
@ -47,7 +47,61 @@ const getOneTrashByBoardId = (boardId) =>
|
|||
type: List.Types.TRASH,
|
||||
});
|
||||
|
||||
const updateOne = (criteria, values) => List.updateOne(criteria).set({ ...values });
|
||||
const updateOne = async (criteria, values) => {
|
||||
if (values.type) {
|
||||
return sails.getDatastore().transaction(async (db) => {
|
||||
const list = await List.updateOne(criteria)
|
||||
.set({ ...values })
|
||||
.usingConnection(db);
|
||||
|
||||
let cards = [];
|
||||
let tasks = [];
|
||||
|
||||
if (list) {
|
||||
let isClosed;
|
||||
if (list.type === List.Types.ACTIVE) {
|
||||
isClosed = false;
|
||||
} else if (list.type === List.Types.CLOSED) {
|
||||
isClosed = true;
|
||||
}
|
||||
|
||||
if (!_.isUndefined(isClosed)) {
|
||||
cards = await Card.update({
|
||||
listId: list.id,
|
||||
})
|
||||
.set({
|
||||
isClosed,
|
||||
})
|
||||
.fetch()
|
||||
.usingConnection(db);
|
||||
|
||||
if (cards.length > 0) {
|
||||
tasks = await Task.update({
|
||||
linkedCardId: sails.helpers.utils.mapRecords(cards),
|
||||
})
|
||||
.set({
|
||||
isCompleted: isClosed,
|
||||
})
|
||||
.fetch()
|
||||
.usingConnection(db);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
list,
|
||||
cards,
|
||||
tasks,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
const list = await List.updateOne(criteria).set({ ...values });
|
||||
|
||||
return {
|
||||
list,
|
||||
};
|
||||
};
|
||||
|
||||
// eslint-disable-next-line no-underscore-dangle
|
||||
const delete_ = (criteria) => List.destroy(criteria).fetch();
|
||||
|
|
|
@ -36,6 +36,11 @@ const getByTaskListIds = async (taskListIds, { sort = ['position', 'id'] } = {})
|
|||
{ sort },
|
||||
);
|
||||
|
||||
const getByLinkedCardId = (linkedCardId) =>
|
||||
defaultFind({
|
||||
linkedCardId,
|
||||
});
|
||||
|
||||
const getOneById = (id, { taskListId } = {}) => {
|
||||
const criteria = {
|
||||
id,
|
||||
|
@ -63,6 +68,7 @@ module.exports = {
|
|||
getByIds,
|
||||
getByTaskListId,
|
||||
getByTaskListIds,
|
||||
getByLinkedCardId,
|
||||
getOneById,
|
||||
update,
|
||||
updateOne,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue