Skip to content

Commit

Permalink
fix: filter by 'unlabeled'
Browse files Browse the repository at this point in the history
  • Loading branch information
julianpoy committed Dec 29, 2023
1 parent 974cddc commit a95874c
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions packages/trpc/src/dbHelpers/getRecipesWithConstraints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@ export const getRecipesWithConstraints = async (args: {
offset,
limit,
recipeIds: filterByRecipeIds,
labels,
labels: _labels,
labelIntersection,
ratings,
recipeIds,
} = args;

const labels = _labels?.filter((label) => label !== "unlabeled");
const mustBeUnlabeled = !!_labels?.includes("unlabeled");

let friends: Set<string> = new Set();
if (contextUserId) {
const friendships = await getFriendshipIds(contextUserId);
Expand Down Expand Up @@ -145,7 +148,21 @@ export const getRecipesWithConstraints = async (args: {
where.AND.push({ id: { in: filterByRecipeIds } });
}

if (labels && labelIntersection) {
if (mustBeUnlabeled) {
where.AND.push({
recipeLabels: {
none: {
label: {
userId: {
in: userIds, // We do this rather than none:{} due to Prisma perf issues...
},
},
},
},
});
}

if (labels?.length && labelIntersection) {
where.AND.push(
...labels.map(
(label) =>
Expand All @@ -162,7 +179,7 @@ export const getRecipesWithConstraints = async (args: {
);
}

if (labels && !labelIntersection) {
if (labels?.length && !labelIntersection) {
where.AND.push({
recipeLabels: {
some: {
Expand Down

0 comments on commit a95874c

Please sign in to comment.