-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update scam detection #1079
Update scam detection #1079
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe use PascalCase for enums (if applicable)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I need to keep them like this here because of mongo |
||
allow = 'allow' | ||
} | ||
|
||
registerEnumType(ScamInputEnum, { | ||
name: 'ScamInputEnum', | ||
}); |
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); | ||
} | ||
} |
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 { } |
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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could have also been "else if" for "deny", and throw error (unrecognized) on "else". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would like to let it like this because are only two possibilities and in the future if we add another one then update the condition 🙏 |
||
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); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍