Skip to content

Instantly share code, notes, and snippets.

@umutyerebakmaz
Last active April 17, 2020 11:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save umutyerebakmaz/a70b032c6c34554640286400b3424aa9 to your computer and use it in GitHub Desktop.
Save umutyerebakmaz/a70b032c6c34554640286400b3424aa9 to your computer and use it in GitHub Desktop.
@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