add mediaListOptions field

This commit is contained in:
DrakeTDL 2023-10-14 10:46:57 -07:00
parent 21326fc6bc
commit e313d44fb0
No known key found for this signature in database
2 changed files with 64 additions and 3 deletions

View File

@ -3,6 +3,63 @@ import { Media } from "./Media.ts"
import { FuzzyDate } from "../anilist.ts"
import { User } from "./User.ts"
export const MediaListTypeOptions = ({ query, level }: Fields<UpdateOperation>) => ({
/** The order each list should be displayed in */
withSectionOrder() {
query[0] = query[0].set({ subField: "sectionOrder", level })
return this
},
/** If the completed sections of the list should be separated by format */
withSplitCompletedSectionByFormat() {
query[0] = query[0].set({ subField: "splitCompletedSectionByFormat", level })
return this
},
/** The names of the user's custom lists */
withCustomLists() {
query[0] = query[0].set({ subField: "customLists", level })
return this
},
/** The names of the user's advanced scoring sections */
withAdvancedScoring() {
query[0] = query[0].set({ subField: "advancedScoring", level })
return this
},
/** If advanced scoring is enabled */
withAdvancedScoringEnabled() {
query[0] = query[0].set({ subField: "advancedScoringEnabled", level })
return this
},
})
export const MediaListOptions = ({ query, level }: Fields<UpdateOperation>) => ({
/** The score format the user is using for media lists */
withScoreFormat() {
query[0] = query[0].set({ subField: "scoreFormat", level })
return this
},
/** The default order list rows should be displayed in */
withRowOrder() {
query[0] = query[0].set({ subField: "rowOrder", level })
return this
},
/** The user's anime list options */
withAnimeList(fn: Fn<typeof MediaListTypeOptions>) {
query[0] = query[0].set({ subField: "animeList", level })
let tmpQuery
fn(MediaListTypeOptions({ query: tmpQuery = [query[0]], level: level + 1 }))
query[0] = tmpQuery[0]
return this
},
/** The user's manga list options */
withMangaList(fn: Fn<typeof MediaListTypeOptions>) {
query[0] = query[0].set({ subField: "mangaList", level })
let tmpQuery
fn(MediaListTypeOptions({ query: tmpQuery = [query[0]], level: level + 1 }))
query[0] = tmpQuery[0]
return this
},
})
export const MediaList = ({ query, level }: Fields<UpdateOperation>) => ({
withCompletedAt(fn: Fn<typeof FuzzyDate>) {
query[0] = query[0].set({

View File

@ -1,4 +1,5 @@
import { Fields, Fn, UpdateOperation } from "../types/Anilist.ts"
import { MediaListOptions } from "./MediaList.ts"
const NotificationOption = ({ query, level }: Fields<UpdateOperation>) => ({
withEnabled() {
@ -183,13 +184,16 @@ export const User = ({ query, level }: Fields<UpdateOperation>) => ({
return this
},
/* The user's media list options */
withMediaListOptions(fn?: Fn<never>) {
withMediaListOptions(fn: Fn<typeof MediaListOptions>) {
query[0] = query[0].set({ subField: "mediaListOptions", level })
let tmpQuery
fn(MediaListOptions({ query: tmpQuery = [query[0]], level: level + 1 }))
query[0] = tmpQuery[0]
return this
},
/* The users favourites */
withFavourites(args?: { page: number }, fn?: Fn<never>) {
query[0] = query[0].set({ subField: "favourites", level, variables: args })
withFavourites(op?: { args?: { page: number }; fn?: Fn<never> }) {
query[0] = query[0].set({ subField: "favourites", level, variables: op?.args })
return this
},
/* The users anime & manga list statistics */