Last active
April 17, 2020 11:10
-
-
Save umutyerebakmaz/a70b032c6c34554640286400b3424aa9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@FieldResolver(() => CategoryAndCount) | |
async turlerineGoreKitaplarveSayilari( | |
@Args() { skip, take }: Pagination, | |
@Arg('state', () => Int) state: number, | |
@Root() user: User | |
): Promise<CategoryAndCount[]> { | |
const userId = user.id; | |
// book_reading_status tablosu | |
// const bookReadingStatus = await this.bookReadingStatusRepository.find({ userId, readingStatus: state }); | |
// if (bookReadingStatus.length === 0) { return []; } | |
// const bookIds = bookReadingStatus.map(obj => obj.bookId); | |
// const bookCategories = await this.bookCategoryRepository.find({ bookId: In(bookIds) }); | |
// console.log(bookCategories); | |
// const categoryIds = bookCategories.map(obj => obj.categoryId); | |
// const categories = await this.categoryRepository.findByIds(categoryIds, { skip, take }); | |
// const catMap = categories.map(cat => ({ ...cat, count: 0 })); | |
const raw = getConnection().query('SELECT category."id", category.title, category.slug, COUNT (*) FROM book_category INNER JOIN category ON book_category."categoryId" = category."id" INNER JOIN book_reading_status ON book_reading_status."bookId" = book_category."bookId" WHERE book_reading_status."userId" = $1 AND book_reading_status."readingStatus" = $2 GROUP BY category."id"', [userId, state]); | |
return raw; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment