-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(notes): resolve notes from a SavedItem (#994)
- Loading branch information
1 parent
19dd8f7
commit a4f4737
Showing
10 changed files
with
369 additions
and
17 deletions.
There are no files selected for viewing
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { PaginationInput } from '@pocket-tools/apollo-utils'; | ||
import { | ||
NoteFilterInput, | ||
NoteSortInput, | ||
SavedItemNoteFilterInput, | ||
} from '../__generated__/graphql'; | ||
import { IContext } from '../apollo'; | ||
import { NoteConnectionModel, NoteModel } from './Note'; | ||
|
||
/** | ||
* Model for resolving note-related fields | ||
* on a SavedItem entity. | ||
*/ | ||
export class SavedItemModel { | ||
constructor( | ||
public readonly url: string, | ||
public readonly context: IContext, | ||
) {} | ||
/** | ||
* Paginate over a note connection, filtered only to | ||
* notes attached to thie save (plus other optional filters). | ||
* @param opts pagination options | ||
* @returns NoteConnectionModel | ||
*/ | ||
async notes(opts: { | ||
sort?: NoteSortInput; | ||
filter?: SavedItemNoteFilterInput; | ||
pagination?: PaginationInput; | ||
}): Promise<NoteConnectionModel> { | ||
const noteModel = new NoteModel(this.context); | ||
const filter: (NoteFilterInput & { sourceUrl: string }) | undefined = | ||
opts.filter != null | ||
? { | ||
...opts.filter, | ||
sourceUrl: this.url, | ||
} | ||
: { sourceUrl: this.url }; | ||
return await noteModel.paginate({ | ||
sort: opts.sort, | ||
filter: filter, | ||
pagination: opts.pagination, | ||
}); | ||
} | ||
} |
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
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
Oops, something went wrong.