Skip to content

Commit

Permalink
Remove duplicate UpsertSubscriptionsDto entities and builders (#2212)
Browse files Browse the repository at this point in the history
Removes duplicate entities and centralises the associated schema and builder for `UpsertSubscriptionsDto`: business logic on the domain layer and implemented entity on the route:

- Move schema and inferred type from datasource to domain layer
- Have route entity implement domain type
- Update imports accordingly
  • Loading branch information
iamacook authored Dec 20, 2024
1 parent 8456649 commit 6fa5b86
Show file tree
Hide file tree
Showing 17 changed files with 45 additions and 151 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { UpsertSubscriptionsDto } from '@/routes/notifications/v1/entities/upsert-subscriptions.dto.entity';
import type { UpsertSubscriptionsDto } from '@/domain/notifications/v2/entities/upsert-subscriptions.dto.entity';
import type { NotificationType } from '@/domain/notifications/v2/entities/notification-type.entity';
import type { UUID } from 'crypto';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { DeviceType } from '@/domain/notifications/v2/entities/device-type.entity';
import { NotificationType } from '@/domain/notifications/v2/entities/notification-type.entity';
import { upsertSubscriptionsDtoBuilder } from '@/routes/notifications/v1/entities/__tests__/upsert-subscriptions.dto.entity.builder';
import { UpsertSubscriptionsDtoSchema } from '@/routes/notifications/v1/entities/upsert-subscriptions.dto.entity';
import { upsertSubscriptionsDtoBuilder } from '@/routes/notifications/v2/entities/__tests__/upsert-subscriptions.dto.builder';
import { UpsertSubscriptionsDtoSchema } from '@/domain/notifications/v2/entities/upsert-subscriptions.dto.entity';
import { faker } from '@faker-js/faker';
import type { UUID } from 'crypto';
import { getAddress } from 'viem';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
import type { DeviceType } from '@/domain/notifications/v2/entities/device-type.entity';
import type { NotificationType } from '@/domain/notifications/v2/entities/notification-type.entity';
import type { UUID } from 'crypto';

export type UpsertSubscriptionsDto = {
cloudMessagingToken: string;
safes: Array<{
chainId: string;
address: `0x${string}`;
notificationTypes: Array<NotificationType>;
}>;
deviceType: DeviceType;
deviceUuid?: UUID;
};
import { DeviceType } from '@/domain/notifications/v2/entities/device-type.entity';
import { NotificationType } from '@/domain/notifications/v2/entities/notification-type.entity';
import { AddressSchema } from '@/validation/entities/schemas/address.schema';
import { UuidSchema } from '@/validation/entities/schemas/uuid.schema';
import { z } from 'zod';

const UpsertSubscriptionsDtoSafesSchema = z.object({
chainId: z.string(),
address: AddressSchema,
notificationTypes: z.array(z.nativeEnum(NotificationType)),
});

export const UpsertSubscriptionsDtoSchema = z.object({
cloudMessagingToken: z.string(),
safes: z.array(UpsertSubscriptionsDtoSafesSchema),
deviceType: z.nativeEnum(DeviceType),
deviceUuid: UuidSchema.nullish().default(null),
});

export type UpsertSubscriptionsSafesDto = z.infer<
typeof UpsertSubscriptionsDtoSafesSchema
>;

export type UpsertSubscriptionsDto = z.infer<
typeof UpsertSubscriptionsDtoSchema
>;
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { IPushNotificationsApi } from '@/domain/interfaces/push-notificatio
import { NotificationType } from '@/datasources/notifications/entities/notification-type.entity.db';
import type { INotificationsRepositoryV2 } from '@/domain/notifications/v2/notifications.repository.interface';
import { NotificationSubscription } from '@/datasources/notifications/entities/notification-subscription.entity.db';
import { upsertSubscriptionsDtoBuilder } from '@/datasources/notifications/__tests__/upsert-subscriptions.dto.entity.builder';
import { upsertSubscriptionsDtoBuilder } from '@/routes/notifications/v2/entities/__tests__/upsert-subscriptions.dto.builder';
import { authPayloadDtoBuilder } from '@/domain/auth/entities/__tests__/auth-payload-dto.entity.builder';
import { NotificationDevice } from '@/datasources/notifications/entities/notification-devices.entity.db';
import { PostgresDatabaseService } from '@/datasources/db/v2/postgres-database.service';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { UpsertSubscriptionsDto } from '@/routes/notifications/v1/entities/upsert-subscriptions.dto.entity';
import type { UpsertSubscriptionsDto } from '@/domain/notifications/v2/entities/upsert-subscriptions.dto.entity';
import type { FirebaseNotification } from '@/datasources/push-notifications-api/entities/firebase-notification.entity';
import type { UUID } from 'crypto';
import type { AuthPayload } from '@/domain/auth/entities/auth-payload.entity';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { INotificationsRepositoryV2 } from '@/domain/notifications/v2/notif
import { notificationTypeBuilder } from '@/datasources/notifications/entities/__tests__/notification-type.entity.db.builder';
import { notificationSubscriptionBuilder } from '@/datasources/notifications/entities/__tests__/notification-subscription.entity.db.builder';
import { NotificationSubscription } from '@/datasources/notifications/entities/notification-subscription.entity.db';
import { upsertSubscriptionsDtoBuilder } from '@/datasources/notifications/__tests__/upsert-subscriptions.dto.entity.builder';
import { upsertSubscriptionsDtoBuilder } from '@/routes/notifications/v2/entities/__tests__/upsert-subscriptions.dto.builder';
import { authPayloadDtoBuilder } from '@/domain/auth/entities/__tests__/auth-payload-dto.entity.builder';
import { NotificationDevice } from '@/datasources/notifications/entities/notification-devices.entity.db';
import { mockEntityManager } from '@/datasources/db/v2/__tests__/entity-manager.mock';
Expand Down
2 changes: 1 addition & 1 deletion src/domain/notifications/v2/notifications.repository.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { UpsertSubscriptionsDto } from '@/routes/notifications/v1/entities/upsert-subscriptions.dto.entity';
import { UpsertSubscriptionsDto } from '@/domain/notifications/v2/entities/upsert-subscriptions.dto.entity';
import { FirebaseNotification } from '@/datasources/push-notifications-api/entities/firebase-notification.entity';
import { IPushNotificationsApi } from '@/domain/interfaces/push-notifications-api.interface';
import { UUID } from 'crypto';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { UpsertSubscriptionsDto } from '@/datasources/notifications/entities/upsert-subscriptions.dto.entity';
import type { UpsertSubscriptionsDto } from '@/domain/notifications/v2/entities/upsert-subscriptions.dto.entity';
import { AuthPayload } from '@/domain/auth/entities/auth-payload.entity';
import { NotificationType } from '@/domain/notifications/v2/entities/notification.entity';
import type { RegisterDeviceDto } from '@/routes/notifications/v1/entities/register-device.dto.entity';
Expand Down Expand Up @@ -28,7 +28,7 @@ export const createV2RegisterDtoBuilder = async (
upsertSubscriptionsDto: {
cloudMessagingToken: args.cloudMessagingToken,
deviceType: args.deviceType,
deviceUuid: (args.uuid as UUID | undefined) || undefined,
deviceUuid: (args.uuid as UUID | undefined) ?? null,
safes: [],
signature: safeV1Registration.signatures[0] as `0x${string}`,
},
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,27 +1,14 @@
import { DeviceType } from '@/domain/notifications/v2/entities/device-type.entity';
import { NotificationType } from '@/domain/notifications/v2/entities/notification-type.entity';
import { AddressSchema } from '@/validation/entities/schemas/address.schema';
import { NumericStringSchema } from '@/validation/entities/schemas/numeric-string.schema';
import { UuidSchema } from '@/validation/entities/schemas/uuid.schema';
import {
UpsertSubscriptionsSafesDto as DomainUpsertSubscriptionsSafesDto,
UpsertSubscriptionsDto as DomainUpsertSubscriptionsDto,
} from '@/domain/notifications/v2/entities/upsert-subscriptions.dto.entity';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import type { UUID } from 'crypto';
import { z } from 'zod';

export const UpsertSubscriptionsDtoSafeSchema = z.object({
chainId: NumericStringSchema,
address: AddressSchema,
notificationTypes: z.array(z.nativeEnum(NotificationType)),
});

export const UpsertSubscriptionsDtoSchema = z.object({
cloudMessagingToken: z.string(),
safes: z.array(UpsertSubscriptionsDtoSafeSchema),
deviceType: z.nativeEnum(DeviceType),
deviceUuid: UuidSchema.nullish().default(null),
});

export class UpsertSubscriptionsSafesDto
implements z.infer<typeof UpsertSubscriptionsDtoSafeSchema>
implements DomainUpsertSubscriptionsSafesDto
{
@ApiProperty()
chainId!: string;
Expand All @@ -37,9 +24,7 @@ export class UpsertSubscriptionsSafesDto
notificationTypes!: Array<NotificationType>;
}

export class UpsertSubscriptionsDto
implements z.infer<typeof UpsertSubscriptionsDtoSchema>
{
export class UpsertSubscriptionsDto implements DomainUpsertSubscriptionsDto {
@ApiProperty()
cloudMessagingToken!: string;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { pageBuilder } from '@/domain/entities/__tests__/page.builder';
import { safeBuilder } from '@/domain/safe/entities/__tests__/safe.builder';
import { TestLoggingModule } from '@/logging/__tests__/test.logging.module';
import { RequestScopedLoggingModule } from '@/logging/logging.module';
import { upsertSubscriptionsDtoBuilder } from '@/routes/notifications/v1/entities/__tests__/upsert-subscriptions.dto.entity.builder';
import { upsertSubscriptionsDtoBuilder } from '@/routes/notifications/v2/entities/__tests__/upsert-subscriptions.dto.builder';
import type { Chain } from '@/routes/chains/entities/chain.entity';
import { faker } from '@faker-js/faker';
import type { INestApplication } from '@nestjs/common';
Expand Down
6 changes: 2 additions & 4 deletions src/routes/notifications/v2/notifications.controller.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { AuthPayload } from '@/domain/auth/entities/auth-payload.entity';
import {
UpsertSubscriptionsDto,
UpsertSubscriptionsDtoSchema,
} from '@/routes/notifications/v2/entities/upsert-subscriptions.dto.entity';
import { UpsertSubscriptionsDto } from '@/routes/notifications/v2/entities/upsert-subscriptions.dto.entity';
import { UpsertSubscriptionsDtoSchema } from '@/domain/notifications/v2/entities/upsert-subscriptions.dto.entity';
import { NotificationsServiceV2 } from '@/routes/notifications/v2/notifications.service';
import { Auth } from '@/routes/auth/decorators/auth.decorator';
import { AuthGuard } from '@/routes/auth/guards/auth.guard';
Expand Down
2 changes: 1 addition & 1 deletion src/routes/notifications/v2/notifications.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AuthPayload } from '@/domain/auth/entities/auth-payload.entity';
import { UpsertSubscriptionsDto } from '@/routes/notifications/v1/entities/upsert-subscriptions.dto.entity';
import { UpsertSubscriptionsDto } from '@/domain/notifications/v2/entities/upsert-subscriptions.dto.entity';
import { Inject, Injectable } from '@nestjs/common';
import { UUID } from 'crypto';
import { NotificationType } from '@/datasources/notifications/entities/notification-type.entity.db';
Expand Down

0 comments on commit 6fa5b86

Please sign in to comment.