diff options
| author | Fuwn <[email protected]> | 2024-10-09 00:41:20 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2024-10-09 00:41:43 -0700 |
| commit | 998b63a35256ac985a5a2714dd1ca451af4dfd8a (patch) | |
| tree | 50796121a9d5ab0330fdc5d7e098bda2860d9726 /src/graphql/user | |
| parent | feat(graphql): add badgeCount field (diff) | |
| download | due.moe-998b63a35256ac985a5a2714dd1ca451af4dfd8a.tar.xz due.moe-998b63a35256ac985a5a2714dd1ca451af4dfd8a.zip | |
chore(prettier): use spaces instead of tabs
Diffstat (limited to 'src/graphql/user')
| -rw-r--r-- | src/graphql/user/resolvers.ts | 30 | ||||
| -rw-r--r-- | src/graphql/user/schema.graphql | 78 |
2 files changed, 58 insertions, 50 deletions
diff --git a/src/graphql/user/resolvers.ts b/src/graphql/user/resolvers.ts index 9bccbd6b..4609108a 100644 --- a/src/graphql/user/resolvers.ts +++ b/src/graphql/user/resolvers.ts @@ -12,7 +12,17 @@ import type { WithIndex } from '../$types'; import type { Resolvers, Badge } from './$types'; import authorisedJson from '$lib/Data/Static/authorised.json'; import type { RequestEvent } from '@sveltejs/kit'; -import { getUserPreferences, setBiography, setCSS, setPinnedBadgeWallCategories, toggleHideAWCBadges, toggleHideMissingBadges, toggleHololiveStreamPinning, togglePinnedBadgeWallCategory, type UserPreferences } from '$lib/Database/SB/User/preferences'; +import { + getUserPreferences, + setBiography, + setCSS, + setPinnedBadgeWallCategories, + toggleHideAWCBadges, + toggleHideMissingBadges, + toggleHololiveStreamPinning, + togglePinnedBadgeWallCategory, + type UserPreferences +} from '$lib/Database/SB/User/preferences'; type Context = RequestEvent<Partial<Record<string, string>>, string | null>; @@ -43,14 +53,14 @@ const authenticatedBadgesOperation = async ( await operation(identity, authorised); - const badges = await getUserBadges(identity.id) + const badges = await getUserBadges(identity.id); return { id: identity.id, badges, preferences: {}, badgesCount: badges.length - } + }; }; const authenticatedPreferencesOperation = async ( @@ -68,7 +78,7 @@ const authenticatedPreferencesOperation = async ( badges: [] as Badge[], preferences: await operation(identity, authorised), badgesCount: 0 - } + }; }; export const resolvers: WithIndex<Resolvers> = { @@ -76,7 +86,7 @@ export const resolvers: WithIndex<Resolvers> = { User: async (_, args) => { if (!args.id) return null; - const badges = (await getUserBadges(args.id)) + const badges = await getUserBadges(args.id); return { id: args.id, @@ -95,8 +105,7 @@ export const resolvers: WithIndex<Resolvers> = { shadowHideBadge: async (_, args, context) => await authenticatedBadgesOperation( context, - async () => - await setShadowHiddenBadge(args.id, args.state == null ? true : args.state) + async () => await setShadowHiddenBadge(args.id, args.state == null ? true : args.state) ), hideBadge: async (_, args, context) => await authenticatedBadgesOperation(context, async (identity) => { @@ -113,7 +122,7 @@ export const resolvers: WithIndex<Resolvers> = { allBadges .filter((badge) => badge.category === category) .filter((badge) => badge.hidden).length > - allBadges.filter((badge) => badge.category === category).length / 2 + allBadges.filter((badge) => badge.category === category).length / 2 ? false : true }); @@ -178,12 +187,11 @@ export const resolvers: WithIndex<Resolvers> = { await authenticatedPreferencesOperation( context as Context, async (identity) => await setBiography(identity.id, args.biography.slice(0, 3000)) - ) - , + ), togglePinnedHololiveStream: async (_, args, context) => await authenticatedPreferencesOperation( context as Context, async (identity) => await toggleHololiveStreamPinning(identity.id, args.stream) - ), + ) } }; diff --git a/src/graphql/user/schema.graphql b/src/graphql/user/schema.graphql index f0ac3081..193b5daf 100644 --- a/src/graphql/user/schema.graphql +++ b/src/graphql/user/schema.graphql @@ -1,52 +1,52 @@ type Query { - User(id: Int): User + User(id: Int): User } type Mutation { - shadowHideBadges(userId: Int!): User! - shadowHideBadge(id: Int!, state: Boolean): User! - hideBadge(category: String): User! - updateBadge( - id: Int - post: String - image: String - description: String - time: String - category: String - hidden: Boolean - source: String - designer: String - ): User! - deleteBadge(id: Int!): User! - pruneUserBadges: User! - toggleHideMissingBadges: User! - toggleHideAWCBadges: User! - setBadgeWallCSS(css: String!): User! - togglePinnedBadgeWallCategory(category: String!): User! - setPinnedBadgeWallCategories(categories: [String!]!): User! - setBiography(biography: String!): User! - togglePinnedHololiveStream(stream: String!): User! + shadowHideBadges(userId: Int!): User! + shadowHideBadge(id: Int!, state: Boolean): User! + hideBadge(category: String): User! + updateBadge( + id: Int + post: String + image: String + description: String + time: String + category: String + hidden: Boolean + source: String + designer: String + ): User! + deleteBadge(id: Int!): User! + pruneUserBadges: User! + toggleHideMissingBadges: User! + toggleHideAWCBadges: User! + setBadgeWallCSS(css: String!): User! + togglePinnedBadgeWallCategory(category: String!): User! + setPinnedBadgeWallCategories(categories: [String!]!): User! + setBiography(biography: String!): User! + togglePinnedHololiveStream(stream: String!): User! } type User { - id: Int! - badges: [Badge!]! - preferences: Preferences - badgesCount: Int! + id: Int! + badges: [Badge!]! + preferences: Preferences + badgesCount: Int! } type Badge { - post: String! - image: String! - description: String - id: Int! - time: String! - category: String - hidden: Boolean! - source: String - designer: String - shadow_hidden: Boolean! - click_count: Int! + post: String! + image: String! + description: String + id: Int! + time: String! + category: String + hidden: Boolean! + source: String + designer: String + shadow_hidden: Boolean! + click_count: Int! } type Preferences { |