Skip to content

Instantly share code, notes, and snippets.

@umutyerebakmaz
Last active April 11, 2020 14:47
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/e6d34188718a347027e402052c22b807 to your computer and use it in GitHub Desktop.
Save umutyerebakmaz/e6d34188718a347027e402052c22b807 to your computer and use it in GitHub Desktop.
// status argümanı boş gönderilirse null değil hi olmamış gibi query'e etki etmesi gerekirken null gidiyor.
// conditional query ya da if if gibi bir yapı kuramadım.
@FieldResolver()
async okuduguKitaplar(
@Args() { skip, take }: Pagination,
@Arg('status', () => Int, { nullable: true }) readingStatus: number,
@Root() user: User
): Promise<Book[]> {
const userId = user.id;
const relation = await this.bookReadingStatusRepository.find({ userId, readingStatus });
if (relation.length === 0) { return []; }
const ids = relation.map(r => r.bookId);
return this.bookRepository.findByIds(ids);
}
@FieldResolver()
async okuduguKitaplar(
@Args() { skip, take }: Pagination,
@Arg('status', () => Int, { nullable: true }) readingStatus: number,
@Root() user: User
): Promise<Book[]> {
const userId = user.id;
let relation = null;
if (readingStatus) {
relation = await this.bookReadingStatusRepository.find({ userId, readingStatus });
}
if (!readingStatus) {
relation = await this.bookReadingStatusRepository.find({ userId });
}
if (relation.length === 0) { return []; }
const ids = relation.map(r => r.bookId);
return this.bookRepository.findByIds(ids);
}
@umutyerebakmaz
Copy link
Author

PARAMETERS: ["c0abe7b6-9c6d-45dc-b518-f29f55b97237",null]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment