-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Ensure that our queue services get validated object data #4843
Changes from all commits
437d432
85e6e61
d8955f4
a019d3b
670f154
1025f18
7a16677
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 |
---|---|---|
|
@@ -3,15 +3,14 @@ import { | |
InboundParseQueue, | ||
InboundParseWorker, | ||
Queue, | ||
QueueOptions, | ||
Worker, | ||
WorkerOptions, | ||
} from '@novu/application-generic'; | ||
import { JobTopicNameEnum } from '@novu/shared'; | ||
import { Injectable, Logger } from '@nestjs/common'; | ||
|
||
import { InboundEmailParse } from '../usecases/inbound-email-parse/inbound-email-parse.usecase'; | ||
import { InboundEmailParseCommand } from '../usecases/inbound-email-parse/inbound-email-parse.command'; | ||
import { IInboundParseDataDto } from '@novu/application-generic/build/main/dtos/inbound-parse-job.dto'; | ||
|
||
const LOG_CONTEXT = 'InboundParseQueueService'; | ||
|
||
|
@@ -34,7 +33,7 @@ export class InboundParseQueueService { | |
} | ||
|
||
public getWorkerProcessor() { | ||
return async ({ data }: { data: InboundEmailParseCommand }) => { | ||
return async ({ data }: { data: IInboundParseDataDto }) => { | ||
Logger.verbose({ data }, 'Processing the inbound parsed email', LOG_CONTEXT); | ||
await this.emailParseUsecase.execute(InboundEmailParseCommand.create({ ...data })); | ||
Comment on lines
+36
to
38
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 wonder if we should do the execution of Command create in this PR or not. it could be a breaking change. |
||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,16 @@ | ||
import { IsDefined, IsNumber, IsOptional, IsString } from 'class-validator'; | ||
import { BaseCommand } from '@novu/application-generic'; | ||
|
||
export class InboundEmailParseCommand extends BaseCommand { | ||
import { | ||
BaseCommand, | ||
IConnection, | ||
IEnvelopeFrom, | ||
IEnvelopeTo, | ||
IFrom, | ||
IHeaders, | ||
IInboundParseDataDto, | ||
ITo, | ||
} from '@novu/application-generic'; | ||
|
||
export class InboundEmailParseCommand extends BaseCommand implements IInboundParseDataDto { | ||
@IsDefined() | ||
@IsString() | ||
html: string; | ||
|
@@ -66,70 +75,3 @@ export class InboundEmailParseCommand extends BaseCommand { | |
@IsDefined() | ||
envelopeTo: IEnvelopeTo[]; | ||
} | ||
|
||
export interface IHeaders { | ||
'content-type': string; | ||
from: string; | ||
to: string; | ||
subject: string; | ||
'message-id': string; | ||
date: string; | ||
'mime-version': string; | ||
} | ||
|
||
export interface IFrom { | ||
address: string; | ||
name: string; | ||
} | ||
|
||
export interface ITo { | ||
address: string; | ||
name: string; | ||
} | ||
|
||
export interface ITlsOptions { | ||
name: string; | ||
standardName: string; | ||
version: string; | ||
} | ||
|
||
export interface IMailFrom { | ||
address: string; | ||
args: boolean; | ||
} | ||
|
||
export interface IRcptTo { | ||
address: string; | ||
args: boolean; | ||
} | ||
|
||
export interface IEnvelope { | ||
mailFrom: IMailFrom; | ||
rcptTo: IRcptTo[]; | ||
} | ||
|
||
export interface IConnection { | ||
id: string; | ||
remoteAddress: string; | ||
remotePort: number; | ||
clientHostname: string; | ||
openingCommand: string; | ||
hostNameAppearsAs: string; | ||
xClient: any; | ||
xForward: any; | ||
transmissionType: string; | ||
tlsOptions: ITlsOptions; | ||
envelope: IEnvelope; | ||
transaction: number; | ||
mailPath: string; | ||
} | ||
|
||
export interface IEnvelopeFrom { | ||
address: string; | ||
args: boolean; | ||
} | ||
|
||
export interface IEnvelopeTo { | ||
address: string; | ||
args: boolean; | ||
} | ||
Comment on lines
-70
to
-135
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. Extracted to application-generic so we could reuse it. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,24 +56,15 @@ export class MarkAllMessagesAs { | |
const isUnreadCountChanged = | ||
command.markAs === MarkMessagesAsEnum.READ || command.markAs === MarkMessagesAsEnum.UNREAD; | ||
|
||
const countQuery = isUnreadCountChanged ? { read: false } : { seen: false }; | ||
|
||
const count = await this.messageRepository.getCount( | ||
command.environmentId, | ||
subscriber._id, | ||
ChannelTypeEnum.IN_APP, | ||
countQuery | ||
); | ||
Comment on lines
-59
to
-66
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. Was not used. |
||
|
||
this.webSocketsQueueService.add( | ||
'sendMessage', | ||
{ | ||
this.webSocketsQueueService.add({ | ||
name: 'sendMessage', | ||
data: { | ||
event: isUnreadCountChanged ? WebSocketEventEnum.UNREAD : WebSocketEventEnum.UNSEEN, | ||
userId: subscriber._id, | ||
_environmentId: command.environmentId, | ||
}, | ||
subscriber._organizationId | ||
); | ||
groupId: subscriber._organizationId, | ||
}); | ||
|
||
this.analyticsService.track( | ||
`Mark all messages as ${command.markAs}- [Notification Center]`, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import { expect } from 'chai'; | ||
|
||
import { InboundMailService } from './inbound-mail.service'; | ||
import { IInboundParseDataDto } from '@novu/application-generic'; | ||
|
||
let inboundMailService: InboundMailService; | ||
|
||
|
@@ -65,7 +66,11 @@ describe('Inbound Mail Service', () => { | |
_organizationId, | ||
_userId, | ||
}; | ||
await inboundMailService.inboundParseQueueService.add(jobId, jobData, _organizationId); | ||
await inboundMailService.inboundParseQueueService.add({ | ||
name: jobId, | ||
data: jobData as unknown as IInboundParseDataDto, | ||
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. Make for the test, IInboundParseDataDto contained a lot of attributes that needed to be added. for now, added casting as those attributes were not tested. |
||
groupId: _organizationId, | ||
}); | ||
|
||
expect(await inboundMailService.inboundParseQueueService.queue.getActiveCount()).to.equal(0); | ||
expect(await inboundMailService.inboundParseQueueService.queue.getWaitingCount()).to.equal(1); | ||
|
@@ -93,7 +98,11 @@ describe('Inbound Mail Service', () => { | |
_organizationId, | ||
_userId, | ||
}; | ||
await inboundMailService.inboundParseQueueService.addMinimalJob(jobId, jobData, _organizationId); | ||
await inboundMailService.inboundParseQueueService.addMinimalJob({ | ||
name: jobId, | ||
data: jobData, | ||
groupId: _organizationId, | ||
}); | ||
|
||
expect(await inboundMailService.inboundParseQueueService.queue.getActiveCount()).to.equal(0); | ||
expect(await inboundMailService.inboundParseQueueService.queue.getWaitingCount()).to.equal(1); | ||
|
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.
Done by me this month, it is not needed as it will be destructured above in
...command,
.More than that i regret that i created two types of one usecase command, Apologies in advance, i will revisit it in order to think of a better way.