mirror of
https://github.com/plankanban/planka.git
synced 2025-07-19 13:19:44 +02:00
parent
ad7fb51cfa
commit
2ee1166747
1557 changed files with 76832 additions and 47042 deletions
91
server/api/hooks/query-methods/models/Board.js
Normal file
91
server/api/hooks/query-methods/models/Board.js
Normal file
|
@ -0,0 +1,91 @@
|
|||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
const defaultFind = (criteria, { sort = 'id' } = {}) => Board.find(criteria).sort(sort);
|
||||
|
||||
/* Query methods */
|
||||
|
||||
const createOne = (values, { user } = {}) =>
|
||||
sails.getDatastore().transaction(async (db) => {
|
||||
const board = await Board.create({ ...values })
|
||||
.fetch()
|
||||
.usingConnection(db);
|
||||
|
||||
const boardMembership = await BoardMembership.create({
|
||||
projectId: board.projectId,
|
||||
boardId: board.id,
|
||||
userId: user.id,
|
||||
role: BoardMembership.Roles.EDITOR,
|
||||
})
|
||||
.fetch()
|
||||
.usingConnection(db);
|
||||
|
||||
const lists = await List.createEach(
|
||||
[List.Types.ARCHIVE, List.Types.TRASH].map((type) => ({
|
||||
type,
|
||||
boardId: board.id,
|
||||
})),
|
||||
)
|
||||
.fetch()
|
||||
.usingConnection(db);
|
||||
|
||||
return { board, boardMembership, lists };
|
||||
});
|
||||
|
||||
const getByIds = (ids, { exceptProjectIdOrIds } = {}) => {
|
||||
const criteria = {
|
||||
id: ids,
|
||||
};
|
||||
|
||||
if (exceptProjectIdOrIds) {
|
||||
criteria.projectId = {
|
||||
'!=': exceptProjectIdOrIds,
|
||||
};
|
||||
}
|
||||
|
||||
return defaultFind(criteria);
|
||||
};
|
||||
|
||||
const getByProjectId = (projectId, { exceptIdOrIds, sort = ['position', 'id'] } = {}) => {
|
||||
const criteria = {
|
||||
projectId,
|
||||
};
|
||||
|
||||
if (exceptIdOrIds) {
|
||||
criteria.id = {
|
||||
'!=': exceptIdOrIds,
|
||||
};
|
||||
}
|
||||
|
||||
return defaultFind(criteria, { sort });
|
||||
};
|
||||
|
||||
const getByProjectIds = (projectIds, { sort = ['position', 'id'] } = {}) =>
|
||||
defaultFind(
|
||||
{
|
||||
projectId: projectIds,
|
||||
},
|
||||
{ sort },
|
||||
);
|
||||
|
||||
const getOneById = (id) => Board.findOne(id);
|
||||
|
||||
const updateOne = (criteria, values) => Board.updateOne(criteria).set({ ...values });
|
||||
|
||||
// eslint-disable-next-line no-underscore-dangle
|
||||
const delete_ = (criteria) => Board.destroy(criteria).fetch();
|
||||
|
||||
const deleteOne = (criteria) => Board.destroyOne(criteria);
|
||||
|
||||
module.exports = {
|
||||
createOne,
|
||||
getByIds,
|
||||
getByProjectId,
|
||||
getByProjectIds,
|
||||
getOneById,
|
||||
updateOne,
|
||||
deleteOne,
|
||||
delete: delete_,
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue