From 8fa105ba0c5b51d87f43d69e47ccfe64958bdf35 Mon Sep 17 00:00:00 2001 From: 7eliassen Date: Fri, 26 Jun 2026 20:44:17 +0300 Subject: [PATCH 1/2] refactor: reduced content size --- src/domain/entities/notePublic.ts | 26 ++++++++++++++++++++++-- src/presentation/http/router/noteList.ts | 12 +++++------ 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/domain/entities/notePublic.ts b/src/domain/entities/notePublic.ts index 4989bec8..ad84b362 100644 --- a/src/domain/entities/notePublic.ts +++ b/src/domain/entities/notePublic.ts @@ -1,4 +1,4 @@ -import type { Note } from '@domain/entities/note.js'; +import type { Note, NoteContent } from '@domain/entities/note.js'; type NotePublicProperties = 'content' | 'createdAt' | 'updatedAt' | 'creatorId' | 'cover'; @@ -10,7 +10,7 @@ export interface NotePublic extends Pick { } /** - *Change Note to NotePublic + * Change Note to NotePublic * @param note - Note data to compose a public note */ export function definePublicNote(note: Note): NotePublic { @@ -25,3 +25,25 @@ export function definePublicNote(note: Note): NotePublic { return notePublic; } + +/** + * Change Note to a trimmed NotePublic for list responses. + * Content only includes the first block as a preview. + * @param note - Note data to compose a note list item + */ +export function defineNoteListItem(note: Note): NotePublic { + const trimmedContent: NoteContent = { + blocks: note.content.blocks.slice(0, 1), + }; + + const notePublic: NotePublic = { + id: note.publicId, + content: trimmedContent, + createdAt: note.createdAt, + updatedAt: note.updatedAt, + creatorId: note.creatorId, + cover: note.cover, + }; + + return notePublic; +} \ No newline at end of file diff --git a/src/presentation/http/router/noteList.ts b/src/presentation/http/router/noteList.ts index beb23fbc..2413a101 100644 --- a/src/presentation/http/router/noteList.ts +++ b/src/presentation/http/router/noteList.ts @@ -1,6 +1,6 @@ import type { FastifyPluginCallback } from 'fastify'; import type NoteService from '@domain/service/note.js'; -import { definePublicNote, type NotePublic } from '@domain/entities/notePublic.js'; +import { defineNoteListItem, type NotePublic } from '@domain/entities/notePublic.js'; import type { NoteListPublic } from '@domain/entities/noteList.js'; /** @@ -51,7 +51,7 @@ const NoteListRouter: FastifyPluginCallback = (fastify, o properties: { items: { id: { type: 'string' }, - content: { type: 'string' }, + content: { type: 'object' }, createdAt: { type: 'string' }, creatorId: { type: 'string' }, updatedAt: { type: 'string' }, @@ -68,7 +68,7 @@ const NoteListRouter: FastifyPluginCallback = (fastify, o /** * Wrapping Notelist for public use */ - const noteListItemsPublic: NotePublic[] = noteList.items.map(definePublicNote); + const noteListItemsPublic: NotePublic[] = noteList.items.map(defineNoteListItem); const noteListPublic: NoteListPublic = { items: noteListItemsPublic, @@ -105,7 +105,7 @@ const NoteListRouter: FastifyPluginCallback = (fastify, o properties: { items: { id: { type: 'string' }, - content: { type: 'string' }, + content: { type: 'object' }, createdAt: { type: 'string' }, creatorId: { type: 'string' }, updatedAt: { type: 'string' }, @@ -122,7 +122,7 @@ const NoteListRouter: FastifyPluginCallback = (fastify, o /** * Wrapping Notelist for public use */ - const noteListItemsPublic: NotePublic[] = noteList.items.map(definePublicNote); + const noteListItemsPublic: NotePublic[] = noteList.items.map(defineNoteListItem); const noteListPublic: NoteListPublic = { items: noteListItemsPublic, @@ -134,4 +134,4 @@ const NoteListRouter: FastifyPluginCallback = (fastify, o done(); }; -export default NoteListRouter; +export default NoteListRouter; \ No newline at end of file From 085c7a2413906f2bad2a76db8b7d58d2420c7ced Mon Sep 17 00:00:00 2001 From: 7eliassen Date: Thu, 9 Jul 2026 15:57:11 +0300 Subject: [PATCH 2/2] chore: lint --- src/domain/entities/notePublic.ts | 2 +- src/presentation/http/router/noteList.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/domain/entities/notePublic.ts b/src/domain/entities/notePublic.ts index ad84b362..0a73c225 100644 --- a/src/domain/entities/notePublic.ts +++ b/src/domain/entities/notePublic.ts @@ -46,4 +46,4 @@ export function defineNoteListItem(note: Note): NotePublic { }; return notePublic; -} \ No newline at end of file +} diff --git a/src/presentation/http/router/noteList.ts b/src/presentation/http/router/noteList.ts index 2413a101..5458e763 100644 --- a/src/presentation/http/router/noteList.ts +++ b/src/presentation/http/router/noteList.ts @@ -134,4 +134,4 @@ const NoteListRouter: FastifyPluginCallback = (fastify, o done(); }; -export default NoteListRouter; \ No newline at end of file +export default NoteListRouter;