Skip to content

Commit

Permalink
feat change /api/info category param to excludeCategory
Browse files Browse the repository at this point in the history
  • Loading branch information
satriadhikara committed Oct 12, 2024
1 parent eb7b2c3 commit eb5d835
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
12 changes: 6 additions & 6 deletions src/repositories/info.repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<unknown> | undefined;
let categoryQ: SQL<unknown> | undefined;
let excludeCategoryQ: SQL<unknown> | undefined;
let angkatanQ: SQL<unknown> | undefined;

if (q.unread === 'true') {
Expand All @@ -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) {
Expand Down Expand Up @@ -302,7 +302,7 @@ export async function getListInfos(

const where = and(
searchQ,
categoryQ,
excludeCategoryQ,
unreadQ,
angkatanQ,
getInfoGroupQuery(db, userRoles),
Expand Down
9 changes: 6 additions & 3 deletions src/types/info.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}),
Expand Down

0 comments on commit eb5d835

Please sign in to comment.