Skip to content

Commit

Permalink
feat: update flow approve character
Browse files Browse the repository at this point in the history
  • Loading branch information
harisato committed Oct 11, 2024
1 parent 13028b9 commit 2a47222
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 30 deletions.
2 changes: 1 addition & 1 deletion hasura/metadata/query_collections.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1648,7 +1648,7 @@
id
}
}
}
}
- name: User - Unlike character
query: |
mutation UserUnLikeCharacter ($story_character_id: Int!) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Could not auto-generate a down migration.
-- Please write an appropriate down migration for the SQL below:
-- alter table "public"."story_character" add column "story_event_submission" integer
-- null;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alter table "public"."story_character" add column "story_event_submission" integer
null;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."story_character" rename column "story_event_submission_id" to "story_event_submission";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."story_character" rename column "story_event_submission" to "story_event_submission_id";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."story_character" drop constraint "story_character_story_event_submission_id_fkey";
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
alter table "public"."story_character"
add constraint "story_character_story_event_submission_id_fkey"
foreign key ("story_event_submission_id")
references "public"."story_event_submission"
("id") on update set null on delete set null;
5 changes: 3 additions & 2 deletions src/modules/story-event/dto/approve-story-character.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { ApiProperty } from '@nestjs/swagger';
import { StoryCharacterStatus } from '../story-event.enum';

export class UpdateCharacterStatusRequestDto {
@ApiProperty()
ids: number[];
// @ApiProperty({ type: [Number], example: [1] })
@ApiProperty({ type: [Number] })
ids: string;

@ApiProperty({
enum: [StoryCharacterStatus.Approved, StoryCharacterStatus.Rejected],
Expand Down
5 changes: 3 additions & 2 deletions src/modules/story-event/story-event.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,12 @@ export class StoryEventController {
@Post('submission/character/approve')
@UseGuards(AuthGuard, RolesGuard)
@ApiBearerAuth()
@UseInterceptors(AuthUserInterceptor)
@ApiConsumes('multipart/form-data')
@UseInterceptors(AuthUserInterceptor, AnyFilesInterceptor())
@SetRequestTimeout()
@Roles(Role.Admin)
approveCharacter(@Body() data: UpdateCharacterStatusRequestDto) {
return this.storyEventSvc.approveCharacter(data.ids, data.status);
return this.storyEventSvc.approveCharacter(data);
}

@Post('submission/manga')
Expand Down
28 changes: 28 additions & 0 deletions src/modules/story-event/story-event.graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,34 @@ export class StoryEventGraphql {
);
}

async getCharacters(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 story_character($ids: [Int!]!) {
story_character(where: {id: {_in: $ids}}) {
id
name
user_id
ipfs_url
story_event_submission_id
authorizer_user {
active_evm_address
}
}
}`,
'story_character',
variables,
headers
);
}

async insertUserCollectCharacter(variables: any) {
const headers = {
'x-hasura-admin-secret': this.configSvc.get<string>(
Expand Down
66 changes: 41 additions & 25 deletions src/modules/story-event/story-event.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
} from './story-event.enum';
import { StoryEventGraphql } from './story-event.graphql';
import { getBytes32FromIpfsHash } from './utils';
import { UpdateCharacterStatusRequestDto } from './dto/approve-story-character.dto';

@Injectable()
export class StoryEventService {
Expand Down Expand Up @@ -143,33 +144,12 @@ export class StoryEventService {
ipfs_url: `${ipfsDisplayUrl}/${metadataCID}`,
user_id: userId,
status: StoryCharacterStatus.Submitted,
story_event_submission_id:
result.data.insert_story_event_submission_one.id,
},
});

if (insertCharacterResult.errors) return insertCharacterResult;
const jobData = {
name,
user_id: userId,
metadata_ipfs: `${ipfsDisplayUrl}/${metadataCID}`,
charater_id: insertCharacterResult.data.insert_story_character_one.id,
submission_id: result.data.insert_story_event_submission_one.id,
user_wallet_address: userWalletAddress,
};

// create job
await this.storyEventQueue.add(
'event',
{
type: SubmissionType.Character,
data: jobData,
},
{
removeOnComplete: true,
removeOnFail: 10,
attempts: 5,
backoff: 5000,
}
);

return result;

Expand All @@ -183,11 +163,47 @@ export class StoryEventService {
}
}

async approveCharacter(ids: number[], status: StoryCharacterStatus) {
async approveCharacter(data: UpdateCharacterStatusRequestDto) {
const { ids, status } = data;
const arrIds = ids.split(',').map((id) => Number(id));
const { token } = ContextProvider.getAuthUser();

if (status === StoryCharacterStatus.Approved) {
const queryCharactersResult = await this.storyEventGraphql.getCharacters({
ids: arrIds,
});
if (queryCharactersResult.errors) return queryCharactersResult;
const characters = queryCharactersResult.data.story_character;
for (const character of characters) {
const jobData = {
name: character.name,
user_id: character.user_id,
metadata_ipfs: character.ipfs_url,
charater_id: character.id,
submission_id: character.story_event_submission_id,
user_wallet_address: character.authorizer_user.active_evm_address,
};

// create job
await this.storyEventQueue.add(
'event',
{
type: SubmissionType.Character,
data: jobData,
},
{
removeOnComplete: true,
removeOnFail: 10,
attempts: 5,
backoff: 5000,
}
);
}
}

return this.storyEventGraphql.updateStoryCharacterStatus(
{
ids,
ids: arrIds,
status,
},
token
Expand Down

0 comments on commit 2a47222

Please sign in to comment.