(query: z.output<typeof findManyBookmarksSchema>, userId: UserId)
| 48 | } |
| 49 | |
| 50 | async function createFindManyFilters(query: z.output<typeof findManyBookmarksSchema>, userId: UserId) { |
| 51 | const { keyword, tagIds = [], tagNames, hostCheckStatus, ids } = query |
| 52 | const filters = [userLimiter(userId)] |
| 53 | if (ids?.length) { |
| 54 | filters.push(inArray(userBookmarks.id, ids)) |
| 55 | } |
| 56 | if (keyword) { |
| 57 | filters.push(createBookmarkFilterByKeyword(userBookmarks, keyword)) |
| 58 | } |
| 59 | if (tagNames?.length) { |
| 60 | const tags = await UserTagController.getAll(userId) |
| 61 | for (const name of tagNames) { |
| 62 | const tag = tags.find((el) => el.name === name) |
| 63 | tag && tagIds.push(tag.id) |
| 64 | } |
| 65 | } |
| 66 | const newTagIds = await UserTagController.filterUserTagIds(userId, tagIds) |
| 67 | if (newTagIds.length) { |
| 68 | const findTargetBIds = db |
| 69 | .select({ bId: userBookmarkToTag.bId }) |
| 70 | .from(userBookmarkToTag) |
| 71 | .where(inArray(userBookmarkToTag.tId, newTagIds)) |
| 72 | .groupBy(userBookmarkToTag.bId) |
| 73 | .having(sql`COUNT(DISTINCT ${userBookmarkToTag.tId}) = ${newTagIds.length}`) |
| 74 | filters.push(inArray(userBookmarks.id, findTargetBIds)) |
| 75 | } |
| 76 | const hostCheckFilter = hostCheckStatus ? createBookmarkHostCheckFilter(userBookmarks, hostCheckStatus) : undefined |
| 77 | if (hostCheckFilter) { |
| 78 | filters.push(hostCheckFilter) |
| 79 | } |
| 80 | return and(...filters) |
| 81 | } |
| 82 | |
| 83 | const UserBookmarkController = { |
| 84 | async insert(bookmark: InsertBookmark) { |
no test coverage detected