add MediaListCollection query

closes #10
This commit is contained in:
DrakeTDL 2023-10-08 18:35:33 -07:00
parent b552c7d882
commit 63bb438d14
No known key found for this signature in database
2 changed files with 108 additions and 2 deletions

View File

@ -11,6 +11,7 @@ import {
LikeArguments,
MediaArguments,
MediaListArguments,
MediaListCollectionArguments,
MediaSort,
MediaTrendArguments,
MediaTrendSort,
@ -549,6 +550,52 @@ const ActivityReply = ({ query, level }: Fields<typeof updateOperation>) => ({
return this
},
})
const MediaListGroup = ({ query, level }: Fields<typeof updateOperation>) => ({
/** Media list entries */
withEntries(fn: (fields: ReturnType<typeof MediaList>) => void) {
query[0] = query[0].set({ subField: "entries", level })
let tmpQuery
fn(MediaList({ query: tmpQuery = [query[0]], level: level + 1 }))
query[0] = tmpQuery[0]
return this
},
withName() {
query[0] = query[0].set({ subField: "name", level })
return this
},
withIsCustomList() {
query[0] = query[0].set({ subField: "isCustomList", level })
return this
},
withIsSplitCompletedList() {
query[0] = query[0].set({ subField: "isSplitCompletedList", level })
return this
},
withStatus() {
query[0] = query[0].set({ subField: "status", level })
return this
},
})
const MediaListCollection = ({ query, level }: Fields<typeof updateOperation>) => ({
/** Grouped media list entries */
withLists(fn: (fields: ReturnType<typeof MediaListGroup>) => void) {
query[0] = query[0].set({ subField: "lists", level })
let tmpQuery
fn(MediaListGroup({ query: tmpQuery = [query[0]], level: level + 1 }))
query[0] = tmpQuery[0]
return this
},
/** The owner of the list */
withUser() {
query[0] = query[0].set({ subField: "user", level })
return this
},
/** If there is another chunk */
withHasNextChunk() {
query[0] = query[0].set({ subField: "hasNextChunk", level })
return this
},
})
const User = ({ query, level }: Fields<typeof updateOperation>) => ({
/** The id of the user */
withId() {
@ -2822,8 +2869,23 @@ export const Client = function (auth?: { token: string }) {
return this
},
/** Media list collection query, provides list pre-grouped by status & custom lists. User ID and Media Type arguments required. */
MediaListCollection() {
throw "To be Implemented"
MediaListCollection(
args: AtLeastOne<MediaListCollectionArguments> & Variables,
fn?: (fields: ReturnType<typeof MediaListCollection>) => void,
) {
operation = operation.set({
subField: "MediaListCollection",
variables: args,
hasSubField: true,
level: 1,
})
if (!fn) operation = operation.set({ subField: "id", level: 2 })
else {
let tmpQuery
fn(MediaListCollection({ query: tmpQuery = [operation], level: 2 }))
operation = tmpQuery[0]
}
return this
},
/** Collection of all the possible media genres */
GenreCollection() {

View File

@ -199,6 +199,50 @@ enum ReviewSort {
UPDATED_AT = "UPDATED_AT",
UPDATED_AT_DESC = "UPDATED_AT_DESC",
}
export type MediaListCollectionArguments = {
/** Filter by a user's id */
userId: Int
/** Filter by a user's name */
userName: String
/** Filter by the list entries media type */
type: MediaType
/** Filter by the watching/reading status */
status: MediaListStatus
/** Filter by note words and #tags */
notes: String
/** Filter by the date the user started the media */
startedAt: FuzzyDateInt
/** Filter by the date the user completed the media */
completedAt: FuzzyDateInt
/** Always return completed list entries in one group, overriding the user's split completed option. */
forceSingleCompletedList: Boolean
/** Which chunk of list entries to load */
chunk: Int
/** The amount of entries per chunk, max 500 */
perChunk: Int
/** Filter by the watching/reading status */
status_in: MediaListStatus[]
/** Filter by the watching/reading status */
status_not_in: MediaListStatus[]
/** Filter by the watching/reading status */
status_not: MediaListStatus
/** Filter by note words and #tags */
notes_like: String
/** Filter by the date the user started the media */
startedAt_greater: FuzzyDateInt
/** Filter by the date the user started the media */
startedAt_lesser: FuzzyDateInt
/** Filter by the date the user started the media */
startedAt_like: String
/** Filter by the date the user completed the media */
completedAt_greater: FuzzyDateInt
/** Filter by the date the user completed the media */
completedAt_lesser: FuzzyDateInt
/** Filter by the date the user completed the media */
completedAt_like: String
/** The order the results will be returned in */
sort: MediaListSort[]
}
export type FollowArguments = {
/** User id of the follower/followed */
userId: Int