Skip to content

Commit

Permalink
Add scam trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
danielailie committed Sep 18, 2024
1 parent 56eaf98 commit 924f433
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 4 deletions.
6 changes: 6 additions & 0 deletions schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down Expand Up @@ -1342,6 +1343,11 @@ enum ScamInfoTypeEnum {
scam
}

input ScamUpdateInput {
collectionIdentifier: String!
type: ScamInfoTypeEnum!
}

input SearchFilter {
searchTerm: String!
}
Expand Down
4 changes: 3 additions & 1 deletion src/modules/admins/admin-operations.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -36,4 +38,4 @@ import { ReportsModuleGraph } from '../reports/reports.module';
],
exports: [FlagNftService],
})
export class AdminOperationsModuleGraph {}
export class AdminOperationsModuleGraph { }
12 changes: 11 additions & 1 deletion src/modules/admins/admin-operations.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down Expand Up @@ -157,4 +160,11 @@ export class AdminOperationsResolver {
});
return true;
}

@Mutation(() => Boolean)
@UseGuards(JwtOrNativeAuthGuard, GqlAdminAuthGuard)
async trigerScamUpdate(@Args('input', { type: () => ScamUpdateInput }) input: ScamUpdateInput): Promise<boolean> {
this.scamUpdatePublisherService.publish({ collectionIdentifier: input.collectionIdentifier, type: input.type });
return true;
}
}
16 changes: 16 additions & 0 deletions src/modules/admins/models/scam-update.input.ts
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -49,4 +51,4 @@ import { PubSubListenerModule } from 'src/pubsub/pub.sub.listener.module';
],
exports: [],
})
export class CacheEventsModule {}
export class CacheEventsModule { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { ScamInfoTypeEnum } from "src/modules/assets/models";

export class MarkScamCollectionEvent {
collectionIdentifier: string;
type: ScamInfoTypeEnum
constructor(init?: Partial<MarkScamCollectionEvent>) {
Object.assign(this, init);
}
}
Original file line number Diff line number Diff line change
@@ -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)
}
}
}
Original file line number Diff line number Diff line change
@@ -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 { }
Original file line number Diff line number Diff line change
@@ -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);
}
}
2 changes: 2 additions & 0 deletions src/modules/rabbitmq/rabbit-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
};
4 changes: 3 additions & 1 deletion src/private.app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand All @@ -22,6 +23,7 @@ import * as ormconfig from './ormconfig';
AdminOperationsModuleGraph,
NftRarityModuleGraph,
CacheEventsPublisherModule,
ScamUpdatePublisherModule,
ScamModule,
NftTraitsModule,
MarketplacesModuleGraph,
Expand All @@ -31,4 +33,4 @@ import * as ormconfig from './ormconfig';
controllers: [MetricsController, ReindexController, CachingController],
exports: [NsfwUpdaterService, RarityUpdaterService],
})
export class PrivateAppModule {}
export class PrivateAppModule { }

0 comments on commit 924f433

Please sign in to comment.