diff --git a/src/domain/entities/noteHistory.ts b/src/domain/entities/noteHistory.ts index 8295e8a4..d2cd0258 100644 --- a/src/domain/entities/noteHistory.ts +++ b/src/domain/entities/noteHistory.ts @@ -1,4 +1,4 @@ -import type { NoteInternalId, Note } from './note.js'; +import type { NoteInternalId, Note, NotePublicId } from './note.js'; import type User from './user.js'; export interface NoteHistoryRecord { @@ -38,4 +38,13 @@ export interface NoteHistoryRecord { */ export type NoteHistoryCreationAttributes = Omit; +/** + * Meta data of the note history record + * Used for presentation of the note history recored in web + */ export type NoteHistoryMeta = Omit; + +/** + * Public note history record with note public id instead of note internal id + */ +export type NoteHistoryPublic = Omit & { noteId: NotePublicId }; diff --git a/src/domain/service/note.ts b/src/domain/service/note.ts index 9e9e851a..c0f834bc 100644 --- a/src/domain/service/note.ts +++ b/src/domain/service/note.ts @@ -8,7 +8,7 @@ import type EditorToolsRepository from '@repository/editorTools.repository.js'; import type User from '@domain/entities/user.js'; import type { NoteList } from '@domain/entities/noteList.js'; import type NoteHistoryRepository from '@repository/noteHistory.repository.js'; -import type { NoteHistoryMeta, NoteHistoryRecord } from '@domain/entities/noteHistory.js'; +import type { NoteHistoryMeta, NoteHistoryRecord, NoteHistoryPublic } from '@domain/entities/noteHistory.js'; /** * Note service @@ -406,13 +406,22 @@ export default class NoteService { * @param id - id of the note history record * @returns full note history record or raises domain error if record not found */ - public async getHistoryResordById(id: NoteHistoryRecord['id']): Promise { + public async getHistoryResordById(id: NoteHistoryRecord['id']): Promise { const noteHistoryRecord = await this.noteHistoryRepository.getHistoryRecordById(id); if (noteHistoryRecord === null) { throw new DomainError('This version of the note not found'); } - return noteHistoryRecord; + const noteHistoryPublic = { + id: noteHistoryRecord.id, + noteId: await this.getNotePublicIdByInternal(noteHistoryRecord.noteId), + userId: noteHistoryRecord.userId, + content: noteHistoryRecord.content, + tools: noteHistoryRecord.tools, + createdAt: noteHistoryRecord.createdAt, + }; + + return noteHistoryPublic; } } diff --git a/src/presentation/http/router/note.test.ts b/src/presentation/http/router/note.test.ts index c528394f..98204b7e 100644 --- a/src/presentation/http/router/note.test.ts +++ b/src/presentation/http/router/note.test.ts @@ -2067,7 +2067,14 @@ describe('Note API', () => { expect(response?.json()).toStrictEqual({ message: expectedMessage }); } else if (expectedResponse !== undefined) { expect(response?.json()).toStrictEqual({ - noteHistoryRecord: history, + noteHistoryRecord: { + id: history.id, + userId: history.userId, + noteId: note.publicId, + createdAt: history.createdAt, + content: history.content, + tools: history.tools, + }, }); } }); diff --git a/src/presentation/http/router/note.ts b/src/presentation/http/router/note.ts index e6cef567..6231d668 100644 --- a/src/presentation/http/router/note.ts +++ b/src/presentation/http/router/note.ts @@ -11,7 +11,7 @@ import { type NotePublic, definePublicNote } from '@domain/entities/notePublic.j import type NoteVisitsService from '@domain/service/noteVisits.js'; import type EditorToolsService from '@domain/service/editorTools.js'; import type EditorTool from '@domain/entities/editorTools.js'; -import type { NoteHistoryMeta, NoteHistoryRecord } from '@domain/entities/noteHistory.js'; +import type { NoteHistoryMeta, NoteHistoryPublic, NoteHistoryRecord } from '@domain/entities/noteHistory.js'; /** * Interface for the note router. @@ -712,7 +712,7 @@ const NoteRouter: FastifyPluginCallback = (fastify, opts, don historyId: NoteHistoryRecord['id']; }; Reply: { - noteHistoryRecord: NoteHistoryRecord; + noteHistoryRecord: NoteHistoryPublic; } | ErrorResponse; }>('/:notePublicId/history/:historyId', { config: { diff --git a/src/presentation/http/schema/History.ts b/src/presentation/http/schema/History.ts index a1b487c5..7dc91c7e 100644 --- a/src/presentation/http/schema/History.ts +++ b/src/presentation/http/schema/History.ts @@ -18,7 +18,7 @@ export const HistotyRecordShema = { }, noteId: { description: 'unique note identifier', - type: 'number', + type: 'string', }, userId: { description: 'unique user identifier', @@ -74,10 +74,6 @@ export const HistoryMetaSchema = { description: 'unique note hisotry record identifier', type: 'number', }, - noteId: { - description: 'unique note identifier', - type: 'number', - }, userId: { description: 'unique user identifier', type: 'number',