add field from User.withStatistics to UserStatistics
This commit is contained in:
parent
e83f16a6b0
commit
4f3913814d
|
@ -1,6 +1,7 @@
|
|||
import { Fields, Fn, UpdateOperation } from "../types/Anilist.ts"
|
||||
import { Favourites } from "./Favourites.ts"
|
||||
import { MediaListOptions } from "./MediaList.ts"
|
||||
import { UserStatisticTypes } from "./UserStatistics.ts"
|
||||
|
||||
const NotificationOption = ({ query, level }: Fields<UpdateOperation>) => ({
|
||||
withEnabled() {
|
||||
|
@ -201,8 +202,11 @@ export const User = ({ query, level }: Fields<UpdateOperation>) => ({
|
|||
return this
|
||||
},
|
||||
/* The users anime & manga list statistics */
|
||||
withStatistics(fn?: Fn<never>) {
|
||||
query[0] = query[0].set({ subField: "statistics", level })
|
||||
withStatistics(fn: Fn<typeof UserStatisticTypes>) {
|
||||
query[0] = query[0].set({ subField: "statistics", level, hasSubField: true })
|
||||
let tmpQuery
|
||||
fn(UserStatisticTypes({ query: tmpQuery = [query[0]], level: level + 1 }))
|
||||
query[0] = tmpQuery[0]
|
||||
return this
|
||||
},
|
||||
/* The number of unread notifications the user has */
|
||||
|
|
|
@ -0,0 +1,497 @@
|
|||
import { Fields, Fn, UpdateOperation } from "../types/Anilist.ts"
|
||||
import {
|
||||
UserStatisticsCountriesArgs,
|
||||
UserStatisticsFormatsArgs,
|
||||
UserStatisticsGenresArgs,
|
||||
UserStatisticsLengthsArgs,
|
||||
UserStatisticsReleaseYearsArgs,
|
||||
UserStatisticsScoresArgs,
|
||||
UserStatisticsStaffArgs,
|
||||
UserStatisticsStartYearsArgs,
|
||||
UserStatisticsStatusesArgs,
|
||||
UserStatisticsStudiosArgs,
|
||||
UserStatisticsTagsArgs,
|
||||
UserStatisticsVoiceActorsArgs,
|
||||
} from "../types/generated/graphql.ts"
|
||||
import { Staff } from "./Staff.ts"
|
||||
import { Studio } from "./Studio.ts"
|
||||
|
||||
const UserFormatStatistics = ({ query, level }: Fields<UpdateOperation>) => ({
|
||||
withCount() {
|
||||
query[0] = query[0].set({ subField: "count", level })
|
||||
return this
|
||||
},
|
||||
withMeanScore() {
|
||||
query[0] = query[0].set({ subField: "meanScore", level })
|
||||
return this
|
||||
},
|
||||
withMinutesWatched() {
|
||||
query[0] = query[0].set({ subField: "minutesWatched", level })
|
||||
return this
|
||||
},
|
||||
withChaptersRead() {
|
||||
query[0] = query[0].set({ subField: "chaptersRead", level })
|
||||
return this
|
||||
},
|
||||
withMediaIds() {
|
||||
query[0] = query[0].set({ subField: "mediaIds", level })
|
||||
return this
|
||||
},
|
||||
withFormat() {
|
||||
query[0] = query[0].set({ subField: "format", level })
|
||||
return this
|
||||
},
|
||||
})
|
||||
|
||||
const UserStatusStatistics = ({ query, level }: Fields<UpdateOperation>) => ({
|
||||
withCount() {
|
||||
query[0] = query[0].set({ subField: "count", level })
|
||||
return this
|
||||
},
|
||||
withMeanScore() {
|
||||
query[0] = query[0].set({ subField: "meanScore", level })
|
||||
return this
|
||||
},
|
||||
withMinutesWatched() {
|
||||
query[0] = query[0].set({ subField: "minutesWatched", level })
|
||||
return this
|
||||
},
|
||||
withChaptersRead() {
|
||||
query[0] = query[0].set({ subField: "chaptersRead", level })
|
||||
return this
|
||||
},
|
||||
withMediaIds() {
|
||||
query[0] = query[0].set({ subField: "mediaIds", level })
|
||||
return this
|
||||
},
|
||||
status() {
|
||||
query[0] = query[0].set({ subField: "status", level })
|
||||
return this
|
||||
},
|
||||
})
|
||||
|
||||
const UserScoreStatistics = ({ query, level }: Fields<UpdateOperation>) => ({
|
||||
withCount() {
|
||||
query[0] = query[0].set({ subField: "count", level })
|
||||
return this
|
||||
},
|
||||
withMeanScore() {
|
||||
query[0] = query[0].set({ subField: "meanScore", level })
|
||||
return this
|
||||
},
|
||||
withMinutesWatched() {
|
||||
query[0] = query[0].set({ subField: "minutesWatched", level })
|
||||
return this
|
||||
},
|
||||
withChaptersRead() {
|
||||
query[0] = query[0].set({ subField: "chaptersRead", level })
|
||||
return this
|
||||
},
|
||||
withMediaIds() {
|
||||
query[0] = query[0].set({ subField: "mediaIds", level })
|
||||
return this
|
||||
},
|
||||
score() {
|
||||
query[0] = query[0].set({ subField: "score", level })
|
||||
return this
|
||||
},
|
||||
})
|
||||
|
||||
const UserLengthStatistics = ({ query, level }: Fields<UpdateOperation>) => ({
|
||||
withCount() {
|
||||
query[0] = query[0].set({ subField: "count", level })
|
||||
return this
|
||||
},
|
||||
withMeanScore() {
|
||||
query[0] = query[0].set({ subField: "meanScore", level })
|
||||
return this
|
||||
},
|
||||
withMinutesWatched() {
|
||||
query[0] = query[0].set({ subField: "minutesWatched", level })
|
||||
return this
|
||||
},
|
||||
withChaptersRead() {
|
||||
query[0] = query[0].set({ subField: "chaptersRead", level })
|
||||
return this
|
||||
},
|
||||
withMediaIds() {
|
||||
query[0] = query[0].set({ subField: "mediaIds", level })
|
||||
return this
|
||||
},
|
||||
length() {
|
||||
query[0] = query[0].set({ subField: "length", level })
|
||||
return this
|
||||
},
|
||||
})
|
||||
|
||||
const UserReleaseYearStatistics = ({ query, level }: Fields<UpdateOperation>) => ({
|
||||
withCount() {
|
||||
query[0] = query[0].set({ subField: "count", level })
|
||||
return this
|
||||
},
|
||||
withMeanScore() {
|
||||
query[0] = query[0].set({ subField: "meanScore", level })
|
||||
return this
|
||||
},
|
||||
withMinutesWatched() {
|
||||
query[0] = query[0].set({ subField: "minutesWatched", level })
|
||||
return this
|
||||
},
|
||||
withChaptersRead() {
|
||||
query[0] = query[0].set({ subField: "chaptersRead", level })
|
||||
return this
|
||||
},
|
||||
withMediaIds() {
|
||||
query[0] = query[0].set({ subField: "mediaIds", level })
|
||||
return this
|
||||
},
|
||||
releaseYear() {
|
||||
query[0] = query[0].set({ subField: "releaseYear", level })
|
||||
return this
|
||||
},
|
||||
})
|
||||
|
||||
const UserStartYearStatistics = ({ query, level }: Fields<UpdateOperation>) => ({
|
||||
withCount() {
|
||||
query[0] = query[0].set({ subField: "count", level })
|
||||
return this
|
||||
},
|
||||
withMeanScore() {
|
||||
query[0] = query[0].set({ subField: "meanScore", level })
|
||||
return this
|
||||
},
|
||||
withMinutesWatched() {
|
||||
query[0] = query[0].set({ subField: "minutesWatched", level })
|
||||
return this
|
||||
},
|
||||
withChaptersRead() {
|
||||
query[0] = query[0].set({ subField: "chaptersRead", level })
|
||||
return this
|
||||
},
|
||||
withMediaIds() {
|
||||
query[0] = query[0].set({ subField: "mediaIds", level })
|
||||
return this
|
||||
},
|
||||
startYear() {
|
||||
query[0] = query[0].set({ subField: "startYear", level })
|
||||
return this
|
||||
},
|
||||
})
|
||||
|
||||
const UserGenreStatistics = ({ query, level }: Fields<UpdateOperation>) => ({
|
||||
withCount() {
|
||||
query[0] = query[0].set({ subField: "count", level })
|
||||
return this
|
||||
},
|
||||
withMeanScore() {
|
||||
query[0] = query[0].set({ subField: "meanScore", level })
|
||||
return this
|
||||
},
|
||||
withMinutesWatched() {
|
||||
query[0] = query[0].set({ subField: "minutesWatched", level })
|
||||
return this
|
||||
},
|
||||
withChaptersRead() {
|
||||
query[0] = query[0].set({ subField: "chaptersRead", level })
|
||||
return this
|
||||
},
|
||||
withMediaIds() {
|
||||
query[0] = query[0].set({ subField: "mediaIds", level })
|
||||
return this
|
||||
},
|
||||
genre() {
|
||||
query[0] = query[0].set({ subField: "genre", level })
|
||||
return this
|
||||
},
|
||||
})
|
||||
|
||||
const UserTagStatistics = ({ query, level }: Fields<UpdateOperation>) => ({
|
||||
withCount() {
|
||||
query[0] = query[0].set({ subField: "count", level })
|
||||
return this
|
||||
},
|
||||
withMeanScore() {
|
||||
query[0] = query[0].set({ subField: "meanScore", level })
|
||||
return this
|
||||
},
|
||||
withMinutesWatched() {
|
||||
query[0] = query[0].set({ subField: "minutesWatched", level })
|
||||
return this
|
||||
},
|
||||
withChaptersRead() {
|
||||
query[0] = query[0].set({ subField: "chaptersRead", level })
|
||||
return this
|
||||
},
|
||||
withMediaIds() {
|
||||
query[0] = query[0].set({ subField: "mediaIds", level })
|
||||
return this
|
||||
},
|
||||
tag() {
|
||||
query[0] = query[0].set({ subField: "tag", level })
|
||||
return this
|
||||
},
|
||||
})
|
||||
|
||||
const UserCountryStatistics = ({ query, level }: Fields<UpdateOperation>) => ({
|
||||
withCount() {
|
||||
query[0] = query[0].set({ subField: "count", level })
|
||||
return this
|
||||
},
|
||||
withMeanScore() {
|
||||
query[0] = query[0].set({ subField: "meanScore", level })
|
||||
return this
|
||||
},
|
||||
withMinutesWatched() {
|
||||
query[0] = query[0].set({ subField: "minutesWatched", level })
|
||||
return this
|
||||
},
|
||||
withChaptersRead() {
|
||||
query[0] = query[0].set({ subField: "chaptersRead", level })
|
||||
return this
|
||||
},
|
||||
withMediaIds() {
|
||||
query[0] = query[0].set({ subField: "mediaIds", level })
|
||||
return this
|
||||
},
|
||||
country() {
|
||||
query[0] = query[0].set({ subField: "country", level })
|
||||
return this
|
||||
},
|
||||
})
|
||||
|
||||
const UserVoiceActorStatistics = ({ query, level }: Fields<UpdateOperation>) => ({
|
||||
withCount() {
|
||||
query[0] = query[0].set({ subField: "count", level })
|
||||
return this
|
||||
},
|
||||
withMeanScore() {
|
||||
query[0] = query[0].set({ subField: "meanScore", level })
|
||||
return this
|
||||
},
|
||||
withMinutesWatched() {
|
||||
query[0] = query[0].set({ subField: "minutesWatched", level })
|
||||
return this
|
||||
},
|
||||
withChaptersRead() {
|
||||
query[0] = query[0].set({ subField: "chaptersRead", level })
|
||||
return this
|
||||
},
|
||||
withMediaIds() {
|
||||
query[0] = query[0].set({ subField: "mediaIds", level })
|
||||
return this
|
||||
},
|
||||
withVoiceActor(fn?: Fn<typeof Staff>) {
|
||||
query[0] = query[0].set({ subField: "voiceActor", level, hasSubField: true })
|
||||
let tmpQuery
|
||||
if (fn) fn(Staff({ query: tmpQuery = [query[0]], level: level + 1 }))
|
||||
else Staff({ query: tmpQuery = [query[0]], level: level + 1 }).withId()
|
||||
query[0] = tmpQuery[0]
|
||||
return this
|
||||
},
|
||||
withCharacterIds() {
|
||||
query[0] = query[0].set({ subField: "characterIds", level })
|
||||
return this
|
||||
},
|
||||
})
|
||||
|
||||
const UserStaffStatistics = ({ query, level }: Fields<UpdateOperation>) => ({
|
||||
withCount() {
|
||||
query[0] = query[0].set({ subField: "count", level })
|
||||
return this
|
||||
},
|
||||
withMeanScore() {
|
||||
query[0] = query[0].set({ subField: "meanScore", level })
|
||||
return this
|
||||
},
|
||||
withMinutesWatched() {
|
||||
query[0] = query[0].set({ subField: "minutesWatched", level })
|
||||
return this
|
||||
},
|
||||
withChaptersRead() {
|
||||
query[0] = query[0].set({ subField: "chaptersRead", level })
|
||||
return this
|
||||
},
|
||||
withMediaIds() {
|
||||
query[0] = query[0].set({ subField: "mediaIds", level })
|
||||
return this
|
||||
},
|
||||
withStaff(fn?: Fn<typeof Staff>) {
|
||||
query[0] = query[0].set({ subField: "staff", level, hasSubField: true })
|
||||
let tmpQuery
|
||||
if (fn) fn(Staff({ query: tmpQuery = [query[0]], level: level + 1 }))
|
||||
else Staff({ query: tmpQuery = [query[0]], level: level + 1 }).withId()
|
||||
query[0] = tmpQuery[0]
|
||||
return this
|
||||
},
|
||||
})
|
||||
|
||||
const UserStudioStatistics = ({ query, level }: Fields<UpdateOperation>) => ({
|
||||
withCount() {
|
||||
query[0] = query[0].set({ subField: "count", level })
|
||||
return this
|
||||
},
|
||||
withMeanScore() {
|
||||
query[0] = query[0].set({ subField: "meanScore", level })
|
||||
return this
|
||||
},
|
||||
withMinutesWatched() {
|
||||
query[0] = query[0].set({ subField: "minutesWatched", level })
|
||||
return this
|
||||
},
|
||||
withChaptersRead() {
|
||||
query[0] = query[0].set({ subField: "chaptersRead", level })
|
||||
return this
|
||||
},
|
||||
withMediaIds() {
|
||||
query[0] = query[0].set({ subField: "mediaIds", level })
|
||||
return this
|
||||
},
|
||||
withStudio(fn?: Fn<typeof Studio>) {
|
||||
query[0] = query[0].set({ subField: "studio", level, hasSubField: true })
|
||||
let tmpQuery
|
||||
if (fn) fn(Studio({ query: tmpQuery = [query[0]], level: level + 1 }))
|
||||
else Studio({ query: tmpQuery = [query[0]], level: level + 1 }).withId()
|
||||
query[0] = tmpQuery[0]
|
||||
return this
|
||||
},
|
||||
})
|
||||
|
||||
export const UserStatistics = ({ query, level }: Fields<UpdateOperation>) => ({
|
||||
withCount() {
|
||||
query[0] = query[0].set({ subField: "count", level })
|
||||
return this
|
||||
},
|
||||
withMeanScore() {
|
||||
query[0] = query[0].set({ subField: "meanScore", level })
|
||||
return this
|
||||
},
|
||||
withStandardDeviation() {
|
||||
query[0] = query[0].set({ subField: "standardDeviation", level })
|
||||
return this
|
||||
},
|
||||
withMinutesWatched() {
|
||||
query[0] = query[0].set({ subField: "minutesWatched", level })
|
||||
return this
|
||||
},
|
||||
withEpisodesWatched() {
|
||||
query[0] = query[0].set({ subField: "episodesWatched", level })
|
||||
return this
|
||||
},
|
||||
withChaptersRead() {
|
||||
query[0] = query[0].set({ subField: "chaptersRead", level })
|
||||
return this
|
||||
},
|
||||
withVolumesRead() {
|
||||
query[0] = query[0].set({ subField: "volumesRead", level })
|
||||
return this
|
||||
},
|
||||
withFormats(
|
||||
op: { args?: UserStatisticsFormatsArgs; fn: Fn<typeof UserFormatStatistics> },
|
||||
) {
|
||||
query[0] = query[0].set({ subField: "formats", level, hasSubField: true })
|
||||
let tmpQuery
|
||||
op.fn(UserFormatStatistics({ query: tmpQuery = [query[0]], level: level + 1 }))
|
||||
query[0] = tmpQuery[0]
|
||||
return this
|
||||
},
|
||||
withStatuses(op: { args?: UserStatisticsStatusesArgs; fn: Fn<typeof UserStatusStatistics> }) {
|
||||
query[0] = query[0].set({ subField: "statuses", level, hasSubField: true })
|
||||
let tmpQuery
|
||||
op.fn(UserStatusStatistics({ query: tmpQuery = [query[0]], level: level + 1 }))
|
||||
query[0] = tmpQuery[0]
|
||||
return this
|
||||
},
|
||||
withScores(op: { args?: UserStatisticsScoresArgs; fn: Fn<typeof UserScoreStatistics> }) {
|
||||
query[0] = query[0].set({ subField: "scores", level, hasSubField: true })
|
||||
let tmpQuery
|
||||
op.fn(UserScoreStatistics({ query: tmpQuery = [query[0]], level: level + 1 }))
|
||||
query[0] = tmpQuery[0]
|
||||
return this
|
||||
},
|
||||
withLengths(op: { args?: UserStatisticsLengthsArgs; fn: Fn<typeof UserLengthStatistics> }) {
|
||||
query[0] = query[0].set({ subField: "lengths", level, hasSubField: true })
|
||||
let tmpQuery
|
||||
op.fn(UserLengthStatistics({ query: tmpQuery = [query[0]], level: level + 1 }))
|
||||
query[0] = tmpQuery[0]
|
||||
return this
|
||||
},
|
||||
withReleaseYears(
|
||||
op: { args?: UserStatisticsReleaseYearsArgs; fn: Fn<typeof UserReleaseYearStatistics> },
|
||||
) {
|
||||
query[0] = query[0].set({ subField: "releaseYears", level, hasSubField: true })
|
||||
let tmpQuery
|
||||
op.fn(UserReleaseYearStatistics({ query: tmpQuery = [query[0]], level: level + 1 }))
|
||||
query[0] = tmpQuery[0]
|
||||
return this
|
||||
},
|
||||
withStartYears(
|
||||
op: { args?: UserStatisticsStartYearsArgs; fn: Fn<typeof UserStartYearStatistics> },
|
||||
) {
|
||||
query[0] = query[0].set({ subField: "startYears", level, hasSubField: true })
|
||||
let tmpQuery
|
||||
op.fn(UserStartYearStatistics({ query: tmpQuery = [query[0]], level: level + 1 }))
|
||||
query[0] = tmpQuery[0]
|
||||
return this
|
||||
},
|
||||
withGenres(op: { args?: UserStatisticsGenresArgs; fn: Fn<typeof UserGenreStatistics> }) {
|
||||
query[0] = query[0].set({ subField: "genres", level, hasSubField: true })
|
||||
let tmpQuery
|
||||
op.fn(UserGenreStatistics({ query: tmpQuery = [query[0]], level: level + 1 }))
|
||||
query[0] = tmpQuery[0]
|
||||
return this
|
||||
},
|
||||
withTags(op: { args?: UserStatisticsTagsArgs; fn: Fn<typeof UserTagStatistics> }) {
|
||||
query[0] = query[0].set({ subField: "tags", level, hasSubField: true })
|
||||
let tmpQuery
|
||||
op.fn(UserTagStatistics({ query: tmpQuery = [query[0]], level: level + 1 }))
|
||||
query[0] = tmpQuery[0]
|
||||
return this
|
||||
},
|
||||
withCountries(op: { args?: UserStatisticsCountriesArgs; fn: Fn<typeof UserCountryStatistics> }) {
|
||||
query[0] = query[0].set({ subField: "countries", level, hasSubField: true })
|
||||
let tmpQuery
|
||||
op.fn(UserCountryStatistics({ query: tmpQuery = [query[0]], level: level + 1 }))
|
||||
query[0] = tmpQuery[0]
|
||||
return this
|
||||
},
|
||||
withVoiceActors(
|
||||
op: { args?: UserStatisticsVoiceActorsArgs; fn: Fn<typeof UserVoiceActorStatistics> },
|
||||
) {
|
||||
query[0] = query[0].set({ subField: "voiceActors", level, hasSubField: true })
|
||||
let tmpQuery
|
||||
op.fn(UserVoiceActorStatistics({ query: tmpQuery = [query[0]], level: level + 1 }))
|
||||
query[0] = tmpQuery[0]
|
||||
return this
|
||||
},
|
||||
withStaff(op: { args?: UserStatisticsStaffArgs; fn: Fn<typeof UserStaffStatistics> }) {
|
||||
query[0] = query[0].set({ subField: "staff", level, hasSubField: true })
|
||||
let tmpQuery
|
||||
op.fn(UserStaffStatistics({ query: tmpQuery = [query[0]], level: level + 1 }))
|
||||
query[0] = tmpQuery[0]
|
||||
return this
|
||||
},
|
||||
withStudios(op: { args?: UserStatisticsStudiosArgs; fn: Fn<typeof UserStudioStatistics> }) {
|
||||
query[0] = query[0].set({ subField: "studios", level, hasSubField: true })
|
||||
let tmpQuery
|
||||
op.fn(UserStudioStatistics({ query: tmpQuery = [query[0]], level: level + 1 }))
|
||||
query[0] = tmpQuery[0]
|
||||
return this
|
||||
},
|
||||
})
|
||||
|
||||
export const UserStatisticTypes = ({ query, level }: Fields<UpdateOperation>) => ({
|
||||
withAnime(fn: Fn<typeof UserStatistics>) {
|
||||
query[0] = query[0].set({ subField: "anime", level, hasSubField: true })
|
||||
let tmpQuery
|
||||
fn(UserStatistics({ query: tmpQuery = [query[0]], level: level + 1 }))
|
||||
query[0] = tmpQuery[0]
|
||||
return this
|
||||
},
|
||||
withManga(fn: Fn<typeof UserStatistics>) {
|
||||
query[0] = query[0].set({ subField: "manga", level, hasSubField: true })
|
||||
let tmpQuery
|
||||
fn(UserStatistics({ query: tmpQuery = [query[0]], level: level + 1 }))
|
||||
query[0] = tmpQuery[0]
|
||||
return this
|
||||
},
|
||||
})
|
Loading…
Reference in New Issue