diff --git a/src/datasources/accounts/accounts.datasource.ts b/src/datasources/accounts/accounts.datasource.ts index 081bcf3adc..da7729550f 100644 --- a/src/datasources/accounts/accounts.datasource.ts +++ b/src/datasources/accounts/accounts.datasource.ts @@ -17,7 +17,7 @@ import { IAccountsDatasource } from '@/domain/interfaces/accounts.datasource.int import { IEncryptionApiManager } from '@/domain/interfaces/encryption-api.manager.interface'; import { ILoggingService, LoggingService } from '@/logging/logging.interface'; import { asError } from '@/logging/utils'; -import { IpSchema } from '@/validation/entities/schemas/ip.schema'; +import { z } from 'zod'; import { Inject, Injectable, @@ -247,8 +247,8 @@ export class AccountsDatasource implements IAccountsDatasource, OnModuleInit { * @param clientIp - client IP address. */ private async checkCreationRateLimit(clientIp: string): Promise { - const { success: isValidIp } = IpSchema.safeParse(clientIp); - if (!clientIp || !isValidIp) { + const { success: isValidIp } = z.string().ip().safeParse(clientIp); + if (!isValidIp) { this.loggingService.warn( `Invalid client IP while creating account: ${clientIp}`, ); diff --git a/src/validation/entities/schemas/__tests__/ip.schema.spec.ts b/src/validation/entities/schemas/__tests__/ip.schema.spec.ts deleted file mode 100644 index cf04d22943..0000000000 --- a/src/validation/entities/schemas/__tests__/ip.schema.spec.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { IpSchema } from '@/validation/entities/schemas/ip.schema'; - -describe('IpSchema', () => { - it('should validate a valid IP address', () => { - const value = '192.168.0.1'; - const result = IpSchema.safeParse(value); - - expect(result.success && result.data).toBe(value); - }); - - it('should not validate a non-IP address', () => { - const value = 'not-an-ip'; - const result = IpSchema.safeParse(value); - - expect(result.success).toBe(false); - }); - - it('should not validate an invalid IP address', () => { - const value = '192.168.0.256'; - const result = IpSchema.safeParse(value); - - expect(result.success).toBe(false); - }); -}); diff --git a/src/validation/entities/schemas/ip.schema.ts b/src/validation/entities/schemas/ip.schema.ts deleted file mode 100644 index 4fc187e798..0000000000 --- a/src/validation/entities/schemas/ip.schema.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { z } from 'zod'; - -export const IpSchema = z.string().ip();