generated from xgeekshq/oss-template
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add user to main channel; fix deleted user issues (#947)
- Loading branch information
1 parent
a2f753c
commit e2a5232
Showing
24 changed files
with
254 additions
and
51 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
30 changes: 30 additions & 0 deletions
30
backend/src/modules/communication/applications/slack-add-user-channel.application.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,30 @@ | ||
import { Logger } from '@nestjs/common'; | ||
import { ConfigurationType } from 'src/modules/communication/dto/types'; | ||
import { ConversationsHandlerInterface } from 'src/modules/communication/interfaces/conversations.handler.interface'; | ||
import { UsersHandlerInterface } from 'src/modules/communication/interfaces/users.handler.interface'; | ||
import { AddUserIntoChannelApplicationInterface } from '../interfaces/communication.application.interface copy'; | ||
|
||
export class SlackAddUserIntoChannelApplication implements AddUserIntoChannelApplicationInterface { | ||
private logger = new Logger(SlackAddUserIntoChannelApplication.name); | ||
|
||
constructor( | ||
private readonly config: ConfigurationType, | ||
private readonly conversationsHandler: ConversationsHandlerInterface, | ||
private readonly usersHandler: UsersHandlerInterface | ||
) {} | ||
|
||
public execute(email: string): Promise<boolean> { | ||
return this.inviteMemberToMainChannel(email); | ||
} | ||
|
||
private async inviteMemberToMainChannel(email: string): Promise<boolean> { | ||
try { | ||
const userId = await this.usersHandler.getSlackUserIdByEmail(email); | ||
await this.conversationsHandler.inviteUserToChannel(this.config.slackMasterChannelId, userId); | ||
} catch (e) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
} |
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
48 changes: 48 additions & 0 deletions
48
backend/src/modules/communication/consumers/slack-add-user-channel.consummer.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,48 @@ | ||
import { OnQueueCompleted, Process, Processor } from '@nestjs/bull'; | ||
import { Inject, Logger } from '@nestjs/common'; | ||
import { Job } from 'bull'; | ||
import { AddUserMainChannelType } from 'src/modules/communication/dto/types'; | ||
import { TYPES } from 'src/modules/communication/interfaces/types'; | ||
import { AddUserIntoChannelApplicationInterface } from '../interfaces/communication.application.interface copy'; | ||
import { SlackAddUserToChannelProducer } from '../producers/slack-add-user-channel.producer'; | ||
import { SlackCommunicationEventListeners } from './slack-communication-event-listeners'; | ||
|
||
@Processor(SlackAddUserToChannelProducer.QUEUE_NAME) | ||
export class SlackAddUserToChannelConsumer extends SlackCommunicationEventListeners< | ||
AddUserMainChannelType, | ||
boolean | ||
> { | ||
constructor( | ||
@Inject(TYPES.application.SlackAddUserIntoChannelApplication) | ||
private readonly application: AddUserIntoChannelApplicationInterface | ||
) { | ||
const logger = new Logger(SlackAddUserToChannelConsumer.name); | ||
super(logger); | ||
} | ||
|
||
@Process() | ||
override async communication(job: Job<AddUserMainChannelType>) { | ||
const { email } = job.data; | ||
|
||
this.logger.verbose( | ||
`execute communication for adding user with email: "${email}" and Job id: "${job.id}" (pid ${process.pid})` | ||
); | ||
|
||
const result = await this.application.execute(email); | ||
|
||
return result; | ||
} | ||
|
||
// https://github.com/OptimalBits/bull/blob/develop/REFERENCE.md#events | ||
@OnQueueCompleted() | ||
override async onCompleted(job: Job<AddUserMainChannelType>, result: boolean[]) { | ||
this.logger.verbose( | ||
`Completed Job id: "${job.id}". User with email: ${job.data.email} was ${ | ||
!result[0] ? 'not' : '' | ||
} added to the main channel` | ||
); | ||
this.saveLog( | ||
`User with email: ${job.data.email} was ${!result[0] ? 'not' : ''} added to the main channel` | ||
); | ||
} | ||
} |
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
3 changes: 3 additions & 0 deletions
3
backend/src/modules/communication/interfaces/communication.application.interface copy.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,3 @@ | ||
export interface AddUserIntoChannelApplicationInterface { | ||
execute(email: string): Promise<boolean>; | ||
} |
8 changes: 7 additions & 1 deletion
8
backend/src/modules/communication/interfaces/slack-communication.service.interface.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 |
---|---|---|
@@ -1,7 +1,13 @@ | ||
import { BoardType, ChangeResponsibleType, MergeBoardType } from '../dto/types'; | ||
import { | ||
AddUserMainChannelType, | ||
BoardType, | ||
ChangeResponsibleType, | ||
MergeBoardType | ||
} from '../dto/types'; | ||
|
||
export interface CommunicationServiceInterface { | ||
execute(board: BoardType): Promise<void>; | ||
executeResponsibleChange(changeResponsibleDto: ChangeResponsibleType): Promise<void>; | ||
executeMergeBoardNotification(mergeBoard: MergeBoardType): Promise<void>; | ||
executeAddUserMainChannel(user: AddUserMainChannelType): Promise<void>; | ||
} |
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
39 changes: 39 additions & 0 deletions
39
backend/src/modules/communication/producers/slack-add-user-channel.producer.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,39 @@ | ||
import { InjectQueue } from '@nestjs/bull'; | ||
import { Injectable, Logger } from '@nestjs/common'; | ||
import { Job, Queue } from 'bull'; | ||
import { AddUserMainChannelType } from 'src/modules/communication/dto/types'; | ||
|
||
@Injectable() | ||
export class SlackAddUserToChannelProducer { | ||
private logger = new Logger(SlackAddUserToChannelProducer.name); | ||
|
||
public static readonly QUEUE_NAME = 'SlackAddUserToChannelProducer'; | ||
|
||
public static readonly ATTEMPTS = 3; | ||
|
||
public static readonly BACKOFF = 3; | ||
|
||
public static readonly DELAY = 0; | ||
|
||
public static readonly REMOVE_ON_COMPLETE = true; | ||
|
||
public static readonly REMOVE_ON_FAIL = true; | ||
|
||
public static readonly PRIORITY = 1; | ||
|
||
constructor( | ||
@InjectQueue(SlackAddUserToChannelProducer.QUEUE_NAME) | ||
private readonly queue: Queue | ||
) {} | ||
|
||
// Job Options https://docs.nestjs.com/techniques/queues#job-options | ||
async add(data: AddUserMainChannelType): Promise<Job<AddUserMainChannelType>> { | ||
const job = await this.queue.add(data); | ||
|
||
this.logger.verbose( | ||
`Add user into mainchannel with email "${data.email}" to queue with Job id: "${job.id}"` | ||
); | ||
|
||
return job; | ||
} | ||
} |
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
Oops, something went wrong.