Skip to content

Commit

Permalink
feat: add messages new api res (#5285)
Browse files Browse the repository at this point in the history
* feat: add messages new api

* fix: spell

* fix: controller
  • Loading branch information
scopsy committed Mar 9, 2024
1 parent 06bc9e2 commit d198dd7
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
14 changes: 13 additions & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,19 @@
"spyon",
"restapi",
"ringcentral",
"reshard"
"reshard",
"userid",
"endgroup",
"aliyun",
"azcopy",
"cpack",
"pulumi",
"hostedtoolcache",
"pyroscope",
"HEAY",
"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 @@ -9,4 +9,5 @@ export enum FeatureFlagsKeysEnum {
IS_API_EXECUTION_LOG_QUEUE_ENABLED = 'IS_API_EXECUTION_LOG_QUEUE_ENABLED',
IS_BILLING_ENABLED = 'IS_BILLING_ENABLED',
IS_IMPROVED_ONBOARDING_ENABLED = 'IS_IMPROVED_ONBOARDING_ENABLED',
IS_NEW_MESSAGES_API_RESPONSE_ENABLED = 'IS_NEW_MESSAGES_API_RESPONSE_ENABLED',
}

0 comments on commit d198dd7

Please sign in to comment.