add featureList to the User type which contains a list of feature type

This commit is contained in:
Hongbo Wu
2024-03-28 14:42:08 +08:00
parent 1afec1ddf3
commit cc2fe04568
5 changed files with 22 additions and 9 deletions

View File

@ -3696,6 +3696,7 @@ export enum UploadImportFileType {
export type User = {
__typename?: 'User';
email?: Maybe<Scalars['String']>;
featureList?: Maybe<Array<Maybe<Feature>>>;
features?: Maybe<Array<Maybe<Scalars['String']>>>;
followersCount?: Maybe<Scalars['Int']>;
friendsCount?: Maybe<Scalars['Int']>;
@ -7139,6 +7140,7 @@ export type UploadImportFileSuccessResolvers<ContextType = ResolverContext, Pare
export type UserResolvers<ContextType = ResolverContext, ParentType extends ResolversParentTypes['User'] = ResolversParentTypes['User']> = {
email?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>;
featureList?: Resolver<Maybe<Array<Maybe<ResolversTypes['Feature']>>>, ParentType, ContextType>;
features?: Resolver<Maybe<Array<Maybe<ResolversTypes['String']>>>, ParentType, ContextType>;
followersCount?: Resolver<Maybe<ResolversTypes['Int']>, ParentType, ContextType>;
friendsCount?: Resolver<Maybe<ResolversTypes['Int']>, ParentType, ContextType>;

View File

@ -2984,6 +2984,7 @@ enum UploadImportFileType {
type User {
email: String
featureList: [Feature]
features: [String]
followersCount: Int
friendsCount: Int

View File

@ -376,7 +376,18 @@ export const functionResolvers = {
if (!ctx.claims?.uid) {
return undefined
}
return findUserFeatures(ctx.claims.uid)
const userFeatures = await findUserFeatures(ctx.claims.uid)
return userFeatures.map((feature) => feature.name)
},
async featureList(
_: User,
__: Record<string, unknown>,
ctx: WithDataSourcesContext
) {
if (!ctx.uid) {
return undefined
}
return findUserFeatures(ctx.uid)
},
},
Article: {

View File

@ -89,6 +89,7 @@ const schema = gql`
source: String
intercomHash: String
features: [String]
featureList: [Feature]
}
type Profile {

View File

@ -122,14 +122,12 @@ export const signFeatureToken = (
)
}
export const findUserFeatures = async (userId: string): Promise<string[]> => {
return (
await getRepository(Feature).find({
where: {
user: { id: userId },
},
})
).map((feature) => feature.name)
export const findUserFeatures = async (userId: string) => {
return getRepository(Feature).find({
where: {
user: { id: userId },
},
})
}
export const findGrantedFeatureByName = async (