-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1079 from multiversx/TOOL-246-update-scam-algorithm
Update scam detection
- Loading branch information
Showing
15 changed files
with
147 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { InputType, Field, registerEnumType } from '@nestjs/graphql'; | ||
import { Matches } from 'class-validator'; | ||
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(() => ScamInputEnum) | ||
type: ScamInputEnum; | ||
} | ||
|
||
export enum ScamInputEnum { | ||
deny = 'deny', | ||
allow = 'allow' | ||
} | ||
|
||
registerEnumType(ScamInputEnum, { | ||
name: 'ScamInputEnum', | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/modules/rabbitmq/elastic-updates/scam-trigger/markScamCollection.event.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { ScamInputEnum } from "src/modules/admins/models/scam-update.input"; | ||
|
||
export class MarkScamCollectionEvent { | ||
collectionIdentifier: string; | ||
type: ScamInputEnum | ||
constructor(init?: Partial<MarkScamCollectionEvent>) { | ||
Object.assign(this, init); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/modules/rabbitmq/elastic-updates/scam-trigger/scam-update-consumer.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { forwardRef, Global, Module } from '@nestjs/common'; | ||
import { rabbitExchanges } from '../../rabbit-config'; | ||
import { CommonRabbitModule } from '../../cache-invalidation/common-rabbitmq.module'; | ||
import { ScamUpdateEventsConsumer } from './scam-update-events.consumer'; | ||
import { ScamModule } from 'src/modules/scam/scam.module'; | ||
|
||
@Global() | ||
@Module({ | ||
imports: [ | ||
CommonRabbitModule.register(() => { | ||
return { | ||
exchange: rabbitExchanges.SCAM_UPDATE, | ||
uri: process.env.COMMON_RABBITMQ_URL, | ||
}; | ||
}), | ||
forwardRef(() => ScamModule) | ||
], | ||
providers: [ScamUpdateEventsConsumer], | ||
exports: [ScamUpdateEventsConsumer], | ||
}) | ||
export class ScamUpdateConsumerModule { } |
23 changes: 23 additions & 0 deletions
23
src/modules/rabbitmq/elastic-updates/scam-trigger/scam-update-events.consumer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { ScamInputEnum } from 'src/modules/admins/models/scam-update.input'; | ||
@Injectable() | ||
export class ScamUpdateEventsConsumer { | ||
constructor(private readonly collectionScamService: CollectionScamService) { } | ||
|
||
@CompetingRabbitConsumer({ | ||
connection: 'common', | ||
queueName: rabbitQueues.SCAM_UPDATE, | ||
exchange: rabbitExchanges.SCAM_UPDATE, | ||
}) | ||
async consumeScamEvents(event: MarkScamCollectionEvent) { | ||
if (event.type === ScamInputEnum.allow) { | ||
await this.collectionScamService.manuallyClearCollectionScamInfo(event.collectionIdentifier) | ||
} else { | ||
await this.collectionScamService.manuallySetCollectionScamInfo(event.collectionIdentifier) | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/modules/rabbitmq/elastic-updates/scam-trigger/scam-update-publiser.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { } |
14 changes: 14 additions & 0 deletions
14
src/modules/rabbitmq/elastic-updates/scam-trigger/scam-update-publiser.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters