diff --git a/schema.gql b/schema.gql index 59098b0d0..c9f95ee41 100644 --- a/schema.gql +++ b/schema.gql @@ -1016,6 +1016,7 @@ type Mutation { stopNftCreate(input: StopNftCreateArgs!): TransactionNode! transferNft(input: TransferNftArgs!): TransactionNode! transferNftCreateRole(input: TransferNftCreateRoleArgs!): TransactionNode! + trigerScamUpdate(input: ScamUpdateInput!): Boolean! updateCollectionRarities(collectionTicker: String!): Boolean! updateCollectionTraits(collectionTicker: String!): Boolean! updateMarketplace(input: UpdateMarketplaceArgs!): Boolean! @@ -1342,6 +1343,11 @@ enum ScamInfoTypeEnum { scam } +input ScamUpdateInput { + collectionIdentifier: String! + type: ScamInfoTypeEnum! +} + input SearchFilter { searchTerm: String! } diff --git a/src/modules/admins/admin-operations.module.ts b/src/modules/admins/admin-operations.module.ts index af4919db0..f8ac966c7 100644 --- a/src/modules/admins/admin-operations.module.ts +++ b/src/modules/admins/admin-operations.module.ts @@ -13,11 +13,13 @@ import { NftTraitsModule } from '../nft-traits/nft-traits.module'; import { MarketplacesModuleGraph } from '../marketplaces/marketplaces.module'; import { AuthModule } from '../auth/auth.module'; import { ReportsModuleGraph } from '../reports/reports.module'; +import { ScamUpdatePublisherModule } from '../rabbitmq/elastic-updates/scam-trigger/scam-update-publiser.module'; @Module({ imports: [ CommonModule, CacheEventsPublisherModule, + ScamUpdatePublisherModule, MxCommunicationModule, NftRarityModuleGraph, NftTraitsModule, @@ -36,4 +38,4 @@ import { ReportsModuleGraph } from '../reports/reports.module'; ], exports: [FlagNftService], }) -export class AdminOperationsModuleGraph {} +export class AdminOperationsModuleGraph { } diff --git a/src/modules/admins/admin-operations.resolver.ts b/src/modules/admins/admin-operations.resolver.ts index 1955fdb35..3de04445d 100644 --- a/src/modules/admins/admin-operations.resolver.ts +++ b/src/modules/admins/admin-operations.resolver.ts @@ -17,6 +17,8 @@ import { ReportsService } from '../reports/reports.service'; import { ClearReportCollectionInput, ClearReportInput } from './models/clear-report.input'; import { MarketplaceReindexDataArgs } from '../marketplaces/models/MarketplaceReindexDataArgs'; import { GraphQLError } from 'graphql'; +import { ScamUpdatePublisherService } from '../rabbitmq/elastic-updates/scam-trigger/scam-update-publiser.service'; +import { ScamUpdateInput } from './models/scam-update.input'; @Resolver(() => Boolean) export class AdminOperationsResolver { @@ -27,9 +29,10 @@ export class AdminOperationsResolver { private readonly nftRarityService: NftRarityService, private readonly nftTraitService: NftTraitsService, private readonly cacheEventsPublisherService: CacheEventsPublisherService, + private readonly scamUpdatePublisherService: ScamUpdatePublisherService, private readonly marketplaceEventsIndexingService: MarketplaceEventsIndexingService, private readonly marketplacesReindexService: MarketplacesReindexService, - ) {} + ) { } @Mutation(() => Boolean) @UseGuards(JwtOrNativeAuthGuard, GqlAdminAuthGuard) @@ -157,4 +160,11 @@ export class AdminOperationsResolver { }); return true; } + + @Mutation(() => Boolean) + @UseGuards(JwtOrNativeAuthGuard, GqlAdminAuthGuard) + async trigerScamUpdate(@Args('input', { type: () => ScamUpdateInput }) input: ScamUpdateInput): Promise { + this.scamUpdatePublisherService.publish({ collectionIdentifier: input.collectionIdentifier, type: input.type }); + return true; + } } diff --git a/src/modules/admins/models/scam-update.input.ts b/src/modules/admins/models/scam-update.input.ts new file mode 100644 index 000000000..cf7801cab --- /dev/null +++ b/src/modules/admins/models/scam-update.input.ts @@ -0,0 +1,16 @@ +import { InputType, Field } from '@nestjs/graphql'; +import { Matches } from 'class-validator'; +import { ScamInfoTypeEnum } from 'src/modules/assets/models'; +import { COLLECTION_IDENTIFIER_ERROR, COLLECTION_IDENTIFIER_RGX } from 'src/utils/constants'; + +@InputType() +export class ScamUpdateInput { + @Matches(RegExp(COLLECTION_IDENTIFIER_RGX), { + message: COLLECTION_IDENTIFIER_ERROR, + }) + @Field(() => String) + collectionIdentifier: string; + + @Field(() => ScamInfoTypeEnum) + type: ScamInfoTypeEnum; +} diff --git a/src/modules/rabbitmq/cache-invalidation/cache-events.module.ts b/src/modules/rabbitmq/cache-invalidation/cache-events.module.ts index 46db42104..008f9e93e 100644 --- a/src/modules/rabbitmq/cache-invalidation/cache-events.module.ts +++ b/src/modules/rabbitmq/cache-invalidation/cache-events.module.ts @@ -18,12 +18,14 @@ import { CampaignsCachingService } from 'src/modules/campaigns/campaigns-caching import { MarketplaceRedisHandler } from 'src/modules/marketplaces/loaders/marketplace.redis-handler'; import { AssetsSupplyRedisHandler } from 'src/modules/assets/loaders/assets-supply.redis-handler'; import { PubSubListenerModule } from 'src/pubsub/pub.sub.listener.module'; +import { ScamUpdatePublisherModule } from '../elastic-updates/scam-trigger/scam-update-publiser.module'; @Module({ imports: [ PubSubListenerModule, CommonModule, CacheInvalidationEventsModule, + ScamUpdatePublisherModule, CacheAdminEventsModule, CommonRabbitModule.register(() => { return { @@ -49,4 +51,4 @@ import { PubSubListenerModule } from 'src/pubsub/pub.sub.listener.module'; ], exports: [], }) -export class CacheEventsModule {} +export class CacheEventsModule { } diff --git a/src/modules/rabbitmq/elastic-updates/scam-trigger/markScamCollection.event.ts b/src/modules/rabbitmq/elastic-updates/scam-trigger/markScamCollection.event.ts new file mode 100644 index 000000000..3d3f9e40e --- /dev/null +++ b/src/modules/rabbitmq/elastic-updates/scam-trigger/markScamCollection.event.ts @@ -0,0 +1,9 @@ +import { ScamInfoTypeEnum } from "src/modules/assets/models"; + +export class MarkScamCollectionEvent { + collectionIdentifier: string; + type: ScamInfoTypeEnum + constructor(init?: Partial) { + Object.assign(this, init); + } +} diff --git a/src/modules/rabbitmq/elastic-updates/scam-trigger/scam-update-events.consumer.ts b/src/modules/rabbitmq/elastic-updates/scam-trigger/scam-update-events.consumer.ts new file mode 100644 index 000000000..53ab90bac --- /dev/null +++ b/src/modules/rabbitmq/elastic-updates/scam-trigger/scam-update-events.consumer.ts @@ -0,0 +1,23 @@ +import { Injectable } from '@nestjs/common'; +import { rabbitExchanges, rabbitQueues } from '../../rabbit-config'; +import { MarkScamCollectionEvent } from './markScamCollection.event'; +import { CompetingRabbitConsumer } from '../../rabbitmq.consumers'; +import { CollectionScamService } from 'src/modules/scam/collection-scam.service'; +import { ScamInfoTypeEnum } from 'src/modules/assets/models'; +@Injectable() +export class ScamUpdateEventsConsumer { + constructor(private readonly collectionScamService: CollectionScamService) { } + + @CompetingRabbitConsumer({ + connection: 'default', + queueName: rabbitQueues.SCAM_UPDATE, + exchange: rabbitExchanges.SCAM_UPDATE, + }) + async consumeScamEvents(event: MarkScamCollectionEvent) { + if (event.type === ScamInfoTypeEnum.none) { + await this.collectionScamService.manuallyClearCollectionScamInfo(event.collectionIdentifier) + } else { + await this.collectionScamService.manuallySetCollectionScamInfo(event.collectionIdentifier) + } + } +} diff --git a/src/modules/rabbitmq/elastic-updates/scam-trigger/scam-update-publiser.module.ts b/src/modules/rabbitmq/elastic-updates/scam-trigger/scam-update-publiser.module.ts new file mode 100644 index 000000000..cad00d2ed --- /dev/null +++ b/src/modules/rabbitmq/elastic-updates/scam-trigger/scam-update-publiser.module.ts @@ -0,0 +1,19 @@ +import { Global, Module } from '@nestjs/common'; +import { rabbitExchanges } from '../../rabbit-config'; +import { CommonRabbitModule } from '../../cache-invalidation/common-rabbitmq.module'; +import { ScamUpdatePublisherService } from './scam-update-publiser.service'; + +@Global() +@Module({ + imports: [ + CommonRabbitModule.register(() => { + return { + exchange: rabbitExchanges.SCAM_UPDATE, + uri: process.env.COMMON_RABBITMQ_URL, + }; + }), + ], + providers: [ScamUpdatePublisherService], + exports: [ScamUpdatePublisherService], +}) +export class ScamUpdatePublisherModule { } diff --git a/src/modules/rabbitmq/elastic-updates/scam-trigger/scam-update-publiser.service.ts b/src/modules/rabbitmq/elastic-updates/scam-trigger/scam-update-publiser.service.ts new file mode 100644 index 000000000..584e69bf4 --- /dev/null +++ b/src/modules/rabbitmq/elastic-updates/scam-trigger/scam-update-publiser.service.ts @@ -0,0 +1,14 @@ +import { Injectable } from '@nestjs/common'; +import { rabbitExchanges } from '../../rabbit-config'; +import { RabbitPublisherService } from '../../rabbit.publisher'; +import { MarkScamCollectionEvent } from './markScamCollection.event'; + + +@Injectable() +export class ScamUpdatePublisherService { + constructor(private readonly rabbitPublisherService: RabbitPublisherService) { } + + async publish(payload: MarkScamCollectionEvent) { + await this.rabbitPublisherService.publish(rabbitExchanges.SCAM_UPDATE, payload); + } +} diff --git a/src/modules/rabbitmq/rabbit-config.ts b/src/modules/rabbitmq/rabbit-config.ts index c6a5f890a..243712f68 100644 --- a/src/modules/rabbitmq/rabbit-config.ts +++ b/src/modules/rabbitmq/rabbit-config.ts @@ -14,8 +14,10 @@ export interface RabbitModuleConfig { export const rabbitExchanges = { CACHE_INVALIDATION: 'nft-cache-invalidation', NFT_LIKE: 'x_portal_gamification_nft_likes_exchange', + SCAM_UPDATE: 'nft-scam-update', }; export const rabbitQueues = { CACHE_INVALIDATION: 'nft-cache-invalidation', + SCAM_UPDATE: 'nft-scam-update', }; diff --git a/src/private.app.module.ts b/src/private.app.module.ts index aef270009..ee96127a0 100644 --- a/src/private.app.module.ts +++ b/src/private.app.module.ts @@ -14,6 +14,7 @@ import { ScamModule } from './modules/scam/scam.module'; import { NftTraitsModule } from './modules/nft-traits/nft-traits.module'; import { CacheEventsPublisherModule } from './modules/rabbitmq/cache-invalidation/cache-invalidation-publisher/change-events-publisher.module'; import * as ormconfig from './ormconfig'; +import { ScamUpdatePublisherModule } from './modules/rabbitmq/elastic-updates/scam-trigger/scam-update-publiser.module'; @Module({ imports: [ @@ -22,6 +23,7 @@ import * as ormconfig from './ormconfig'; AdminOperationsModuleGraph, NftRarityModuleGraph, CacheEventsPublisherModule, + ScamUpdatePublisherModule, ScamModule, NftTraitsModule, MarketplacesModuleGraph, @@ -31,4 +33,4 @@ import * as ormconfig from './ormconfig'; controllers: [MetricsController, ReindexController, CachingController], exports: [NsfwUpdaterService, RarityUpdaterService], }) -export class PrivateAppModule {} +export class PrivateAppModule { }