Skip to content

Commit

Permalink
added notification for team
Browse files Browse the repository at this point in the history
  • Loading branch information
mertlsarac committed Dec 25, 2022
1 parent 5ffea8c commit 35edc43
Showing 1 changed file with 46 additions and 4 deletions.
50 changes: 46 additions & 4 deletions app/controller/team.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Context, TeamRole, MongoDbProvider, TokenUtil, JoinTeamMailActionParams, MessageQueueChannelType } from "@open-template-hub/common";
import { Context, TeamRole, MongoDbProvider, TokenUtil, JoinTeamMailActionParams, MessageQueueChannelType, MessageQueueProvider, NotificationParams, BusinessLogicActionType, QueueMessage } from "@open-template-hub/common";
import { Environment } from "../../environment";
import { TeamRepository } from "../repository/team.repository";
import { UserRepository } from "../repository/user.repository";
Expand Down Expand Up @@ -89,6 +89,17 @@ export class TeamController {
message,
orchestrationChannelTag as string
);

const notificationParams = {
timestamp: new Date().getTime(),
username: writerUser.username,
message: "Join request from " + team.name
} as NotificationParams;

await this.sendJoinTeamRequestNotificationToQueue(
context.message_queue_provider,
notificationParams
)
}

addReader = async (
Expand Down Expand Up @@ -142,6 +153,17 @@ export class TeamController {
message,
orchestrationChannelTag as string
);

const notificationParams = {
timestamp: new Date().getTime(),
username: readerUser.username,
message: "Join request from " + team.name
} as NotificationParams;

await this.sendJoinTeamRequestNotificationToQueue(
context.message_queue_provider,
notificationParams
)
}

removeWriter = async (
Expand Down Expand Up @@ -199,13 +221,11 @@ export class TeamController {
mongodb_provider.getConnection()
);

const teamRepositoryResponse = await teamRepository.verify(
await teamRepository.verify(
decodedToken.username,
decodedToken.team.id,
decodedToken.team.role
);

console.log(teamRepositoryResponse);
}

deleteTeam = async (
Expand All @@ -219,4 +239,26 @@ export class TeamController {
context.username
);
}

private async sendJoinTeamRequestNotificationToQueue(
messageQueueProvider: MessageQueueProvider,
notificationParams: NotificationParams
) {
const orchestrationChannelTag = this.environment.args().mqArgs?.orchestrationServerMessageQueueChannel

const message = {
sender: MessageQueueChannelType.AUTH,
receiver: MessageQueueChannelType.BUSINESS_LOGIC,
message: {
notification: {
params: notificationParams
}
} as BusinessLogicActionType
} as QueueMessage

await messageQueueProvider.publish(
message,
orchestrationChannelTag as string
)
}
}

0 comments on commit 35edc43

Please sign in to comment.