diff --git a/hasura/metadata/databases/punkga-pg/tables/public_story_ip_asset.yaml b/hasura/metadata/databases/punkga-pg/tables/public_story_ip_asset.yaml index 17541f3..d6595e8 100644 --- a/hasura/metadata/databases/punkga-pg/tables/public_story_ip_asset.yaml +++ b/hasura/metadata/databases/punkga-pg/tables/public_story_ip_asset.yaml @@ -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 diff --git a/hasura/metadata/databases/punkga-pg/tables/public_story_manga.yaml b/hasura/metadata/databases/punkga-pg/tables/public_story_manga.yaml index a14f6dc..2686ca4 100644 --- a/hasura/metadata/databases/punkga-pg/tables/public_story_manga.yaml +++ b/hasura/metadata/databases/punkga-pg/tables/public_story_manga.yaml @@ -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 diff --git a/hasura/metadata/databases/punkga-pg/tables/public_story_manga_character.yaml b/hasura/metadata/databases/punkga-pg/tables/public_story_manga_character.yaml index 0f45318..c857733 100644 --- a/hasura/metadata/databases/punkga-pg/tables/public_story_manga_character.yaml +++ b/hasura/metadata/databases/punkga-pg/tables/public_story_manga_character.yaml @@ -1,3 +1,7 @@ table: name: story_manga_character schema: public +object_relationships: + - name: story_character + using: + foreign_key_constraint_on: story_character_id diff --git a/src/modules/chapter/chapter.graphql.ts b/src/modules/chapter/chapter.graphql.ts index 993ff87..86244df 100644 --- a/src/modules/chapter/chapter.graphql.ts +++ b/src/modules/chapter/chapter.graphql.ts @@ -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( + 'graphql.adminSecret' + ), + }; + const result = await this.graphqlSvc.query( + this.configService.get('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; + } } diff --git a/src/modules/chapter/chapter.service.ts b/src/modules/chapter/chapter.service.ts index 0fa08d7..a70e9b8 100644 --- a/src/modules/chapter/chapter.service.ts +++ b/src/modules/chapter/chapter.service.ts @@ -7,6 +7,7 @@ import rimraf from 'rimraf'; import { ForbiddenException, Injectable, + InternalServerErrorException, Logger, NotFoundException, } from '@nestjs/common'; @@ -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 = { @@ -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); diff --git a/src/modules/story-event/story-event.consumer.ts b/src/modules/story-event/story-event.consumer.ts index 0757201..388ce9a 100644 --- a/src/modules/story-event/story-event.consumer.ts +++ b/src/modules/story-event/story-event.consumer.ts @@ -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( diff --git a/src/modules/story-event/story-event.graphql.ts b/src/modules/story-event/story-event.graphql.ts index 1c786ed..495ef2b 100644 --- a/src/modules/story-event/story-event.graphql.ts +++ b/src/modules/story-event/story-event.graphql.ts @@ -367,7 +367,7 @@ export class StoryEventGraphql { return this.graphqlSvc.query( this.configSvc.get('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 @@ -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 }