Set voice and secondary voice in user personalization

This commit is contained in:
Hongbo Wu 2022-11-11 14:08:28 +08:00
parent f9fa4656d0
commit ac21e4e6c8
5 changed files with 44 additions and 23 deletions

View file

@ -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

View file

@ -2458,6 +2458,10 @@ export type UserPersonalization = {
libraryLayoutType?: Maybe<Scalars['String']>;
librarySortOrder?: Maybe<SortOrder>;
margin?: Maybe<Scalars['Int']>;
speechRate?: Maybe<Scalars['String']>;
speechSecondaryVoice?: Maybe<Scalars['String']>;
speechVoice?: Maybe<Scalars['String']>;
speechVolume?: Maybe<Scalars['String']>;
theme?: Maybe<Scalars['String']>;
};
@ -4767,6 +4771,10 @@ export type UserPersonalizationResolvers<ContextType = ResolverContext, ParentTy
libraryLayoutType?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>;
librarySortOrder?: Resolver<Maybe<ResolversTypes['SortOrder']>, ParentType, ContextType>;
margin?: Resolver<Maybe<ResolversTypes['Int']>, ParentType, ContextType>;
speechRate?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>;
speechSecondaryVoice?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>;
speechVoice?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>;
speechVolume?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>;
theme?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>;
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
};

View file

@ -1911,6 +1911,10 @@ type UserPersonalization {
libraryLayoutType: String
librarySortOrder: SortOrder
margin: Int
speechRate: String
speechSecondaryVoice: String
speechVoice: String
speechVolume: String
theme: String
}

View file

@ -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<UserPersonalization>(
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

View file

@ -963,6 +963,10 @@ const schema = gql`
margin: Int
libraryLayoutType: String
librarySortOrder: SortOrder
speechVoice: String
speechSecondaryVoice: String
speechRate: String
speechVolume: String
}
# Query: UserPersonalization