Skip to content
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

feat: add messages new api res #5285

Merged
merged 3 commits into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,8 @@
"pyroscope",
"HEAY",
"Pyroscope",
"PYROSCOPE"
"PYROSCOPE",
"usecases"
],
"flagWords": [],
"patterns": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { BadRequestException, Injectable } from '@nestjs/common';
import { MessageEntity, MessageRepository, SubscriberEntity } from '@novu/dal';
import { ActorTypeEnum } from '@novu/shared';
import { ActorTypeEnum, FeatureFlagsKeysEnum } from '@novu/shared';

import { GetMessagesCommand } from './get-messages.command';
import { GetSubscriber, GetSubscriberCommand } from '../../../subscribers/usecases/get-subscriber';
import { GetFeatureFlag, GetFeatureFlagCommand } from '@novu/application-generic';

@Injectable()
export class GetMessages {
constructor(private messageRepository: MessageRepository, private getSubscriberUseCase: GetSubscriber) {}
constructor(
private messageRepository: MessageRepository,
private getSubscriberUseCase: GetSubscriber,
private getFeatureFlag: GetFeatureFlag
) {}

async execute(command: GetMessagesCommand) {
const LIMIT = command.limit;
Expand Down Expand Up @@ -53,6 +58,24 @@ export class GetMessages {
}
}

const isEnabled = await this.getFeatureFlag.execute(
GetFeatureFlagCommand.create({
key: FeatureFlagsKeysEnum.IS_NEW_MESSAGES_API_RESPONSE_ENABLED,
organizationId: command.organizationId,
userId: 'api',
environmentId: command.environmentId,
})
);

if (isEnabled) {
return {
hasMore: data?.length === command.limit,
page: command.page,
pageSize: LIMIT,
data,
};
}

const totalCount = await this.messageRepository.count(query);

const hasMore = this.getHasMore(command.page, LIMIT, data.length, totalCount);
Expand Down
4 changes: 2 additions & 2 deletions apps/api/src/app/widgets/dtos/message-response.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ export class MessageResponseDto {
}

export class MessagesResponseDto {
@ApiProperty()
totalCount: number;
@ApiPropertyOptional()
totalCount?: number;

@ApiProperty()
hasMore: boolean;
Expand Down
1 change: 1 addition & 0 deletions libs/shared/src/types/feature-flags/feature-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ export enum FeatureFlagsKeysEnum {
IS_BILLING_ENABLED = 'IS_BILLING_ENABLED',
IS_ECHO_ENABLED = 'IS_ECHO_ENABLED',
IS_IMPROVED_ONBOARDING_ENABLED = 'IS_IMPROVED_ONBOARDING_ENABLED',
IS_NEW_MESSAGES_API_RESPONSE_ENABLED = 'IS_NEW_MESSAGES_API_RESPONSE_ENABLED',
}
Loading