Skip to content

Commit

Permalink
feat: user query available character api
Browse files Browse the repository at this point in the history
  • Loading branch information
harisato committed Oct 16, 2024
1 parent e785076 commit a4fa79b
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/modules/story-event/story-event.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,14 @@ export class StoryEventController {
collectCharacter(@Param() param: CollectCharacterParamDto) {
return this.storyEventSvc.collectCharacter(param.id);
}

@Get('character/available')
@UseGuards(AuthGuard, RolesGuard)
@ApiBearerAuth()
@UseInterceptors(AuthUserInterceptor)
@SetRequestTimeout()
@Roles(Role.User)
queryAvailableCharacter() {
return this.storyEventSvc.queryAvailableCharacter();
}
}
67 changes: 67 additions & 0 deletions src/modules/story-event/story-event.graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -521,4 +521,71 @@ export class StoryEventGraphql {
headers
);
}

async queryAvailableCharacters(variables: any) {
const headers = {
'x-hasura-admin-secret': this.configSvc.get<string>(
'graphql.adminSecret'
),
};

return this.graphqlSvc.query(
this.configSvc.get<string>('graphql.endpoint'),
'',
`query availableCharacter($user_id: bpchar) {
default: story_character(where: {is_default_character: {_eq: true}}) {
id
avatar_url
descripton_url
is_default_character
name
status
authorizer_user {
id
nickname
}
story_ip_asset {
id
ip_asset_id
}
}
collected: story_character(where: {user_collect_characters: {user_id: {_eq: $user_id}}}) {
id
avatar_url
descripton_url
is_default_character
name
status
authorizer_user {
id
nickname
}
story_ip_asset {
id
ip_asset_id
}
}
user_ip: story_character(where: {user_id: {_eq: $user_id}}) {
id
avatar_url
descripton_url
is_default_character
name
status
authorizer_user {
id
nickname
}
story_ip_asset {
id
ip_asset_id
}
}
}
`,
'availableCharacter',
variables,
headers
);
}
}
7 changes: 7 additions & 0 deletions src/modules/story-event/story-event.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,4 +505,11 @@ export class StoryEventService {
},
});
}

async queryAvailableCharacter() {
const { userId } = ContextProvider.getAuthUser();
return this.storyEventGraphql.queryAvailableCharacters({
user_id: userId,
});
}
}

0 comments on commit a4fa79b

Please sign in to comment.