From 245085861fa5ae7138d5c4f5b33b2ca6d5009faf Mon Sep 17 00:00:00 2001 From: devnull-1337 Date: Sun, 6 Apr 2025 14:01:42 +0530 Subject: [PATCH 1/8] Note title composer on backend --- src/domain/entities/NoteHierarchy.ts | 8 ++--- src/presentation/http/router/note.test.ts | 31 ++++++++++++++----- src/presentation/http/schema/NoteHierarchy.ts | 18 +++-------- .../storage/postgres/orm/sequelize/note.ts | 16 ++++++++-- 4 files changed, 46 insertions(+), 27 deletions(-) diff --git a/src/domain/entities/NoteHierarchy.ts b/src/domain/entities/NoteHierarchy.ts index 8ada950f..c6ff0765 100644 --- a/src/domain/entities/NoteHierarchy.ts +++ b/src/domain/entities/NoteHierarchy.ts @@ -1,4 +1,4 @@ -import type { NoteContent, NotePublicId } from './note.js'; +import type { NotePublicId } from './note.js'; /** * Note Tree entity @@ -8,12 +8,12 @@ export interface NoteHierarchy { /** * public note id */ - id: NotePublicId; + noteId: NotePublicId; /** - * note content + * note title */ - content: NoteContent; + noteTitle: string; /** * child notes diff --git a/src/presentation/http/router/note.test.ts b/src/presentation/http/router/note.test.ts index 2d3ad260..683c4937 100644 --- a/src/presentation/http/router/note.test.ts +++ b/src/presentation/http/router/note.test.ts @@ -1,7 +1,7 @@ import { MemberRole } from '@domain/entities/team.js'; import { describe, test, expect, beforeEach } from 'vitest'; import type User from '@domain/entities/user.js'; -import type { Note } from '@domain/entities/note.js'; +import type { Note, NoteContent } from '@domain/entities/note.js'; describe('Note API', () => { /** @@ -2278,6 +2278,23 @@ describe('Note API', () => { let accessToken = ''; let user: User; + const getTitleFromContent = (content: NoteContent | undefined): string => { + const limitCharsForNoteTitle = 50; // Same as frontend + + if (!content) { + return 'Untitled'; + } + + const firstNoteBlock = content.blocks[0]; + const text = (firstNoteBlock?.data as { text?: string })?.text; + + if (text === undefined || text.trim() === '') { + return 'Untitled'; // Same fallback + } + + return text.replace(/ /g, ' ').slice(0, limitCharsForNoteTitle); + }; + beforeEach(async () => { /** create test user */ user = await global.db.insertUser(); @@ -2304,8 +2321,8 @@ describe('Note API', () => { }, expected: (note: Note, childNote: Note | null) => ({ - id: note.publicId, - content: note.content, + noteId: note.publicId, + noteTitle: getTitleFromContent(note.content), childNotes: childNote, }), }, @@ -2336,12 +2353,12 @@ describe('Note API', () => { }; }, expected: (note: Note, childNote: Note | null) => ({ - id: note.publicId, - content: note.content, + noteId: note.publicId, + noteTitle: getTitleFromContent(note.content), childNotes: [ { - id: childNote?.publicId, - content: childNote?.content, + noteId: childNote?.publicId, + noteTitle: getTitleFromContent(childNote?.content), childNotes: null, }, ], diff --git a/src/presentation/http/schema/NoteHierarchy.ts b/src/presentation/http/schema/NoteHierarchy.ts index 84b27fd5..0e169f60 100644 --- a/src/presentation/http/schema/NoteHierarchy.ts +++ b/src/presentation/http/schema/NoteHierarchy.ts @@ -1,25 +1,15 @@ export const NoteHierarchySchema = { $id: 'NoteHierarchySchema', properties: { - id: { + noteId: { type: 'string', pattern: '[a-zA-Z0-9-_]+', maxLength: 10, minLength: 10, }, - content: { - type: 'object', - properties: { - time: { - type: 'number', - }, - blocks: { - type: 'array', - }, - version: { - type: 'string', - }, - }, + noteTitle: { + type: 'string', + maxLength: 50, }, childNotes: { type: 'array', diff --git a/src/repository/storage/postgres/orm/sequelize/note.ts b/src/repository/storage/postgres/orm/sequelize/note.ts index b621ffc9..55703c51 100644 --- a/src/repository/storage/postgres/orm/sequelize/note.ts +++ b/src/repository/storage/postgres/orm/sequelize/note.ts @@ -402,11 +402,23 @@ export default class NoteSequelizeStorage { let root: NoteHierarchy | null = null; + const getTitleFromContent = (content: NoteContent): string => { + const limitCharsForNoteTitle = 50; + const firstNoteBlock = content.blocks[0]; + const text = (firstNoteBlock?.data as { text?: string })?.text; + + if (text === undefined || text.trim() === '') { + return 'Untitled'; + } + + return text.replace(/ /g, ' ').slice(0, limitCharsForNoteTitle); + }; + // Step 1: Parse and initialize all notes notes.forEach((note) => { notesMap.set(note.noteid, { - id: note.public_id, - content: note.content, + noteId: note.public_id, + noteTitle: getTitleFromContent(note.content), childNotes: null, }); }); From 772ad5f3b38507043df0adaa148b4cb39a07c12b Mon Sep 17 00:00:00 2001 From: devnull-1337 Date: Sun, 6 Apr 2025 14:48:07 +0530 Subject: [PATCH 2/8] Removed useless comments --- src/presentation/http/router/note.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/presentation/http/router/note.test.ts b/src/presentation/http/router/note.test.ts index 683c4937..711d3e4b 100644 --- a/src/presentation/http/router/note.test.ts +++ b/src/presentation/http/router/note.test.ts @@ -2279,7 +2279,7 @@ describe('Note API', () => { let user: User; const getTitleFromContent = (content: NoteContent | undefined): string => { - const limitCharsForNoteTitle = 50; // Same as frontend + const limitCharsForNoteTitle = 50; if (!content) { return 'Untitled'; @@ -2289,7 +2289,7 @@ describe('Note API', () => { const text = (firstNoteBlock?.data as { text?: string })?.text; if (text === undefined || text.trim() === '') { - return 'Untitled'; // Same fallback + return 'Untitled'; } return text.replace(/ /g, ' ').slice(0, limitCharsForNoteTitle); From b7354b5809d8493fe363ea7ad0ee4312e7267e29 Mon Sep 17 00:00:00 2001 From: devnull-1337 Date: Sun, 13 Apr 2025 21:59:56 +0530 Subject: [PATCH 3/8] Refactor done --- src/domain/entities/note.ts | 25 ++++++ src/domain/service/note.ts | 56 +++++++++++++- src/repository/note.repository.ts | 11 ++- .../storage/postgres/orm/sequelize/note.ts | 77 ++++--------------- 4 files changed, 96 insertions(+), 73 deletions(-) diff --git a/src/domain/entities/note.ts b/src/domain/entities/note.ts index 2af128e9..794ce2a2 100644 --- a/src/domain/entities/note.ts +++ b/src/domain/entities/note.ts @@ -87,3 +87,28 @@ export interface Note { * Part of note entity used to create new note */ export type NoteCreationAttributes = Pick; + +/** + * Part of note Hierarchy + */ +export type NoteRow = { + /** + * Note id + */ + noteId: NoteInternalId; + + /** + * Note public id + */ + publicId: NotePublicId; + + /** + * Note content + */ + content: NoteContent; + + /** + * Parent note id + */ + parentId: NoteInternalId | null; +}; diff --git a/src/domain/service/note.ts b/src/domain/service/note.ts index 111b98fd..b2bdb679 100644 --- a/src/domain/service/note.ts +++ b/src/domain/service/note.ts @@ -1,4 +1,4 @@ -import type { Note, NoteInternalId, NotePublicId } from '@domain/entities/note.js'; +import type { Note, NoteContent, NoteInternalId, NotePublicId } from '@domain/entities/note.js'; import type NoteRepository from '@repository/note.repository.js'; import type NoteVisitsRepository from '@repository/noteVisits.repository.js'; import { createPublicId } from '@infrastructure/utils/id.js'; @@ -466,8 +466,58 @@ export default class NoteService { // If there is no ultimate parent, the provided noteId is the ultimate parent const rootNoteId = ultimateParent ?? noteId; - const noteHierarchy = await this.noteRepository.getNoteHierarchyByNoteId(rootNoteId); + const notesRows = await this.noteRepository.getNoteRowByNoteId(rootNoteId); - return noteHierarchy; + const notesMap = new Map(); + + let root: NoteHierarchy | null = null; + + if (!notesRows || notesRows.length === 0) { + return null; + } + // Step 1: Parse and initialize all notes + notesRows.forEach((note) => { + notesMap.set(note.noteId, { + noteId: note.publicId, + noteTitle: this.getTitleFromContent(note.content), + childNotes: null, + }); + }); + + // Step 2: Build hierarchy + notesRows.forEach((note) => { + if (note.parentId === null) { + root = notesMap.get(note.noteId) ?? null; + } else { + const parent = notesMap.get(note.parentId); + + if (parent) { + // Initialize childNotes as an array if it's null + if (parent.childNotes === null) { + parent.childNotes = []; + } + parent.childNotes?.push(notesMap.get(note.noteId)!); + } + } + }); + + return root; } + + /** + * Get the title of the note + * @param content - content of the note + * @returns the title of the note + */ + public getTitleFromContent(content: NoteContent): string { + const limitCharsForNoteTitle = 50; + const firstNoteBlock = content.blocks[0]; + const text = (firstNoteBlock?.data as { text?: string })?.text; + + if (text === undefined || text.trim() === '') { + return 'Untitled'; + } + + return text.replace(/ /g, ' ').slice(0, limitCharsForNoteTitle); + }; } diff --git a/src/repository/note.repository.ts b/src/repository/note.repository.ts index a56df5d0..64f540cb 100644 --- a/src/repository/note.repository.ts +++ b/src/repository/note.repository.ts @@ -1,5 +1,4 @@ -import type { Note, NoteCreationAttributes, NoteInternalId, NotePublicId } from '@domain/entities/note.js'; -import type { NoteHierarchy } from '@domain/entities/NoteHierarchy.js'; +import type { Note, NoteCreationAttributes, NoteInternalId, NotePublicId, NoteRow } from '@domain/entities/note.js'; import type NoteStorage from '@repository/storage/note.storage.js'; /** @@ -93,11 +92,11 @@ export default class NoteRepository { } /** - * Gets the Note tree by note id + * Fetches the raw recursive note tree data from DB * @param noteId - note id - * @returns NoteHierarchy structure + * @returns Array of raw note rows (note with parent_id) */ - public async getNoteHierarchyByNoteId(noteId: NoteInternalId): Promise { - return await this.storage.getNoteHierarchybyNoteId(noteId); + public async getNoteRowByNoteId(noteId: NoteInternalId): Promise { + return await this.storage.getNoteRowbyNoteId(noteId); } } diff --git a/src/repository/storage/postgres/orm/sequelize/note.ts b/src/repository/storage/postgres/orm/sequelize/note.ts index 55703c51..a8b2aaf5 100644 --- a/src/repository/storage/postgres/orm/sequelize/note.ts +++ b/src/repository/storage/postgres/orm/sequelize/note.ts @@ -1,12 +1,11 @@ import type { CreationOptional, InferAttributes, InferCreationAttributes, ModelStatic, NonAttribute, Sequelize } from 'sequelize'; import { DataTypes, Model, Op, QueryTypes } from 'sequelize'; import type Orm from '@repository/storage/postgres/orm/sequelize/index.js'; -import type { Note, NoteContent, NoteCreationAttributes, NoteInternalId, NotePublicId } from '@domain/entities/note.js'; +import type { Note, NoteCreationAttributes, NoteInternalId, NotePublicId, NoteRow } from '@domain/entities/note.js'; import { UserModel } from '@repository/storage/postgres/orm/sequelize/user.js'; import type { NoteSettingsModel } from './noteSettings.js'; import type { NoteVisitsModel } from './noteVisits.js'; import type { NoteHistoryModel } from './noteHistory.js'; -import type { NoteHierarchy } from '@domain/entities/NoteHierarchy.js'; /* eslint-disable @typescript-eslint/naming-convention */ @@ -349,19 +348,19 @@ export default class NoteSequelizeStorage { } /** - * Creates a tree of notes - * @param noteId - public note id - * @returns NoteHierarchy + * Fetches the raw recursive note tree data from DB + * @param noteId - note id + * @returns Array of raw note rows (note with parent_id) */ - public async getNoteHierarchybyNoteId(noteId: NoteInternalId): Promise { + public async getNoteRowbyNoteId(noteId: NoteInternalId): Promise { // Fetch all notes and relations in a recursive query const query = ` WITH RECURSIVE note_tree AS ( SELECT - n.id AS noteId, + n.id AS "noteId", n.content, - n.public_id, - nr.parent_id + n.public_id AS "publicId", + nr.parent_id AS "parentId" FROM ${String(this.database.literal(this.tableName).val)} n LEFT JOIN ${String(this.database.literal('note_relations').val)} nr ON n.id = nr.note_id WHERE n.id = :startNoteId @@ -369,13 +368,13 @@ export default class NoteSequelizeStorage { UNION ALL SELECT - n.id AS noteId, + n.id AS "noteId", n.content, - n.public_id, - nr.parent_id + n.public_id AS "publicId", + nr.parent_id AS "parentId" FROM ${String(this.database.literal(this.tableName).val)} n INNER JOIN ${String(this.database.literal('note_relations').val)} nr ON n.id = nr.note_id - INNER JOIN note_tree nt ON nr.parent_id = nt.noteId + INNER JOIN note_tree nt ON nr.parent_id = nt."noteId" ) SELECT * FROM note_tree; `; @@ -388,58 +387,8 @@ export default class NoteSequelizeStorage { if (!result || result.length === 0) { return null; // No data found } - - type NoteRow = { - noteid: NoteInternalId; - public_id: NotePublicId; - content: NoteContent; - parent_id: NoteInternalId | null; - }; - const notes = result as NoteRow[]; - const notesMap = new Map(); - - let root: NoteHierarchy | null = null; - - const getTitleFromContent = (content: NoteContent): string => { - const limitCharsForNoteTitle = 50; - const firstNoteBlock = content.blocks[0]; - const text = (firstNoteBlock?.data as { text?: string })?.text; - - if (text === undefined || text.trim() === '') { - return 'Untitled'; - } - - return text.replace(/ /g, ' ').slice(0, limitCharsForNoteTitle); - }; - - // Step 1: Parse and initialize all notes - notes.forEach((note) => { - notesMap.set(note.noteid, { - noteId: note.public_id, - noteTitle: getTitleFromContent(note.content), - childNotes: null, - }); - }); - - // Step 2: Build hierarchy - notes.forEach((note) => { - if (note.parent_id === null) { - root = notesMap.get(note.noteid) ?? null; - } else { - const parent = notesMap.get(note.parent_id); - - if (parent) { - // Initialize childNotes as an array if it's null - if (parent.childNotes === null) { - parent.childNotes = []; - } - parent.childNotes?.push(notesMap.get(note.noteid)!); - } - } - }); - - return root; + return notes; } } From 226df481de164be4c2abf758ec4804d3951b5662 Mon Sep 17 00:00:00 2001 From: devnull-1337 Date: Tue, 15 Apr 2025 00:20:46 +0530 Subject: [PATCH 4/8] description changed --- src/repository/note.repository.ts | 4 ++-- src/repository/storage/postgres/orm/sequelize/note.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/repository/note.repository.ts b/src/repository/note.repository.ts index 64f540cb..f9484e1b 100644 --- a/src/repository/note.repository.ts +++ b/src/repository/note.repository.ts @@ -92,9 +92,9 @@ export default class NoteRepository { } /** - * Fetches the raw recursive note tree data from DB + * Get note row by noteId * @param noteId - note id - * @returns Array of raw note rows (note with parent_id) + * @returns an array of note rows */ public async getNoteRowByNoteId(noteId: NoteInternalId): Promise { return await this.storage.getNoteRowbyNoteId(noteId); diff --git a/src/repository/storage/postgres/orm/sequelize/note.ts b/src/repository/storage/postgres/orm/sequelize/note.ts index a8b2aaf5..8650b0d9 100644 --- a/src/repository/storage/postgres/orm/sequelize/note.ts +++ b/src/repository/storage/postgres/orm/sequelize/note.ts @@ -348,9 +348,9 @@ export default class NoteSequelizeStorage { } /** - * Fetches the raw recursive note tree data from DB + * Get note row by noteId * @param noteId - note id - * @returns Array of raw note rows (note with parent_id) + * @returns an array of note rows */ public async getNoteRowbyNoteId(noteId: NoteInternalId): Promise { // Fetch all notes and relations in a recursive query From 6b4b121646b444f4c93e6b13d0b62f7f4785e4d5 Mon Sep 17 00:00:00 2001 From: devnull-1337 Date: Thu, 17 Apr 2025 20:28:45 +0530 Subject: [PATCH 5/8] Removed duplicate method --- src/presentation/http/router/note.test.ts | 40 +++++++++-------------- 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/src/presentation/http/router/note.test.ts b/src/presentation/http/router/note.test.ts index 711d3e4b..575932ac 100644 --- a/src/presentation/http/router/note.test.ts +++ b/src/presentation/http/router/note.test.ts @@ -1,7 +1,7 @@ import { MemberRole } from '@domain/entities/team.js'; import { describe, test, expect, beforeEach } from 'vitest'; import type User from '@domain/entities/user.js'; -import type { Note, NoteContent } from '@domain/entities/note.js'; +import type { Note } from '@domain/entities/note.js'; describe('Note API', () => { /** @@ -2278,23 +2278,6 @@ describe('Note API', () => { let accessToken = ''; let user: User; - const getTitleFromContent = (content: NoteContent | undefined): string => { - const limitCharsForNoteTitle = 50; - - if (!content) { - return 'Untitled'; - } - - const firstNoteBlock = content.blocks[0]; - const text = (firstNoteBlock?.data as { text?: string })?.text; - - if (text === undefined || text.trim() === '') { - return 'Untitled'; - } - - return text.replace(/ /g, ' ').slice(0, limitCharsForNoteTitle); - }; - beforeEach(async () => { /** create test user */ user = await global.db.insertUser(); @@ -2307,7 +2290,10 @@ describe('Note API', () => { { description: 'Should get note hierarchy with no parent or child when noteId passed has no relations', setup: async () => { - const note = await global.db.insertNote({ creatorId: user.id }); + const note = await global.db.insertNote({ + creatorId: user.id, + content: DEFAULT_NOTE_CONTENT, + }); await global.db.insertNoteSetting({ noteId: note.id, @@ -2322,7 +2308,7 @@ describe('Note API', () => { expected: (note: Note, childNote: Note | null) => ({ noteId: note.publicId, - noteTitle: getTitleFromContent(note.content), + noteTitle: 'text', childNotes: childNote, }), }, @@ -2331,8 +2317,14 @@ describe('Note API', () => { { description: 'Should get note hierarchy with child when noteId passed has relations', setup: async () => { - const childNote = await global.db.insertNote({ creatorId: user.id }); - const parentNote = await global.db.insertNote({ creatorId: user.id }); + const childNote = await global.db.insertNote({ + creatorId: user.id, + content: DEFAULT_NOTE_CONTENT, + }); + const parentNote = await global.db.insertNote({ + creatorId: user.id, + content: DEFAULT_NOTE_CONTENT, + }); await global.db.insertNoteSetting({ noteId: childNote.id, @@ -2354,11 +2346,11 @@ describe('Note API', () => { }, expected: (note: Note, childNote: Note | null) => ({ noteId: note.publicId, - noteTitle: getTitleFromContent(note.content), + noteTitle: 'text', childNotes: [ { noteId: childNote?.publicId, - noteTitle: getTitleFromContent(childNote?.content), + noteTitle: 'text', childNotes: null, }, ], From 837de3cebfeb2d3042e2d6a1b5537ef8ef161430 Mon Sep 17 00:00:00 2001 From: devnull-1337 Date: Thu, 17 Apr 2025 21:21:39 +0530 Subject: [PATCH 6/8] Changed from NoteRow to NoteDAO --- src/domain/entities/note.ts | 2 +- src/domain/service/note.ts | 2 +- src/repository/note.repository.ts | 6 +++--- src/repository/storage/postgres/orm/sequelize/note.ts | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/domain/entities/note.ts b/src/domain/entities/note.ts index 794ce2a2..b85e7208 100644 --- a/src/domain/entities/note.ts +++ b/src/domain/entities/note.ts @@ -91,7 +91,7 @@ export type NoteCreationAttributes = Pick(); diff --git a/src/repository/note.repository.ts b/src/repository/note.repository.ts index f9484e1b..bc5d46b8 100644 --- a/src/repository/note.repository.ts +++ b/src/repository/note.repository.ts @@ -1,4 +1,4 @@ -import type { Note, NoteCreationAttributes, NoteInternalId, NotePublicId, NoteRow } from '@domain/entities/note.js'; +import type { Note, NoteCreationAttributes, NoteInternalId, NotePublicId, NoteDAO } from '@domain/entities/note.js'; import type NoteStorage from '@repository/storage/note.storage.js'; /** @@ -96,7 +96,7 @@ export default class NoteRepository { * @param noteId - note id * @returns an array of note rows */ - public async getNoteRowByNoteId(noteId: NoteInternalId): Promise { - return await this.storage.getNoteRowbyNoteId(noteId); + public async getNoteDAOByNoteId(noteId: NoteInternalId): Promise { + return await this.storage.getNoteDAObyNoteId(noteId); } } diff --git a/src/repository/storage/postgres/orm/sequelize/note.ts b/src/repository/storage/postgres/orm/sequelize/note.ts index 8650b0d9..30cd5707 100644 --- a/src/repository/storage/postgres/orm/sequelize/note.ts +++ b/src/repository/storage/postgres/orm/sequelize/note.ts @@ -1,7 +1,7 @@ import type { CreationOptional, InferAttributes, InferCreationAttributes, ModelStatic, NonAttribute, Sequelize } from 'sequelize'; import { DataTypes, Model, Op, QueryTypes } from 'sequelize'; import type Orm from '@repository/storage/postgres/orm/sequelize/index.js'; -import type { Note, NoteCreationAttributes, NoteInternalId, NotePublicId, NoteRow } from '@domain/entities/note.js'; +import type { Note, NoteCreationAttributes, NoteInternalId, NotePublicId, NoteDAO } from '@domain/entities/note.js'; import { UserModel } from '@repository/storage/postgres/orm/sequelize/user.js'; import type { NoteSettingsModel } from './noteSettings.js'; import type { NoteVisitsModel } from './noteVisits.js'; @@ -352,7 +352,7 @@ export default class NoteSequelizeStorage { * @param noteId - note id * @returns an array of note rows */ - public async getNoteRowbyNoteId(noteId: NoteInternalId): Promise { + public async getNoteDAObyNoteId(noteId: NoteInternalId): Promise { // Fetch all notes and relations in a recursive query const query = ` WITH RECURSIVE note_tree AS ( @@ -387,7 +387,7 @@ export default class NoteSequelizeStorage { if (!result || result.length === 0) { return null; // No data found } - const notes = result as NoteRow[]; + const notes = result as NoteDAO[]; return notes; } From d8209fb36970f8a9718a89606f074389566c2bb4 Mon Sep 17 00:00:00 2001 From: devnull-1337 Date: Thu, 17 Apr 2025 23:44:29 +0530 Subject: [PATCH 7/8] Name changes --- src/domain/service/note.ts | 2 +- src/repository/note.repository.ts | 8 ++++---- src/repository/storage/postgres/orm/sequelize/note.ts | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/domain/service/note.ts b/src/domain/service/note.ts index 9a662e99..c4ae5b52 100644 --- a/src/domain/service/note.ts +++ b/src/domain/service/note.ts @@ -466,7 +466,7 @@ export default class NoteService { // If there is no ultimate parent, the provided noteId is the ultimate parent const rootNoteId = ultimateParent ?? noteId; - const notesRows = await this.noteRepository.getNoteDAOByNoteId(rootNoteId); + const notesRows = await this.noteRepository.getNoteTreeByNoteId(rootNoteId); const notesMap = new Map(); diff --git a/src/repository/note.repository.ts b/src/repository/note.repository.ts index bc5d46b8..f0b1e5c0 100644 --- a/src/repository/note.repository.ts +++ b/src/repository/note.repository.ts @@ -92,11 +92,11 @@ export default class NoteRepository { } /** - * Get note row by noteId + * Get note and all of its children recursively * @param noteId - note id - * @returns an array of note rows + * @returns an array of note DAO */ - public async getNoteDAOByNoteId(noteId: NoteInternalId): Promise { - return await this.storage.getNoteDAObyNoteId(noteId); + public async getNoteTreeByNoteId(noteId: NoteInternalId): Promise { + return await this.storage.getNoteTreebyNoteId(noteId); } } diff --git a/src/repository/storage/postgres/orm/sequelize/note.ts b/src/repository/storage/postgres/orm/sequelize/note.ts index 30cd5707..ef65799e 100644 --- a/src/repository/storage/postgres/orm/sequelize/note.ts +++ b/src/repository/storage/postgres/orm/sequelize/note.ts @@ -348,11 +348,11 @@ export default class NoteSequelizeStorage { } /** - * Get note row by noteId + * Get note and all of its children recursively * @param noteId - note id - * @returns an array of note rows + * @returns an array of note DAO */ - public async getNoteDAObyNoteId(noteId: NoteInternalId): Promise { + public async getNoteTreebyNoteId(noteId: NoteInternalId): Promise { // Fetch all notes and relations in a recursive query const query = ` WITH RECURSIVE note_tree AS ( From 83faa869920c3c0798b971599833344e732e0871 Mon Sep 17 00:00:00 2001 From: devnull-1337 Date: Thu, 22 May 2025 19:34:11 +0530 Subject: [PATCH 8/8] Name change --- src/domain/entities/note.ts | 4 ++-- src/repository/note.repository.ts | 6 +++--- src/repository/storage/postgres/orm/sequelize/note.ts | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/domain/entities/note.ts b/src/domain/entities/note.ts index b85e7208..82f375c4 100644 --- a/src/domain/entities/note.ts +++ b/src/domain/entities/note.ts @@ -89,9 +89,9 @@ export interface Note { export type NoteCreationAttributes = Pick; /** - * Part of note Hierarchy + * Note preview entity used to display notes in a sidebar hierarchy */ -export type NoteDAO = { +export type NotePreview = { /** * Note id */ diff --git a/src/repository/note.repository.ts b/src/repository/note.repository.ts index f0b1e5c0..234c0741 100644 --- a/src/repository/note.repository.ts +++ b/src/repository/note.repository.ts @@ -1,4 +1,4 @@ -import type { Note, NoteCreationAttributes, NoteInternalId, NotePublicId, NoteDAO } from '@domain/entities/note.js'; +import type { Note, NoteCreationAttributes, NoteInternalId, NotePublicId, NotePreview } from '@domain/entities/note.js'; import type NoteStorage from '@repository/storage/note.storage.js'; /** @@ -94,9 +94,9 @@ export default class NoteRepository { /** * Get note and all of its children recursively * @param noteId - note id - * @returns an array of note DAO + * @returns an array of NotePreview */ - public async getNoteTreeByNoteId(noteId: NoteInternalId): Promise { + public async getNoteTreeByNoteId(noteId: NoteInternalId): Promise { return await this.storage.getNoteTreebyNoteId(noteId); } } diff --git a/src/repository/storage/postgres/orm/sequelize/note.ts b/src/repository/storage/postgres/orm/sequelize/note.ts index ef65799e..1b9ba87c 100644 --- a/src/repository/storage/postgres/orm/sequelize/note.ts +++ b/src/repository/storage/postgres/orm/sequelize/note.ts @@ -1,7 +1,7 @@ import type { CreationOptional, InferAttributes, InferCreationAttributes, ModelStatic, NonAttribute, Sequelize } from 'sequelize'; import { DataTypes, Model, Op, QueryTypes } from 'sequelize'; import type Orm from '@repository/storage/postgres/orm/sequelize/index.js'; -import type { Note, NoteCreationAttributes, NoteInternalId, NotePublicId, NoteDAO } from '@domain/entities/note.js'; +import type { Note, NoteCreationAttributes, NoteInternalId, NotePublicId, NotePreview } from '@domain/entities/note.js'; import { UserModel } from '@repository/storage/postgres/orm/sequelize/user.js'; import type { NoteSettingsModel } from './noteSettings.js'; import type { NoteVisitsModel } from './noteVisits.js'; @@ -350,9 +350,9 @@ export default class NoteSequelizeStorage { /** * Get note and all of its children recursively * @param noteId - note id - * @returns an array of note DAO + * @returns an array of NotePreview */ - public async getNoteTreebyNoteId(noteId: NoteInternalId): Promise { + public async getNoteTreebyNoteId(noteId: NoteInternalId): Promise { // Fetch all notes and relations in a recursive query const query = ` WITH RECURSIVE note_tree AS ( @@ -387,7 +387,7 @@ export default class NoteSequelizeStorage { if (!result || result.length === 0) { return null; // No data found } - const notes = result as NoteDAO[]; + const notes = result as NotePreview[]; return notes; }