Skip to content

Commit

Permalink
feat: update create chapter
Browse files Browse the repository at this point in the history
  • Loading branch information
harisato committed Oct 18, 2024
1 parent d70b2a9 commit 239a241
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,10 @@ array_relationships:
table:
name: story_character
schema: public
- name: story_mangas
using:
foreign_key_constraint_on:
column: story_ip_asset_id
table:
name: story_manga
schema: public
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,11 @@ object_relationships:
- name: story_ip_asset
using:
foreign_key_constraint_on: story_ip_asset_id
array_relationships:
- name: story_manga_characters
using:
foreign_key_constraint_on:
column: story_manga_id
table:
name: story_manga_character
schema: public
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
table:
name: story_manga_character
schema: public
object_relationships:
- name: story_character
using:
foreign_key_constraint_on: story_character_id
23 changes: 23 additions & 0 deletions src/modules/chapter/chapter.graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -489,4 +489,27 @@ export class ChapterGraphql {
result.data?.manga_by_pk?.manga_languages[0]?.title || 'Punkga Manga'
);
}

async insertMangaCharacters(variables: any) {
const headers = {
'x-hasura-admin-secret': this.configService.get<string>(
'graphql.adminSecret'
),
};
const result = await this.graphqlSvc.query(
this.configService.get<string>('graphql.endpoint'),
'',
`mutation insert_story_manga_character($objects: [story_manga_character_insert_input!] = {}) {
insert_story_manga_character(objects: $objects) {
affected_rows
}
}
`,
'insert_story_manga_character',
variables,
headers
);

return result;
}
}
21 changes: 21 additions & 0 deletions src/modules/chapter/chapter.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import rimraf from 'rimraf';
import {
ForbiddenException,
Injectable,
InternalServerErrorException,
Logger,
NotFoundException,
} from '@nestjs/common';
Expand Down Expand Up @@ -238,6 +239,25 @@ export class ChapterService {
(character) => character.story_ip_asset.ip_asset_id
);

// insert manga characters
const insertMangaCharacterResult =
await this.chapterGraphql.insertMangaCharacters({
objects: character_ids.map((character) => ({
story_character_id: character.story_character_id,
story_manga_id: storyMangaId,
})),
});
if (insertMangaCharacterResult.errors) {
this.logger.error(
`insert manga characters error: ${JSON.stringify(
insertMangaCharacterResult
)}`
);
throw new InternalServerErrorException(
'insert story characters failed '
);
}

const userWalletAddress =
await this.chapterGraphql.queryUserAddressById(userId);
const jobData = {
Expand All @@ -249,6 +269,7 @@ export class ChapterService {
user_wallet_address: userWalletAddress,
ip_asset_ids: ipAssetIds,
metadata_hash: getBytes32FromIpfsHash(metadataCID),
character_ids,
};

await this.storyEventService.addEventJob(SubmissionType.Manga, jobData);
Expand Down
8 changes: 4 additions & 4 deletions src/modules/story-event/story-event.consumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,18 +197,18 @@ export class StoryEventConsumer implements OnModuleInit {
await this.mintAndRegisterIpAndMakeDerivative(data);

// --- update story artwork set story_ip_id
const updateStoryArtworkResult =
const updateStoryMangaResult =
await this.storyEventGraphql.updateStoryManga({
id: data.story_manga_id,
story_ip_asset_id: storyIPAId,
});
if (updateStoryArtworkResult.errors) {
if (updateStoryMangaResult.errors) {
this.logger.error(
`Update story artwork error: ${JSON.stringify(
updateStoryArtworkResult
updateStoryMangaResult
)}`
);
throw new InternalServerErrorException('Update story artwork failed ');
throw new InternalServerErrorException('Update story manga failed ');
}

this.logger.log(
Expand Down
8 changes: 4 additions & 4 deletions src/modules/story-event/story-event.graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ export class StoryEventGraphql {
return this.graphqlSvc.query(
this.configSvc.get<string>('graphql.endpoint'),
'',
`query story_manga($limit: Int = 10, $offset: Int = 0) {
`query story_manga($limit: Int = 100, $offset: Int = 0) {
story_manga_aggregate(where: {manga: {status: {_eq: "On-Going"}}}) {
aggregate {
count
Expand Down Expand Up @@ -400,9 +400,9 @@ export class StoryEventGraphql {
is_main_language
}
}
story_ip_asset {
ip_asset_id
story_characters {
story_manga_characters {
story_character {
id
avatar_url
descripton_url
}
Expand Down

0 comments on commit 239a241

Please sign in to comment.