diff --git a/packages/api/src/entity/user_personalization.ts b/packages/api/src/entity/user_personalization.ts index 5e7cc51f8..76f6a4d1b 100644 --- a/packages/api/src/entity/user_personalization.ts +++ b/packages/api/src/entity/user_personalization.ts @@ -19,34 +19,34 @@ export class UserPersonalization { user!: User @Column('text', { nullable: true }) - fontFamily?: string + fontFamily?: string | null @Column('integer', { nullable: true }) - fontSize?: number + fontSize?: number | null @Column('text', { nullable: true }) - margin?: number + margin?: number | null @Column('text', { nullable: true }) - theme?: string + theme?: string | null @Column('text', { nullable: true }) - libraryLayoutType?: string + libraryLayoutType?: string | null @Column('text', { nullable: true }) - librarySortOrder?: string + librarySortOrder?: string | null @Column('text', { nullable: true }) - speechVoice?: string + speechVoice?: string | null @Column('text', { nullable: true }) - speechSecondaryVoice?: string + speechSecondaryVoice?: string | null @Column('text', { nullable: true }) - speechRate?: string + speechRate?: string | null @Column('text', { nullable: true }) - speechVolume?: string + speechVolume?: string | null @CreateDateColumn({ default: () => 'CURRENT_TIMESTAMP' }) createdAt!: Date diff --git a/packages/api/src/generated/graphql.ts b/packages/api/src/generated/graphql.ts index 1f1815b31..130c6973e 100644 --- a/packages/api/src/generated/graphql.ts +++ b/packages/api/src/generated/graphql.ts @@ -2458,6 +2458,10 @@ export type UserPersonalization = { libraryLayoutType?: Maybe; librarySortOrder?: Maybe; margin?: Maybe; + speechRate?: Maybe; + speechSecondaryVoice?: Maybe; + speechVoice?: Maybe; + speechVolume?: Maybe; theme?: Maybe; }; @@ -4767,6 +4771,10 @@ export type UserPersonalizationResolvers, ParentType, ContextType>; librarySortOrder?: Resolver, ParentType, ContextType>; margin?: Resolver, ParentType, ContextType>; + speechRate?: Resolver, ParentType, ContextType>; + speechSecondaryVoice?: Resolver, ParentType, ContextType>; + speechVoice?: Resolver, ParentType, ContextType>; + speechVolume?: Resolver, ParentType, ContextType>; theme?: Resolver, ParentType, ContextType>; __isTypeOf?: IsTypeOfResolverFn; }; diff --git a/packages/api/src/generated/schema.graphql b/packages/api/src/generated/schema.graphql index 4a4048d46..6a5850c50 100644 --- a/packages/api/src/generated/schema.graphql +++ b/packages/api/src/generated/schema.graphql @@ -1911,6 +1911,10 @@ type UserPersonalization { libraryLayoutType: String librarySortOrder: SortOrder margin: Int + speechRate: String + speechSecondaryVoice: String + speechVoice: String + speechVolume: String theme: String } diff --git a/packages/api/src/resolvers/user_personalization/index.ts b/packages/api/src/resolvers/user_personalization/index.ts index d5b8e8792..54d526012 100644 --- a/packages/api/src/resolvers/user_personalization/index.ts +++ b/packages/api/src/resolvers/user_personalization/index.ts @@ -1,30 +1,35 @@ import { - GetUserPersonalizationResult, GetUserPersonalizationError, - SetUserPersonalizationSuccess, - SetUserPersonalizationError, + GetUserPersonalizationResult, MutationSetUserPersonalizationArgs, + SetUserPersonalizationError, + SetUserPersonalizationSuccess, SortOrder, } from '../../generated/graphql' import { authorized } from '../../utils/helpers' +import { UserPersonalization } from '../../entity/user_personalization' +import { AppDataSource } from '../../server' +import { setClaims } from '../../entity/utils' export const setUserPersonalizationResolver = authorized< SetUserPersonalizationSuccess, SetUserPersonalizationError, MutationSetUserPersonalizationArgs ->(async (_, { input }, { models, authTrx, claims: { uid } }) => { - const updatedUserPersonalization = await authTrx((tx) => - models.userPersonalization.upsert( - { - userId: uid, - ...input, - }, - tx +>(async (_, { input }, { claims: { uid } }) => { + const updatedUserPersonalization = + await AppDataSource.transaction( + async (entityManager) => { + await setClaims(entityManager, uid) + + return entityManager.getRepository(UserPersonalization).save({ + user: { id: uid }, + ...input, + }) + } ) - ) // Cast SortOrder from string to enum - const librarySortOrder = updatedUserPersonalization?.librarySortOrder as + const librarySortOrder = updatedUserPersonalization.librarySortOrder as | SortOrder | null | undefined diff --git a/packages/api/src/schema.ts b/packages/api/src/schema.ts index 7faa4c4a7..b8b9db254 100755 --- a/packages/api/src/schema.ts +++ b/packages/api/src/schema.ts @@ -963,6 +963,10 @@ const schema = gql` margin: Int libraryLayoutType: String librarySortOrder: SortOrder + speechVoice: String + speechSecondaryVoice: String + speechRate: String + speechVolume: String } # Query: UserPersonalization