diff --git a/src/repositories/info.repo.ts b/src/repositories/info.repo.ts index cb79a39..721db5b 100644 --- a/src/repositories/info.repo.ts +++ b/src/repositories/info.repo.ts @@ -252,7 +252,7 @@ export async function getListInfos( ? sql`(setweight(to_tsvector('indonesian', ${infos.title}), 'A') || setweight(to_tsvector('indonesian', ${infos.content}), 'B')) @@ to_tsquery('indonesian', ${searchPhrase})` : undefined; let unreadQ: SQL | undefined; - let categoryQ: SQL | undefined; + let excludeCategoryQ: SQL | undefined; let angkatanQ: SQL | undefined; if (q.unread === 'true') { @@ -263,14 +263,14 @@ export async function getListInfos( unreadQ = notInArray(infos.id, getReadInfosByUser); } - if (q.category) { - const getInfosByCategory = db + if (q.excludeCategory && q.excludeCategory.length > 0) { + const getInfosToExclude = db .select({ infoId: infoCategories.infoId }) .from(infos) .innerJoin(infoCategories, eq(infoCategories.infoId, infos.id)) .innerJoin(categories, eq(infoCategories.categoryId, categories.id)) - .where(eq(categories.name, q.category)); - categoryQ = inArray(infos.id, getInfosByCategory); + .where(inArray(categories.name, q.excludeCategory)); + excludeCategoryQ = notInArray(infos.id, getInfosToExclude); } if (angkatanYear !== undefined) { @@ -302,7 +302,7 @@ export async function getListInfos( const where = and( searchQ, - categoryQ, + excludeCategoryQ, unreadQ, angkatanQ, getInfoGroupQuery(db, userRoles), diff --git a/src/types/info.types.ts b/src/types/info.types.ts index 398c7c5..78814a0 100644 --- a/src/types/info.types.ts +++ b/src/types/info.types.ts @@ -126,9 +126,12 @@ export const ListInfoParamsSchema = z.object({ search: z.string().optional().openapi({ example: 'content', }), - category: z.string().optional().openapi({ - example: 'cat', - }), + excludeCategory: z + .array(z.string()) + .optional() + .openapi({ + example: ['cat1', 'cat2'], + }), unread: z.enum(['true', 'false']).default('false').openapi({ example: 'true', }),