diff --git a/src/datasources/notifications/__tests__/upsert-subscriptions.dto.entity.builder.ts b/src/datasources/notifications/__tests__/upsert-subscriptions.dto.entity.builder.ts deleted file mode 100644 index 1dc50ae2a6..0000000000 --- a/src/datasources/notifications/__tests__/upsert-subscriptions.dto.entity.builder.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { faker } from '@faker-js/faker'; -import type { IBuilder } from '@/__tests__/builder'; -import { Builder } from '@/__tests__/builder'; -import { getAddress } from 'viem'; -import type { UpsertSubscriptionsDto } from '@/routes/notifications/v1/entities/upsert-subscriptions.dto.entity'; -import { DeviceType } from '@/domain/notifications/v2/entities/device-type.entity'; -import { NotificationType } from '@/domain/notifications/v2/entities/notification-type.entity'; -import type { UUID } from 'crypto'; - -export function upsertSubscriptionsDtoBuilder(): IBuilder { - return new Builder() - .with('cloudMessagingToken', faker.string.alphanumeric({ length: 10 })) - .with('deviceType', faker.helpers.arrayElement(Object.values(DeviceType))) - .with('deviceUuid', faker.string.uuid() as UUID) - .with( - 'safes', - Array.from( - { - length: faker.number.int({ min: 1, max: 5 }), - }, - () => { - return { - chainId: faker.string.numeric(), - address: getAddress(faker.finance.ethereumAddress()), - notificationTypes: faker.helpers.arrayElements( - Object.values(NotificationType), - ), - }; - }, - ), - ); -} diff --git a/src/datasources/notifications/entities/upsert-subscriptions.dto.entity.ts b/src/datasources/notifications/entities/upsert-subscriptions.dto.entity.ts deleted file mode 100644 index 1b9fde48a2..0000000000 --- a/src/datasources/notifications/entities/upsert-subscriptions.dto.entity.ts +++ /dev/null @@ -1,15 +0,0 @@ -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'; - -// TODO: Move to domain -export type UpsertSubscriptionsDto = { - cloudMessagingToken: string; - safes: Array<{ - chainId: string; - address: `0x${string}`; - notificationTypes: Array; - }>; - deviceType: DeviceType; - deviceUuid?: UUID; -}; diff --git a/src/domain/interfaces/notifications.datasource.interface.ts b/src/domain/interfaces/notifications.datasource.interface.ts index ed8b03e591..da26d84d7b 100644 --- a/src/domain/interfaces/notifications.datasource.interface.ts +++ b/src/domain/interfaces/notifications.datasource.interface.ts @@ -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'; diff --git a/src/routes/notifications/v1/entities/__tests__/upsert-subscriptions-dto.entity.spec.ts b/src/domain/notifications/v2/entities/__tests__/upsert-subscriptions-dto.entity.spec.ts similarity index 96% rename from src/routes/notifications/v1/entities/__tests__/upsert-subscriptions-dto.entity.spec.ts rename to src/domain/notifications/v2/entities/__tests__/upsert-subscriptions-dto.entity.spec.ts index ea8aa0a52c..89dc14860e 100644 --- a/src/routes/notifications/v1/entities/__tests__/upsert-subscriptions-dto.entity.spec.ts +++ b/src/domain/notifications/v2/entities/__tests__/upsert-subscriptions-dto.entity.spec.ts @@ -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'; diff --git a/src/domain/notifications/v2/entities/upsert-subscriptions.dto.entity.ts b/src/domain/notifications/v2/entities/upsert-subscriptions.dto.entity.ts index 723ac466d1..f7cd9e10db 100644 --- a/src/domain/notifications/v2/entities/upsert-subscriptions.dto.entity.ts +++ b/src/domain/notifications/v2/entities/upsert-subscriptions.dto.entity.ts @@ -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; - }>; - 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 +>; diff --git a/src/domain/notifications/v2/notifications.repository.integration.spec.ts b/src/domain/notifications/v2/notifications.repository.integration.spec.ts index 931e2b95d5..a3776338c1 100644 --- a/src/domain/notifications/v2/notifications.repository.integration.spec.ts +++ b/src/domain/notifications/v2/notifications.repository.integration.spec.ts @@ -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'; diff --git a/src/domain/notifications/v2/notifications.repository.interface.ts b/src/domain/notifications/v2/notifications.repository.interface.ts index ed74a11644..f652c07cc6 100644 --- a/src/domain/notifications/v2/notifications.repository.interface.ts +++ b/src/domain/notifications/v2/notifications.repository.interface.ts @@ -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'; diff --git a/src/domain/notifications/v2/notifications.repository.spec.ts b/src/domain/notifications/v2/notifications.repository.spec.ts index e379e71d6c..81a1153f05 100644 --- a/src/domain/notifications/v2/notifications.repository.spec.ts +++ b/src/domain/notifications/v2/notifications.repository.spec.ts @@ -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'; diff --git a/src/domain/notifications/v2/notifications.repository.ts b/src/domain/notifications/v2/notifications.repository.ts index 4da9392aa9..e86e6913fb 100644 --- a/src/domain/notifications/v2/notifications.repository.ts +++ b/src/domain/notifications/v2/notifications.repository.ts @@ -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'; diff --git a/src/routes/notifications/v1/entities/__tests__/create-registration-v2.dto.builder.ts b/src/routes/notifications/v1/entities/__tests__/create-registration-v2.dto.builder.ts index 0bee171fe6..41c3a747f1 100644 --- a/src/routes/notifications/v1/entities/__tests__/create-registration-v2.dto.builder.ts +++ b/src/routes/notifications/v1/entities/__tests__/create-registration-v2.dto.builder.ts @@ -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'; @@ -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}`, }, diff --git a/src/routes/notifications/v1/entities/__tests__/upsert-subscriptions.dto.entity.builder.ts b/src/routes/notifications/v1/entities/__tests__/upsert-subscriptions.dto.entity.builder.ts deleted file mode 100644 index 8f0e6ab832..0000000000 --- a/src/routes/notifications/v1/entities/__tests__/upsert-subscriptions.dto.entity.builder.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { faker } from '@faker-js/faker'; -import type { IBuilder } from '@/__tests__/builder'; -import { Builder } from '@/__tests__/builder'; -import { getAddress } from 'viem'; -import type { UpsertSubscriptionsDto } from '@/routes/notifications/v1/entities/upsert-subscriptions.dto.entity'; -import { DeviceType } from '@/domain/notifications/v2/entities/device-type.entity'; -import type { UUID } from 'crypto'; -import { NotificationType } from '@/domain/notifications/v2/entities/notification-type.entity'; - -export function upsertSubscriptionsDtoBuilder(): IBuilder { - return new Builder() - .with('cloudMessagingToken', faker.string.alphanumeric({ length: 10 })) - .with('deviceType', faker.helpers.arrayElement(Object.values(DeviceType))) - .with('deviceUuid', faker.string.uuid() as UUID) - .with( - 'safes', - Array.from( - { - length: faker.number.int({ min: 1, max: 5 }), - }, - () => { - return { - chainId: faker.string.numeric(), - address: getAddress(faker.finance.ethereumAddress()), - notificationTypes: faker.helpers.arrayElements( - Object.values(NotificationType), - ), - }; - }, - ), - ); -} diff --git a/src/routes/notifications/v1/entities/upsert-subscriptions.dto.entity.ts b/src/routes/notifications/v1/entities/upsert-subscriptions.dto.entity.ts deleted file mode 100644 index f1a6d6bacd..0000000000 --- a/src/routes/notifications/v1/entities/upsert-subscriptions.dto.entity.ts +++ /dev/null @@ -1,22 +0,0 @@ -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'; - -export const UpsertSubscriptionsDtoSchema = z.object({ - cloudMessagingToken: z.string(), - safes: z.array( - z.object({ - chainId: z.string(), - address: AddressSchema, - notificationTypes: z.array(z.nativeEnum(NotificationType)), - }), - ), - deviceType: z.nativeEnum(DeviceType), - deviceUuid: UuidSchema.nullish().default(null), -}); - -export type UpsertSubscriptionsDto = z.infer< - typeof UpsertSubscriptionsDtoSchema ->; diff --git a/src/domain/notifications/v2/entities/__tests__/upsert-subscriptions.dto.entity.builder.ts b/src/routes/notifications/v2/entities/__tests__/upsert-subscriptions.dto.builder.ts similarity index 100% rename from src/domain/notifications/v2/entities/__tests__/upsert-subscriptions.dto.entity.builder.ts rename to src/routes/notifications/v2/entities/__tests__/upsert-subscriptions.dto.builder.ts diff --git a/src/routes/notifications/v2/entities/upsert-subscriptions.dto.entity.ts b/src/routes/notifications/v2/entities/upsert-subscriptions.dto.entity.ts index 04971847d8..9fc81b2d0e 100644 --- a/src/routes/notifications/v2/entities/upsert-subscriptions.dto.entity.ts +++ b/src/routes/notifications/v2/entities/upsert-subscriptions.dto.entity.ts @@ -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 + implements DomainUpsertSubscriptionsSafesDto { @ApiProperty() chainId!: string; @@ -37,9 +24,7 @@ export class UpsertSubscriptionsSafesDto notificationTypes!: Array; } -export class UpsertSubscriptionsDto - implements z.infer -{ +export class UpsertSubscriptionsDto implements DomainUpsertSubscriptionsDto { @ApiProperty() cloudMessagingToken!: string; diff --git a/src/routes/notifications/v2/notifications.controller.spec.ts b/src/routes/notifications/v2/notifications.controller.spec.ts index 158ffb2a66..77e49d5e69 100644 --- a/src/routes/notifications/v2/notifications.controller.spec.ts +++ b/src/routes/notifications/v2/notifications.controller.spec.ts @@ -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'; diff --git a/src/routes/notifications/v2/notifications.controller.ts b/src/routes/notifications/v2/notifications.controller.ts index fd90fa0590..1012595185 100644 --- a/src/routes/notifications/v2/notifications.controller.ts +++ b/src/routes/notifications/v2/notifications.controller.ts @@ -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'; diff --git a/src/routes/notifications/v2/notifications.service.ts b/src/routes/notifications/v2/notifications.service.ts index 82fe8a77d3..3449b48f78 100644 --- a/src/routes/notifications/v2/notifications.service.ts +++ b/src/routes/notifications/v2/notifications.service.ts @@ -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';