Skip to content

Commit

Permalink
feat: tags multiply select
Browse files Browse the repository at this point in the history
  • Loading branch information
ufaboy committed Dec 22, 2024
1 parent 32af0a4 commit d62e042
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
15 changes: 12 additions & 3 deletions src/services/bookService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ async function searchBook(params: QueryBooks) {
id,
name,
text,
tag,

rating,
view_count,
authorName,
Expand All @@ -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] === '-') {
Expand Down Expand Up @@ -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,
},
},
},
},
Expand Down
4 changes: 2 additions & 2 deletions src/types/book.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit d62e042

Please sign in to comment.