diff --git a/src/modules/cards/infrastructure/repositories/mappers/CardMapper.ts b/src/modules/cards/infrastructure/repositories/mappers/CardMapper.ts index 1aaf286b..069a617b 100644 --- a/src/modules/cards/infrastructure/repositories/mappers/CardMapper.ts +++ b/src/modules/cards/infrastructure/repositories/mappers/CardMapper.ts @@ -31,11 +31,11 @@ interface UrlContentData { }; } -interface NoteContentData { +export interface NoteContentData { text: string; } -type CardContentData = UrlContentData | NoteContentData; +export type CardContentData = UrlContentData | NoteContentData; // Persistence layer types export interface CardPersistenceData { diff --git a/src/modules/cards/infrastructure/repositories/query-services/NoteCardQueryService.ts b/src/modules/cards/infrastructure/repositories/query-services/NoteCardQueryService.ts index a1e32f36..4d082708 100644 --- a/src/modules/cards/infrastructure/repositories/query-services/NoteCardQueryService.ts +++ b/src/modules/cards/infrastructure/repositories/query-services/NoteCardQueryService.ts @@ -9,6 +9,7 @@ import { } from '../../../domain/ICardQueryRepository'; import { cards } from '../schema/card.sql'; import { CardTypeEnum } from '../../../domain/value-objects/CardType'; +import { NoteContentData } from '../mappers/CardMapper'; export class NoteCardQueryService { constructor(private db: PostgresJsDatabase) {} @@ -52,8 +53,8 @@ export class NoteCardQueryService { // Map to DTOs const items: NoteCardForUrlDTO[] = noteCardsResult.map((card) => { - const contentData = card.contentData as any; - const noteText = contentData?.note?.text || ''; + const contentData = card.contentData as NoteContentData; + const noteText = contentData.text; return { id: card.id, diff --git a/src/modules/cards/tests/application/GetCollectionPageUseCase.test.ts b/src/modules/cards/tests/application/GetCollectionPageUseCase.test.ts index e047c9b4..cb3a8b96 100644 --- a/src/modules/cards/tests/application/GetCollectionPageUseCase.test.ts +++ b/src/modules/cards/tests/application/GetCollectionPageUseCase.test.ts @@ -757,6 +757,7 @@ describe('GetCollectionPageUseCase', () => { getUrlCardView: jest.fn(), getLibrariesForCard: jest.fn(), getLibrariesForUrl: jest.fn(), + getNoteCardsForUrl: jest.fn(), }; const errorUseCase = new GetCollectionPageUseCase( diff --git a/src/modules/cards/tests/application/GetLibrariesForUrlUseCase.test.ts b/src/modules/cards/tests/application/GetLibrariesForUrlUseCase.test.ts index 07e2fca5..f0fa3cfe 100644 --- a/src/modules/cards/tests/application/GetLibrariesForUrlUseCase.test.ts +++ b/src/modules/cards/tests/application/GetLibrariesForUrlUseCase.test.ts @@ -317,6 +317,7 @@ describe('GetLibrariesForUrlUseCase', () => { getLibrariesForUrl: jest .fn() .mockRejectedValue(new Error('Database error')), + getNoteCardsForUrl: jest.fn(), }; const errorUseCase = new GetLibrariesForUrlUseCase( diff --git a/src/modules/cards/tests/application/GetMyUrlCardsUseCase.test.ts b/src/modules/cards/tests/application/GetMyUrlCardsUseCase.test.ts index 7e22148d..001ef645 100644 --- a/src/modules/cards/tests/application/GetMyUrlCardsUseCase.test.ts +++ b/src/modules/cards/tests/application/GetMyUrlCardsUseCase.test.ts @@ -628,6 +628,7 @@ describe('GetUrlCardsUseCase', () => { .mockRejectedValue(new Error('Database connection failed')), getLibrariesForCard: jest.fn(), getLibrariesForUrl: jest.fn(), + getNoteCardsForUrl: jest.fn(), }; const errorUseCase = new GetUrlCardsUseCase( diff --git a/src/modules/cards/tests/application/GetUrlCardViewUseCase.test.ts b/src/modules/cards/tests/application/GetUrlCardViewUseCase.test.ts index 4ffb16c9..ac4452aa 100644 --- a/src/modules/cards/tests/application/GetUrlCardViewUseCase.test.ts +++ b/src/modules/cards/tests/application/GetUrlCardViewUseCase.test.ts @@ -476,6 +476,7 @@ describe('GetUrlCardViewUseCase', () => { .mockRejectedValue(new Error('Database connection failed')), getLibrariesForCard: jest.fn(), getLibrariesForUrl: jest.fn(), + getNoteCardsForUrl: jest.fn(), }; const errorUseCase = new GetUrlCardViewUseCase(errorRepo, profileService); diff --git a/src/modules/cards/tests/infrastructure/DrizzleCardQueryRepository.getNoteCardsForUrl.integration.test.ts b/src/modules/cards/tests/infrastructure/DrizzleCardQueryRepository.getNoteCardsForUrl.integration.test.ts index e43d3037..c98daff5 100644 --- a/src/modules/cards/tests/infrastructure/DrizzleCardQueryRepository.getNoteCardsForUrl.integration.test.ts +++ b/src/modules/cards/tests/infrastructure/DrizzleCardQueryRepository.getNoteCardsForUrl.integration.test.ts @@ -8,7 +8,10 @@ import { DrizzleCardQueryRepository } from '../../infrastructure/repositories/Dr import { DrizzleCardRepository } from '../../infrastructure/repositories/DrizzleCardRepository'; import { CuratorId } from '../../domain/value-objects/CuratorId'; import { cards } from '../../infrastructure/repositories/schema/card.sql'; -import { collections, collectionCards } from '../../infrastructure/repositories/schema/collection.sql'; +import { + collections, + collectionCards, +} from '../../infrastructure/repositories/schema/collection.sql'; import { libraryMemberships } from '../../infrastructure/repositories/schema/libraryMembership.sql'; import { publishedRecords } from '../../infrastructure/repositories/schema/publishedRecord.sql'; import { CardBuilder } from '../utils/builders/CardBuilder'; @@ -215,7 +218,7 @@ describe('DrizzleCardQueryRepository - getNoteCardsForUrl', () => { expect(page1.items[1]!.note).toBe('Note 2 about the article'); // Test second page - const page2 = await queryRepository.getNoteCardsFor Url(testUrl, { + const page2 = await queryRepository.getNoteCardsForUrl(testUrl, { page: 2, limit: 2, sortBy: CardSortField.CREATED_AT,