code quality
Some checks failed
CI / lint-typecheck (pull_request) Failing after 12s
CI / tests (pull_request) Has been skipped
CI / contract-tests (pull_request) Has been skipped
CI / e2e-tests (pull_request) Has been skipped
CI / comment-pr (pull_request) Has been skipped
CI / commit-types (pull_request) Has been skipped
Some checks failed
CI / lint-typecheck (pull_request) Failing after 12s
CI / tests (pull_request) Has been skipped
CI / contract-tests (pull_request) Has been skipped
CI / e2e-tests (pull_request) Has been skipped
CI / comment-pr (pull_request) Has been skipped
CI / commit-types (pull_request) Has been skipped
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { Notification } from '@core/notifications/domain/entities/Notification';
|
||||
import { Notification, type NotificationStatus, type NotificationUrgency } from '@core/notifications/domain/entities/Notification';
|
||||
import type { NotificationChannel, NotificationType } from '@core/notifications/domain/types/NotificationTypes';
|
||||
import { NotificationOrmEntity } from '../entities/NotificationOrmEntity';
|
||||
import { TypeOrmPersistenceSchemaError } from '../errors/TypeOrmPersistenceSchemaError';
|
||||
import {
|
||||
@@ -44,40 +45,40 @@ export class NotificationOrmMapper {
|
||||
}
|
||||
|
||||
try {
|
||||
const domainProps: any = {
|
||||
const domainProps = {
|
||||
id: entity.id,
|
||||
recipientId: entity.recipientId,
|
||||
type: entity.type,
|
||||
type: entity.type as NotificationType,
|
||||
title: entity.title,
|
||||
body: entity.body,
|
||||
channel: entity.channel,
|
||||
status: entity.status,
|
||||
urgency: entity.urgency,
|
||||
channel: entity.channel as NotificationChannel,
|
||||
status: entity.status as NotificationStatus,
|
||||
urgency: entity.urgency as NotificationUrgency,
|
||||
createdAt: entity.createdAt,
|
||||
requiresResponse: entity.requiresResponse,
|
||||
};
|
||||
|
||||
if (entity.data !== null && entity.data !== undefined) {
|
||||
domainProps.data = entity.data as Record<string, unknown>;
|
||||
(domainProps as any).data = entity.data;
|
||||
}
|
||||
|
||||
if (entity.actionUrl !== null && entity.actionUrl !== undefined) {
|
||||
domainProps.actionUrl = entity.actionUrl;
|
||||
(domainProps as any).actionUrl = entity.actionUrl;
|
||||
}
|
||||
|
||||
if (entity.actions !== null && entity.actions !== undefined) {
|
||||
domainProps.actions = entity.actions;
|
||||
(domainProps as any).actions = entity.actions;
|
||||
}
|
||||
|
||||
if (entity.readAt !== null && entity.readAt !== undefined) {
|
||||
domainProps.readAt = entity.readAt;
|
||||
(domainProps as any).readAt = entity.readAt;
|
||||
}
|
||||
|
||||
if (entity.respondedAt !== null && entity.respondedAt !== undefined) {
|
||||
domainProps.respondedAt = entity.respondedAt;
|
||||
(domainProps as any).respondedAt = entity.respondedAt;
|
||||
}
|
||||
|
||||
return Notification.create(domainProps);
|
||||
return Notification.create(domainProps as any);
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : 'Invalid persisted Notification';
|
||||
throw new TypeOrmPersistenceSchemaError({ entityName, fieldName: 'unknown', reason: 'invalid_shape', message });
|
||||
|
||||
@@ -34,7 +34,7 @@ export class NotificationPreferenceOrmMapper {
|
||||
}
|
||||
|
||||
try {
|
||||
const domainProps: any = {
|
||||
const domainProps = {
|
||||
id: entity.id,
|
||||
driverId: entity.driverId,
|
||||
channels: entity.channels,
|
||||
@@ -43,22 +43,22 @@ export class NotificationPreferenceOrmMapper {
|
||||
};
|
||||
|
||||
if (entity.typePreferences !== null && entity.typePreferences !== undefined) {
|
||||
domainProps.typePreferences = entity.typePreferences;
|
||||
(domainProps as unknown as { typePreferences: unknown }).typePreferences = entity.typePreferences;
|
||||
}
|
||||
|
||||
if (entity.digestFrequencyHours !== null && entity.digestFrequencyHours !== undefined) {
|
||||
domainProps.digestFrequencyHours = entity.digestFrequencyHours;
|
||||
(domainProps as unknown as { digestFrequencyHours: unknown }).digestFrequencyHours = entity.digestFrequencyHours;
|
||||
}
|
||||
|
||||
if (entity.quietHoursStart !== null && entity.quietHoursStart !== undefined) {
|
||||
domainProps.quietHoursStart = entity.quietHoursStart;
|
||||
(domainProps as unknown as { quietHoursStart: unknown }).quietHoursStart = entity.quietHoursStart;
|
||||
}
|
||||
|
||||
if (entity.quietHoursEnd !== null && entity.quietHoursEnd !== undefined) {
|
||||
domainProps.quietHoursEnd = entity.quietHoursEnd;
|
||||
(domainProps as unknown as { quietHoursEnd: unknown }).quietHoursEnd = entity.quietHoursEnd;
|
||||
}
|
||||
|
||||
return NotificationPreference.create(domainProps);
|
||||
return NotificationPreference.create(domainProps as unknown as Parameters<typeof NotificationPreference.create>[0]);
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : 'Invalid persisted NotificationPreference';
|
||||
throw new TypeOrmPersistenceSchemaError({ entityName, fieldName: 'unknown', reason: 'invalid_shape', message });
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import type { DataSource } from 'typeorm';
|
||||
import type { NotificationPreference } from '@core/notifications/domain/entities/NotificationPreference';
|
||||
import type { NotificationPreferenceOrmMapper } from '../mappers/NotificationPreferenceOrmMapper';
|
||||
|
||||
import { TypeOrmNotificationPreferenceRepository } from './TypeOrmNotificationPreferenceRepository';
|
||||
|
||||
@@ -33,7 +36,7 @@ describe('TypeOrmNotificationPreferenceRepository', () => {
|
||||
toOrmEntity: vi.fn().mockReturnValue({ id: 'orm-preference-1' }),
|
||||
};
|
||||
|
||||
const repo = new TypeOrmNotificationPreferenceRepository(dataSource as any, mapper as any);
|
||||
const repo = new TypeOrmNotificationPreferenceRepository(dataSource as unknown as DataSource, mapper as unknown as NotificationPreferenceOrmMapper);
|
||||
|
||||
// Test findByDriverId
|
||||
const preference = await repo.findByDriverId('driver-123');
|
||||
@@ -43,8 +46,8 @@ describe('TypeOrmNotificationPreferenceRepository', () => {
|
||||
expect(preference).toEqual({ id: 'domain-preference-1' });
|
||||
|
||||
// Test save
|
||||
const domainPreference = { id: 'driver-123', driverId: 'driver-123', toJSON: () => ({ id: 'driver-123', driverId: 'driver-123' }) };
|
||||
await repo.save(domainPreference as any);
|
||||
const domainPreference = { id: 'driver-123', driverId: 'driver-123', toJSON: () => ({ id: 'driver-123', driverId: 'driver-123' }) } as unknown as NotificationPreference;
|
||||
await repo.save(domainPreference);
|
||||
expect(mapper.toOrmEntity).toHaveBeenCalledWith(domainPreference);
|
||||
expect(ormRepo.save).toHaveBeenCalledWith({ id: 'orm-preference-1' });
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import type { DataSource } from 'typeorm';
|
||||
import type { NotificationOrmMapper } from '../mappers/NotificationOrmMapper';
|
||||
|
||||
import { TypeOrmNotificationRepository } from './TypeOrmNotificationRepository';
|
||||
|
||||
@@ -36,7 +38,7 @@ describe('TypeOrmNotificationRepository', () => {
|
||||
toOrmEntity: vi.fn().mockReturnValue({ id: 'orm-notification-1' }),
|
||||
};
|
||||
|
||||
const repo = new TypeOrmNotificationRepository(dataSource as any, mapper as any);
|
||||
const repo = new TypeOrmNotificationRepository(dataSource as unknown as DataSource, mapper as unknown as NotificationOrmMapper);
|
||||
|
||||
// Test findById
|
||||
const notification = await repo.findById('notification-1');
|
||||
@@ -61,13 +63,13 @@ describe('TypeOrmNotificationRepository', () => {
|
||||
expect(count).toBe(1);
|
||||
|
||||
// Test create
|
||||
const domainNotification = { id: 'new-notification', toJSON: () => ({ id: 'new-notification' }) };
|
||||
await repo.create(domainNotification as any);
|
||||
const domainNotification = { id: 'new-notification', toJSON: () => ({ id: 'new-notification' }) } as unknown as Notification;
|
||||
await repo.create(domainNotification);
|
||||
expect(mapper.toOrmEntity).toHaveBeenCalledWith(domainNotification);
|
||||
expect(ormRepo.save).toHaveBeenCalledWith({ id: 'orm-notification-1' });
|
||||
|
||||
// Test update
|
||||
await repo.update(domainNotification as any);
|
||||
await repo.update(domainNotification);
|
||||
expect(mapper.toOrmEntity).toHaveBeenCalledWith(domainNotification);
|
||||
expect(ormRepo.save).toHaveBeenCalledWith({ id: 'orm-notification-1' });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user