ref: Refactoring
This commit is contained in:
@@ -23,10 +23,10 @@
|
||||
* - name: before
|
||||
* in: query
|
||||
* required: false
|
||||
* description: Pagination cursor (JSON object with id and listChangedAt)
|
||||
* description: Pagination cursor (JSON object with listChangedAt and id)
|
||||
* schema:
|
||||
* type: string
|
||||
* example: '{"id": "1357158568008091269", "listChangedAt": "2024-01-01T00:00:00.000Z"}'
|
||||
* example: '{"listChangedAt": "2024-01-01T00:00:00.000Z", "id": "1357158568008091269"}'
|
||||
* - name: search
|
||||
* in: query
|
||||
* required: false
|
||||
|
||||
@@ -87,7 +87,7 @@ module.exports = {
|
||||
},
|
||||
type: {
|
||||
type: 'string',
|
||||
isIn: List.FINITE_TYPES,
|
||||
isIn: List.KANBAN_TYPES,
|
||||
required: true,
|
||||
},
|
||||
position: {
|
||||
|
||||
@@ -100,7 +100,7 @@ module.exports = {
|
||||
throw Errors.LIST_NOT_FOUND; // Forbidden
|
||||
}
|
||||
|
||||
if (!sails.helpers.lists.isFinite(list)) {
|
||||
if (!sails.helpers.lists.isKanban(list)) {
|
||||
throw Errors.NOT_ENOUGH_RIGHTS;
|
||||
}
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ module.exports = {
|
||||
boardId: idInput,
|
||||
type: {
|
||||
type: 'string',
|
||||
isIn: List.FINITE_TYPES,
|
||||
isIn: List.KANBAN_TYPES,
|
||||
},
|
||||
position: {
|
||||
type: 'number',
|
||||
@@ -146,7 +146,7 @@ module.exports = {
|
||||
throw Errors.LIST_NOT_FOUND; // Forbidden
|
||||
}
|
||||
|
||||
if (!sails.helpers.lists.isFinite(list)) {
|
||||
if (!sails.helpers.lists.isKanban(list)) {
|
||||
throw Errors.NOT_ENOUGH_RIGHTS;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* operationId: getUsers
|
||||
* responses:
|
||||
* 200:
|
||||
* description: List of users retrieved successfully
|
||||
* description: Users retrieved successfully
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* operationId: getWebhooks
|
||||
* responses:
|
||||
* 200:
|
||||
* description: List of webhooks retrieved successfully
|
||||
* description: Webhooks retrieved successfully
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
|
||||
@@ -23,7 +23,7 @@ const buildBodyByFormat = (board, card, action, actorUser, t) => {
|
||||
|
||||
switch (action.type) {
|
||||
case Action.Types.CREATE_CARD: {
|
||||
const listName = sails.helpers.lists.makeName(action.data.list);
|
||||
const listName = sails.helpers.lists.resolveName(action.data.list, t);
|
||||
|
||||
return {
|
||||
text: t('%s created %s in %s on %s', actorUser.name, card.name, listName, board.name),
|
||||
@@ -44,8 +44,8 @@ const buildBodyByFormat = (board, card, action, actorUser, t) => {
|
||||
};
|
||||
}
|
||||
case Action.Types.MOVE_CARD: {
|
||||
const fromListName = sails.helpers.lists.makeName(action.data.fromList);
|
||||
const toListName = sails.helpers.lists.makeName(action.data.toList);
|
||||
const fromListName = sails.helpers.lists.resolveName(action.data.fromList, t);
|
||||
const toListName = sails.helpers.lists.resolveName(action.data.toList, t);
|
||||
|
||||
return {
|
||||
text: t(
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ module.exports = {
|
||||
async fn(inputs) {
|
||||
return List.qm.getByBoardId(inputs.id, {
|
||||
exceptIdOrIds: inputs.exceptListIdOrIds,
|
||||
typeOrTypes: List.FINITE_TYPES,
|
||||
typeOrTypes: List.KANBAN_TYPES,
|
||||
});
|
||||
},
|
||||
};
|
||||
@@ -41,12 +41,26 @@ module.exports = {
|
||||
async fn(inputs) {
|
||||
const { values } = inputs;
|
||||
|
||||
if (sails.helpers.lists.isFinite(inputs.list)) {
|
||||
if (values.list) {
|
||||
const typeState = List.TYPE_STATE_BY_TYPE[values.list.type];
|
||||
|
||||
if (inputs.record.isClosed) {
|
||||
if (typeState === List.TypeStates.OPENED) {
|
||||
values.isClosed = false;
|
||||
}
|
||||
} else if (typeState === List.TypeStates.CLOSED) {
|
||||
values.isClosed = true;
|
||||
}
|
||||
}
|
||||
|
||||
const list = values.list || inputs.list;
|
||||
|
||||
if (sails.helpers.lists.isFinite(list)) {
|
||||
if (_.isUndefined(values.position)) {
|
||||
throw 'positionMustBeInValues';
|
||||
}
|
||||
|
||||
const cards = await Card.qm.getByListId(inputs.list.id);
|
||||
const cards = await Card.qm.getByListId(list.id);
|
||||
|
||||
const { position, repositions } = sails.helpers.utils.insertToPositionables(
|
||||
values.position,
|
||||
@@ -84,7 +98,6 @@ module.exports = {
|
||||
let card = await Card.qm.createOne({
|
||||
..._.pick(inputs.record, [
|
||||
'boardId',
|
||||
'listId',
|
||||
'prevListId',
|
||||
'type',
|
||||
'name',
|
||||
@@ -95,6 +108,7 @@ module.exports = {
|
||||
'isClosed',
|
||||
]),
|
||||
...values,
|
||||
listId: list.id,
|
||||
creatorUserId: values.creatorUser.id,
|
||||
listChangedAt: new Date().toISOString(),
|
||||
});
|
||||
@@ -240,7 +254,7 @@ module.exports = {
|
||||
included: {
|
||||
projects: [inputs.project],
|
||||
boards: [inputs.board],
|
||||
lists: [inputs.list],
|
||||
lists: [list],
|
||||
cardMemberships: nextCardMemberships,
|
||||
cardLabels: nextCardLabels,
|
||||
taskLists: nextTaskLists,
|
||||
@@ -277,19 +291,19 @@ module.exports = {
|
||||
}
|
||||
|
||||
await sails.helpers.actions.createOne.with({
|
||||
list,
|
||||
webhooks,
|
||||
values: {
|
||||
card,
|
||||
type: Action.Types.CREATE_CARD, // TODO: introduce separate type?
|
||||
data: {
|
||||
card: _.pick(card, ['name']),
|
||||
list: _.pick(inputs.list, ['id', 'type', 'name']),
|
||||
list: _.pick(list, ['id', 'type', 'name']),
|
||||
},
|
||||
user: values.creatorUser,
|
||||
},
|
||||
project: inputs.project,
|
||||
board: inputs.board,
|
||||
list: inputs.list,
|
||||
});
|
||||
|
||||
return {
|
||||
|
||||
@@ -25,7 +25,7 @@ module.exports = {
|
||||
async fn(inputs) {
|
||||
const { values } = inputs;
|
||||
|
||||
const lists = await sails.helpers.boards.getFiniteListsById(values.board.id);
|
||||
const lists = await sails.helpers.boards.getKanbanListsById(values.board.id);
|
||||
|
||||
const { position, repositions } = sails.helpers.utils.insertToPositionables(
|
||||
values.position,
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
// TODO: rename?
|
||||
module.exports = {
|
||||
sync: true,
|
||||
|
||||
@@ -15,6 +14,6 @@ module.exports = {
|
||||
},
|
||||
|
||||
fn(inputs) {
|
||||
return inputs.record.name || _.upperFirst(inputs.record.type);
|
||||
return List.KANBAN_TYPES.includes(inputs.record.type);
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,27 @@
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
sync: true,
|
||||
|
||||
inputs: {
|
||||
record: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
t: {
|
||||
type: 'ref',
|
||||
},
|
||||
},
|
||||
|
||||
fn(inputs) {
|
||||
if (inputs.record.name) {
|
||||
return inputs.record.name;
|
||||
}
|
||||
|
||||
const name = _.upperFirst(inputs.record.type);
|
||||
return inputs.t ? inputs.t(name) : name;
|
||||
},
|
||||
};
|
||||
@@ -58,7 +58,7 @@ module.exports = {
|
||||
const board = values.board || inputs.board;
|
||||
|
||||
if (!_.isUndefined(values.position)) {
|
||||
const lists = await sails.helpers.boards.getFiniteListsById(board.id, inputs.record.id);
|
||||
const lists = await sails.helpers.boards.getKanbanListsById(board.id, inputs.record.id);
|
||||
|
||||
const { position, repositions } = sails.helpers.utils.insertToPositionables(
|
||||
values.position,
|
||||
|
||||
@@ -29,8 +29,8 @@ const buildBodyByFormat = (board, card, notification, actorUser, t) => {
|
||||
|
||||
switch (notification.type) {
|
||||
case Notification.Types.MOVE_CARD: {
|
||||
const fromListName = sails.helpers.lists.makeName(notification.data.fromList);
|
||||
const toListName = sails.helpers.lists.makeName(notification.data.toList);
|
||||
const fromListName = sails.helpers.lists.resolveName(notification.data.fromList, t);
|
||||
const toListName = sails.helpers.lists.resolveName(notification.data.toList, t);
|
||||
|
||||
return {
|
||||
text: t(
|
||||
@@ -144,8 +144,8 @@ const buildEmail = (board, card, notification, actorUser, notifiableUser, t) =>
|
||||
let html;
|
||||
switch (notification.type) {
|
||||
case Notification.Types.MOVE_CARD: {
|
||||
const fromListName = sails.helpers.lists.makeName(notification.data.fromList);
|
||||
const toListName = sails.helpers.lists.makeName(notification.data.toList);
|
||||
const fromListName = sails.helpers.lists.resolveName(notification.data.fromList, t);
|
||||
const toListName = sails.helpers.lists.resolveName(notification.data.toList, t);
|
||||
|
||||
html = `<p>${t(
|
||||
'%s moved %s from %s to %s on %s',
|
||||
@@ -243,10 +243,6 @@ module.exports = {
|
||||
arrayOfValues.map((values) => {
|
||||
const id = ids.shift();
|
||||
|
||||
const isCommentRelated =
|
||||
values.type === Notification.Types.COMMENT_CARD ||
|
||||
values.type === Notification.Types.MENTION_IN_COMMENT;
|
||||
|
||||
const nextValues = {
|
||||
...values,
|
||||
id,
|
||||
@@ -254,10 +250,10 @@ module.exports = {
|
||||
boardId: values.card.boardId,
|
||||
cardId: values.card.id,
|
||||
};
|
||||
|
||||
if (isCommentRelated) {
|
||||
if (values.comment) {
|
||||
nextValues.commentId = values.comment.id;
|
||||
} else {
|
||||
}
|
||||
if (values.action) {
|
||||
nextValues.actionId = values.action.id;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,8 +29,8 @@ const buildBodyByFormat = (board, card, notification, actorUser, t) => {
|
||||
|
||||
switch (notification.type) {
|
||||
case Notification.Types.MOVE_CARD: {
|
||||
const fromListName = sails.helpers.lists.makeName(notification.data.fromList);
|
||||
const toListName = sails.helpers.lists.makeName(notification.data.toList);
|
||||
const fromListName = sails.helpers.lists.resolveName(notification.data.fromList, t);
|
||||
const toListName = sails.helpers.lists.resolveName(notification.data.toList, t);
|
||||
|
||||
return {
|
||||
text: t(
|
||||
@@ -152,8 +152,8 @@ const buildAndSendEmail = async (
|
||||
let html;
|
||||
switch (notification.type) {
|
||||
case Notification.Types.MOVE_CARD: {
|
||||
const fromListName = sails.helpers.lists.makeName(notification.data.fromList);
|
||||
const toListName = sails.helpers.lists.makeName(notification.data.toList);
|
||||
const fromListName = sails.helpers.lists.resolveName(notification.data.fromList, t);
|
||||
const toListName = sails.helpers.lists.resolveName(notification.data.toList, t);
|
||||
|
||||
html = `<p>${t(
|
||||
'%s moved %s from %s to %s on %s',
|
||||
@@ -234,13 +234,11 @@ module.exports = {
|
||||
async fn(inputs) {
|
||||
const { values } = inputs;
|
||||
|
||||
const isCommentRelated =
|
||||
values.type === Notification.Types.COMMENT_CARD ||
|
||||
values.type === Notification.Types.MENTION_IN_COMMENT;
|
||||
|
||||
if (isCommentRelated) {
|
||||
if (values.comment) {
|
||||
values.commentId = values.comment.id;
|
||||
} else {
|
||||
}
|
||||
|
||||
if (values.action) {
|
||||
values.actionId = values.action.id;
|
||||
}
|
||||
|
||||
@@ -268,13 +266,12 @@ module.exports = {
|
||||
boards: [inputs.board],
|
||||
lists: [inputs.list],
|
||||
cards: [values.card],
|
||||
...(isCommentRelated
|
||||
? {
|
||||
comments: [values.comment],
|
||||
}
|
||||
: {
|
||||
actions: [values.action],
|
||||
}),
|
||||
...(values.comment && {
|
||||
comments: [values.comment],
|
||||
}),
|
||||
...(values.action && {
|
||||
actions: [values.action],
|
||||
}),
|
||||
},
|
||||
}),
|
||||
user: values.creatorUser,
|
||||
|
||||
@@ -7,6 +7,7 @@ module.exports = {
|
||||
inputs: {
|
||||
roleOrRoles: {
|
||||
type: 'json',
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
|
||||
@@ -56,19 +56,12 @@ const getIdsByEndlessListId = async (
|
||||
const searchParts = buildSearchParts(search);
|
||||
|
||||
if (searchParts.length > 0) {
|
||||
let ilikeValues = searchParts.map((searchPart) => {
|
||||
const ilikeValues = searchParts.map((searchPart) => {
|
||||
queryValues.push(searchPart);
|
||||
return `'%' || $${queryValues.length} || '%'`;
|
||||
});
|
||||
|
||||
query += ` AND ((card.name ILIKE ALL(ARRAY[${ilikeValues.join(', ')}]))`;
|
||||
|
||||
ilikeValues = searchParts.map((searchPart) => {
|
||||
queryValues.push(searchPart);
|
||||
return `'%' || $${queryValues.length} || '%'`;
|
||||
});
|
||||
|
||||
query += ` OR (card.description ILIKE ALL(ARRAY[${ilikeValues.join(', ')}])))`;
|
||||
query += ` AND ((card.name ILIKE ALL(ARRAY[${ilikeValues.join(', ')}])) OR (card.description ILIKE ALL(ARRAY[${ilikeValues.join(', ')}])))`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,6 +95,8 @@ const SortOrders = {
|
||||
|
||||
const FINITE_TYPES = [Types.ACTIVE, Types.CLOSED];
|
||||
|
||||
const KANBAN_TYPES = [Types.ACTIVE, Types.CLOSED];
|
||||
|
||||
const TYPE_STATE_BY_TYPE = {
|
||||
[Types.ACTIVE]: TypeStates.OPENED,
|
||||
[Types.CLOSED]: Types.CLOSED,
|
||||
@@ -119,6 +121,7 @@ module.exports = {
|
||||
SortFieldNames,
|
||||
SortOrders,
|
||||
FINITE_TYPES,
|
||||
KANBAN_TYPES,
|
||||
TYPE_STATE_BY_TYPE,
|
||||
COLORS,
|
||||
|
||||
|
||||
Reference in New Issue
Block a user