Last active
April 11, 2020 14:47
-
-
Save umutyerebakmaz/e6d34188718a347027e402052c22b807 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
// 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); | |
} |
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() | |
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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
PARAMETERS: ["c0abe7b6-9c6d-45dc-b518-f29f55b97237",null]