Skip to content

Commit

Permalink
fix(api, shared, application-generic): Replace branded types with `st…
Browse files Browse the repository at this point in the history
…ring` type (#6354)
  • Loading branch information
rifont authored Aug 20, 2024
1 parent 88b6f41 commit 20fc0f0
Show file tree
Hide file tree
Showing 17 changed files with 88 additions and 139 deletions.
3 changes: 1 addition & 2 deletions apps/api/src/app/events/dtos/trigger-event-request.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { Type } from 'class-transformer';
import { ApiExtraModels, ApiProperty, ApiPropertyOptional, getSchemaPath } from '@nestjs/swagger';
import {
ControlsDto,
TopicKey,
TriggerRecipients,
TriggerRecipientsTypeEnum,
TriggerRecipientSubscriber,
Expand All @@ -27,7 +26,7 @@ export class TenantPayloadDto extends UpdateTenantRequestDto {}

export class TopicPayloadDto {
@ApiProperty()
topicKey: TopicKey;
topicKey: string;

@ApiProperty({ example: 'Topic', enum: TriggerRecipientsTypeEnum })
type: TriggerRecipientsTypeEnum;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { IsArray, IsOptional, IsString } from 'class-validator';

import type { NotificationFilter } from '../utils/types';

export class UpdateAllNotificationsRequestDto implements Pick<NotificationFilter, 'tags'> {
export class UpdateAllNotificationsRequestDto {
@IsOptional()
@IsArray()
@IsString({ each: true })
Expand Down
18 changes: 9 additions & 9 deletions apps/api/src/app/layouts/dtos/create-layout.dto.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsBoolean, IsDefined, IsOptional, IsString } from 'class-validator';

import { LayoutDto } from './layout.dto';
import { LayoutVariables } from '../types';

import { LayoutDescription, LayoutId, LayoutIdentifier, LayoutName, LayoutVariables } from '../types';

export class CreateLayoutResponseDto implements Pick<LayoutDto, '_id'> {
@ApiProperty()
_id: LayoutId;
export class CreateLayoutResponseDto {
@ApiProperty({
description: 'The unique identifier for the Layout created.',
})
_id: string;
}

export class CreateLayoutRequestDto {
Expand All @@ -16,21 +16,21 @@ export class CreateLayoutRequestDto {
})
@IsString()
@IsDefined()
name: LayoutName;
name: string;

@ApiProperty({
description: 'User defined custom key that will be a unique identifier for the Layout created.',
})
@IsString()
@IsDefined()
identifier: LayoutIdentifier;
identifier: string;

@ApiPropertyOptional({
description: 'User description of the layout',
})
@IsString()
@IsOptional()
description: LayoutDescription;
description: string;

@ApiProperty({
description: 'User defined content for the layout.',
Expand Down
26 changes: 8 additions & 18 deletions apps/api/src/app/layouts/dtos/layout.dto.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,27 @@
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import {
ChannelTypeEnum,
EnvironmentId,
ITemplateVariable,
OrganizationId,
LayoutDescription,
LayoutId,
LayoutName,
LayoutIdentifier,
UserId,
} from '../types';
import { ChannelTypeEnum, ITemplateVariable } from '../types';

export class LayoutDto {
@ApiPropertyOptional()
_id?: LayoutId;
_id?: string;

@ApiProperty()
_organizationId: OrganizationId;
_organizationId: string;

@ApiProperty()
_environmentId: EnvironmentId;
_environmentId: string;

@ApiProperty()
_creatorId: UserId;
_creatorId: string;

@ApiProperty()
name: LayoutName;
name: string;

@ApiProperty()
identifier: LayoutIdentifier;
identifier: string;

@ApiProperty()
description?: LayoutDescription;
description?: string;

@ApiProperty({
enum: ChannelTypeEnum,
Expand Down
8 changes: 4 additions & 4 deletions apps/api/src/app/layouts/dtos/update-layout.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { IsBoolean, IsOptional, IsString } from 'class-validator';

import { LayoutDto } from './layout.dto';

import { LayoutDescription, LayoutIdentifier, LayoutName, LayoutVariables } from '../types';
import { LayoutVariables } from '../types';

export class UpdateLayoutResponseDto extends LayoutDto {}

Expand All @@ -13,21 +13,21 @@ export class UpdateLayoutRequestDto {
})
@IsString()
@IsOptional()
name?: LayoutName;
name?: string;

@ApiProperty({
description: 'User defined custom key that will be a unique identifier for the Layout updated.',
})
@IsString()
@IsOptional()
identifier: LayoutIdentifier;
identifier: string;

@ApiPropertyOptional({
description: 'User defined description of the layout',
})
@IsString()
@IsOptional()
description?: LayoutDescription;
description?: string;

@ApiPropertyOptional({
description: 'User defined content for the layout.',
Expand Down
6 changes: 3 additions & 3 deletions apps/api/src/app/tenant/dtos/create-tenant-response.dto.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { ApiProperty } from '@nestjs/swagger';

import { EnvironmentId, TenantCustomData } from '@novu/shared';
import { TenantCustomData } from '@novu/shared';
import { TenantId } from '@novu/dal';

export class CreateTenantResponseDto {
@ApiProperty()
_id: TenantId;
_id: string;

@ApiProperty()
identifier: string;
Expand All @@ -17,7 +17,7 @@ export class CreateTenantResponseDto {
data?: TenantCustomData;

@ApiProperty()
_environmentId: EnvironmentId;
_environmentId: string;

@ApiProperty()
createdAt: string;
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/app/topics/dtos/add-subscribers.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ export class AddSubscribersRequestDto {
})
@IsArray()
@IsDefined()
subscribers: ExternalSubscriberId[];
subscribers: string[];
}
19 changes: 13 additions & 6 deletions apps/api/src/app/topics/dtos/create-topic.dto.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsDefined, IsString } from 'class-validator';

import { TopicDto } from './topic.dto';

import { TopicKey, TopicName } from '../types';
export class CreateTopicResponseDto {
@ApiPropertyOptional({
description: 'The unique identifier for the Topic created.',
})
_id: string;

export class CreateTopicResponseDto implements Pick<TopicDto, '_id' & 'key'> {}
@ApiProperty({
description:
'User defined custom key and provided by the user that will be an unique identifier for the Topic created.',
})
key: string;
}

export class CreateTopicRequestDto {
@ApiProperty({
Expand All @@ -14,12 +21,12 @@ export class CreateTopicRequestDto {
})
@IsString()
@IsDefined()
key: TopicKey;
key: string;

@ApiProperty({
description: 'User defined custom name and provided by the user that will name the Topic created.',
})
@IsString()
@IsDefined()
name: TopicName;
name: string;
}
4 changes: 1 addition & 3 deletions apps/api/src/app/topics/dtos/filter-topics.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import { Transform } from 'class-transformer';

import { TopicDto } from './topic.dto';

import { TopicKey } from '../types';

export class FilterTopicsRequestDto {
@Transform(({ value }) => Number(value))
@IsOptional()
Expand All @@ -24,7 +22,7 @@ export class FilterTopicsRequestDto {
@IsString()
@IsOptional()
@ApiPropertyOptional({ type: String })
public key?: TopicKey;
public key?: string;
}

export class FilterTopicsResponseDto {
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/app/topics/dtos/remove-subscribers.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ export class RemoveSubscribersRequestDto {
})
@IsArray()
@IsDefined()
subscribers: ExternalSubscriberId[];
subscribers: string[];
}
4 changes: 1 addition & 3 deletions apps/api/src/app/topics/dtos/rename-topic.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { IsDefined, IsString } from 'class-validator';

import { TopicDto } from './topic.dto';

import { TopicName } from '../types';

export class RenameTopicResponseDto extends TopicDto {}

export class RenameTopicRequestDto {
Expand All @@ -13,5 +11,5 @@ export class RenameTopicRequestDto {
})
@IsString()
@IsDefined()
name: TopicName;
name: string;
}
14 changes: 6 additions & 8 deletions apps/api/src/app/topics/dtos/topic-subscriber.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,22 @@ import { ApiProperty } from '@nestjs/swagger';

import { ITopicSubscriber } from '@novu/shared';

import { EnvironmentId, ExternalSubscriberId, OrganizationId, SubscriberId, TopicId, TopicKey } from '../types';

export class TopicSubscriberDto implements ITopicSubscriber {
@ApiProperty()
_organizationId: OrganizationId;
_organizationId: string;

@ApiProperty()
_environmentId: EnvironmentId;
_environmentId: string;

@ApiProperty()
_subscriberId: SubscriberId;
_subscriberId: string;

@ApiProperty()
_topicId: TopicId;
_topicId: string;

@ApiProperty()
topicKey: TopicKey;
topicKey: string;

@ApiProperty()
externalSubscriberId: ExternalSubscriberId;
externalSubscriberId: string;
}
13 changes: 6 additions & 7 deletions apps/api/src/app/topics/dtos/topic.dto.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { EnvironmentId, ExternalSubscriberId, OrganizationId, TopicId, TopicKey, TopicName } from '../types';

export class TopicDto {
@ApiPropertyOptional()
_id: TopicId;
_id: string;

@ApiProperty()
_organizationId: OrganizationId;
_organizationId: string;

@ApiProperty()
_environmentId: EnvironmentId;
_environmentId: string;

@ApiProperty()
key: TopicKey;
key: string;

@ApiProperty()
name: TopicName;
name: string;

@ApiProperty()
subscribers: ExternalSubscriberId[];
subscribers: string[];
}
26 changes: 8 additions & 18 deletions libs/application-generic/src/usecases/get-layout/layout.dto.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,27 @@
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import {
EnvironmentId,
OrganizationId,
ChannelTypeEnum,
ITemplateVariable,
LayoutDescription,
LayoutId,
LayoutName,
LayoutIdentifier,
UserId,
} from '@novu/dal';
import { ChannelTypeEnum, ITemplateVariable } from '@novu/dal';

export class LayoutDto {
@ApiPropertyOptional()
_id?: LayoutId;
_id?: string;

@ApiProperty()
_organizationId: OrganizationId;
_organizationId: string;

@ApiProperty()
_environmentId: EnvironmentId;
_environmentId: string;

@ApiProperty()
_creatorId: UserId;
_creatorId: string;

@ApiProperty()
name: LayoutName;
name: string;

@ApiProperty()
identifier: LayoutIdentifier;
identifier: string;

@ApiProperty()
description?: LayoutDescription;
description?: string;

@ApiProperty()
channel: ChannelTypeEnum;
Expand Down
Loading

0 comments on commit 20fc0f0

Please sign in to comment.