Add negative label filtering for cards
This commit is contained in:
@@ -57,6 +57,13 @@
|
||||
* schema:
|
||||
* type: string
|
||||
* example: 1357158568008091268,1357158568008091269
|
||||
* - name: excludedLabelIds
|
||||
* in: query
|
||||
* required: false
|
||||
* description: Comma-separated label IDs to exclude from results
|
||||
* schema:
|
||||
* type: string
|
||||
* example: 1357158568008091268,1357158568008091269
|
||||
* responses:
|
||||
* 200:
|
||||
* description: Cards retrieved successfully
|
||||
@@ -189,6 +196,7 @@ module.exports = {
|
||||
},
|
||||
userIds: idsInput,
|
||||
labelIds: idsInput,
|
||||
excludedLabelIds: idsInput,
|
||||
},
|
||||
|
||||
exits: {
|
||||
@@ -235,12 +243,28 @@ module.exports = {
|
||||
}
|
||||
|
||||
let filterLabelIds;
|
||||
let filterExcludedLabelIds;
|
||||
if (inputs.labelIds) {
|
||||
const labels = await Label.qm.getByBoardId(list.boardId);
|
||||
const availableLabelIdsSet = new Set(sails.helpers.utils.mapRecords(labels));
|
||||
|
||||
filterLabelIds = _.uniq(inputs.labelIds.split(','));
|
||||
filterLabelIds = filterLabelIds.filter((labelId) => availableLabelIdsSet.has(labelId));
|
||||
|
||||
if (inputs.excludedLabelIds) {
|
||||
filterExcludedLabelIds = _.uniq(inputs.excludedLabelIds.split(','));
|
||||
filterExcludedLabelIds = filterExcludedLabelIds.filter((labelId) =>
|
||||
availableLabelIdsSet.has(labelId),
|
||||
);
|
||||
}
|
||||
} else if (inputs.excludedLabelIds) {
|
||||
const labels = await Label.qm.getByBoardId(list.boardId);
|
||||
const availableLabelIdsSet = new Set(sails.helpers.utils.mapRecords(labels));
|
||||
|
||||
filterExcludedLabelIds = _.uniq(inputs.excludedLabelIds.split(','));
|
||||
filterExcludedLabelIds = filterExcludedLabelIds.filter((labelId) =>
|
||||
availableLabelIdsSet.has(labelId),
|
||||
);
|
||||
}
|
||||
|
||||
const cards = await Card.qm.getByEndlessListId(list.id, {
|
||||
@@ -248,6 +272,7 @@ module.exports = {
|
||||
search: inputs.search,
|
||||
userIds: filterUserIds,
|
||||
labelIds: filterLabelIds,
|
||||
excludedLabelIds: filterExcludedLabelIds,
|
||||
});
|
||||
|
||||
const cardIds = sails.helpers.utils.mapRecords(cards);
|
||||
|
||||
@@ -38,8 +38,13 @@ const getByListId = async (listId, { exceptIdOrIds, sort = ['position', 'id'] }
|
||||
return defaultFind(criteria, { sort });
|
||||
};
|
||||
|
||||
const getByEndlessListId = async (listId, { before, search, userIds, labelIds }) => {
|
||||
if (search || userIds || labelIds) {
|
||||
const getByEndlessListId = async (
|
||||
listId,
|
||||
{ before, search, userIds, labelIds, excludedLabelIds },
|
||||
) => {
|
||||
const hasExcludedLabelIds = excludedLabelIds && excludedLabelIds.length > 0;
|
||||
|
||||
if (search || userIds || labelIds || hasExcludedLabelIds) {
|
||||
if (userIds && userIds.length === 0) {
|
||||
return [];
|
||||
}
|
||||
@@ -108,6 +113,20 @@ const getByEndlessListId = async (listId, { before, search, userIds, labelIds })
|
||||
query += ` AND card_label.label_id IN (${inValues.join(', ')})`;
|
||||
}
|
||||
|
||||
if (hasExcludedLabelIds) {
|
||||
const inValues = excludedLabelIds.map((labelId) => {
|
||||
queryValues.push(labelId);
|
||||
return `$${queryValues.length}`;
|
||||
});
|
||||
|
||||
query += ` AND NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM card_label AS excluded_card_label
|
||||
WHERE excluded_card_label.card_id = card.id
|
||||
AND excluded_card_label.label_id IN (${inValues.join(', ')})
|
||||
)`;
|
||||
}
|
||||
|
||||
query += ` LIMIT ${LIMIT}`;
|
||||
|
||||
let queryResult;
|
||||
|
||||
Reference in New Issue
Block a user