Skip to content

Commit

Permalink
fix(api): replace admin user id with org id in tracking (#6368)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChmaraX authored Aug 21, 2024
1 parent e06b89f commit 1955864
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 57 deletions.
2 changes: 1 addition & 1 deletion .source
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ describe('CreateUsageRecords', () => {
const analyticsServiceStub = {
track: sinon.stub(),
};
const communityUserRepositoryStub = { findOne: () => Promise.resolve({ _id: 'user_id' }) };
const upsertSubscriptionUsecase = { execute: () => Promise.resolve() };
const getCustomerUsecase = { execute: () => Promise.resolve() };
const getPlatformNotificationUsageUsecase = { execute: () => Promise.resolve() };
Expand Down Expand Up @@ -87,7 +86,6 @@ describe('CreateUsageRecords', () => {
getCustomerUsecase,
upsertSubscriptionUsecase,
getPlatformNotificationUsageUsecase,
communityUserRepositoryStub,
analyticsServiceStub
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import { Inject, Injectable, NotFoundException } from '@nestjs/common';
import {
MessageEntity,
MessageRepository,
MessageTemplateEntity,
SubscriberRepository,
CommunityUserRepository,
} from '@novu/dal';
import { MessageEntity, MessageRepository, MessageTemplateEntity, SubscriberRepository } from '@novu/dal';
import { AnalyticsService } from '@novu/application-generic';

import { UpdateMessageActionsCommand } from './update-message-actions.command';
Expand All @@ -17,8 +11,7 @@ export class UpdateMessageActions {
constructor(
private messageRepository: MessageRepository,
private subscriberRepository: SubscriberRepository,
private analyticsService: AnalyticsService,
private communityUserRepository: CommunityUserRepository
private analyticsService: AnalyticsService
) {}

async execute(command: UpdateMessageActionsCommand): Promise<MessageEntity> {
Expand Down Expand Up @@ -75,18 +68,12 @@ export class UpdateMessageActions {
);
}

const orgUser = await this.communityUserRepository.findOne({
_organizationId: command.organizationId,
this.analyticsService.track('Notification Action Clicked - [Notification Center]', command.organizationId, {
_subscriber: subscriber._id,
_organization: command.organizationId,
_environment: command.environmentId,
});

if (orgUser) {
this.analyticsService.track('Notification Action Clicked - [Notification Center]', orgUser._id, {
_subscriber: subscriber._id,
_organization: command.organizationId,
_environment: command.environmentId,
});
}

return (await this.messageRepository.findOne({
_environmentId: command.environmentId,
_id: command.messageId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import { Injectable, NotFoundException } from '@nestjs/common';
import {
MessageEntity,
DalException,
MessageRepository,
SubscriberRepository,
SubscriberEntity,
CommunityUserRepository,
} from '@novu/dal';
import { MessageEntity, DalException, MessageRepository, SubscriberRepository, SubscriberEntity } from '@novu/dal';
import {
WebSocketsQueueService,
AnalyticsService,
Expand All @@ -27,8 +20,7 @@ export class RemoveMessage {
private messageRepository: MessageRepository,
private webSocketsQueueService: WebSocketsQueueService,
private analyticsService: AnalyticsService,
private subscriberRepository: SubscriberRepository,
private communityUserRepository: CommunityUserRepository
private subscriberRepository: SubscriberRepository
) {}

async execute(command: RemoveMessageCommand): Promise<MessageEntity> {
Expand Down Expand Up @@ -84,17 +76,11 @@ export class RemoveMessage {
private async updateServices(command: RemoveMessageCommand, subscriber, message, marked: MarkEnum) {
this.updateSocketCount(subscriber, marked);

const orgUser = await this.communityUserRepository.findOne({
_organizationId: command.organizationId,
this.analyticsService.track(`Removed Message - [Notification Center]`, command.organizationId, {
_subscriber: message._subscriberId,
_organization: command.organizationId,
_template: message._templateId,
});

if (orgUser) {
this.analyticsService.track(`Removed Message - [Notification Center]`, orgUser._id, {
_subscriber: message._subscriberId,
_organization: command.organizationId,
_template: message._templateId,
});
}
}

private updateSocketCount(subscriber: SubscriberEntity, mark: MarkEnum) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
SubscriberRepository,
SubscriberEntity,
FeedRepository,
CommunityUserRepository,
} from '@novu/dal';
import { ChannelTypeEnum, WebSocketEventEnum } from '@novu/shared';
import {
Expand All @@ -29,7 +28,6 @@ export class RemoveAllMessages {
private webSocketsQueueService: WebSocketsQueueService,
private analyticsService: AnalyticsService,
private subscriberRepository: SubscriberRepository,
private communityUserRepository: CommunityUserRepository,
private feedRepository: FeedRepository
) {}

Expand Down Expand Up @@ -62,19 +60,13 @@ export class RemoveAllMessages {
await this.updateServices(command, subscriber, MarkEnum.SEEN);
await this.updateServices(command, subscriber, MarkEnum.READ);

const orgUser = await this.communityUserRepository.findOne({
_organizationId: command.organizationId,
this.analyticsService.track(`Removed All Feed Messages - [Notification Center]`, command.organizationId, {
_subscriber: subscriber._id,
_organization: command.organizationId,
_environment: command.environmentId,
_feedId: command.feedId,
});

if (orgUser) {
this.analyticsService.track(`Removed All Feed Messages - [Notification Center]`, orgUser._id, {
_subscriber: subscriber._id,
_organization: command.organizationId,
_environment: command.environmentId,
_feedId: command.feedId,
});
}

await this.invalidateCache.invalidateQuery({
key: buildFeedKey().invalidate({
subscriberId: command.subscriberId,
Expand Down
4 changes: 2 additions & 2 deletions apps/api/src/app/widgets/widgets.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import { SharedModule } from '../shared/shared.module';
import { AuthModule } from '../auth/auth.module';
import { SubscribersModule } from '../subscribers/subscribers.module';
import { IntegrationModule } from '../integrations/integrations.module';
import { CommunityOrganizationRepository, CommunityUserRepository } from '@novu/dal';
import { CommunityOrganizationRepository } from '@novu/dal';

@Module({
imports: [SharedModule, SubscribersModule, AuthModule, IntegrationModule],
providers: [...USE_CASES, CommunityOrganizationRepository, CommunityUserRepository],
providers: [...USE_CASES, CommunityOrganizationRepository],
exports: [...USE_CASES],
controllers: [WidgetsController],
})
Expand Down

0 comments on commit 1955864

Please sign in to comment.