From d62e042211b077a95ee268b4a3c251238a19cda2 Mon Sep 17 00:00:00 2001 From: Azat Kashapov Date: Sun, 22 Dec 2024 10:22:33 +0100 Subject: [PATCH] feat: tags multiply select --- src/services/bookService.ts | 15 ++++++++++++--- src/types/book.ts | 4 ++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/services/bookService.ts b/src/services/bookService.ts index 6da7834..15c18c3 100644 --- a/src/services/bookService.ts +++ b/src/services/bookService.ts @@ -134,7 +134,7 @@ async function searchBook(params: QueryBooks) { id, name, text, - tag, + rating, view_count, authorName, @@ -145,6 +145,12 @@ async function searchBook(params: QueryBooks) { page = 1, perPage = 10, } = params; + const tags = Array.isArray(params['tag[]']) + ? params['tag[]'] + : params['tag[]'] + ? [params['tag[]']] + : undefined; + let { sort = 'id' } = params; let sortWay = 'asc'; if (sort[0] === '-') { @@ -173,12 +179,15 @@ async function searchBook(params: QueryBooks) { }, }); } - if (tag) { + if (tags) { + console.log('tags', tags); whereConditions.push({ book_tag: { some: { tag: { - name: tag, + name: { + in: tags, + }, }, }, }, diff --git a/src/types/book.ts b/src/types/book.ts index 0aa79df..b99307f 100644 --- a/src/types/book.ts +++ b/src/types/book.ts @@ -50,9 +50,9 @@ interface MetaLinks { } interface QueryBooks { - [key: string]: string | number | undefined; + [key: string]: string | number | undefined | string[]; id?: number; - tag?: string; + 'tag[]'?: string[]; view_count?: number; name?: string; text?: string;