-
Notifications
You must be signed in to change notification settings - Fork 2
Fix/note title composer #291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2450858
Note title composer on backend
devnull-1337 772ad5f
Removed useless comments
devnull-1337 b7354b5
Refactor done
devnull-1337 226df48
description changed
devnull-1337 6b4b121
Removed duplicate method
devnull-1337 837de3c
Changed from NoteRow to NoteDAO
devnull-1337 d8209fb
Name changes
devnull-1337 83faa86
Name change
devnull-1337 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Improve the comment please |
||
| * @param noteId - note id | ||
| * @returns NoteHierarchy structure | ||
| * @returns Array of raw note rows (note with parent_id) | ||
| */ | ||
| public async getNoteHierarchyByNoteId(noteId: NoteInternalId): Promise<NoteHierarchy | null> { | ||
| return await this.storage.getNoteHierarchybyNoteId(noteId); | ||
| public async getNoteRowByNoteId(noteId: NoteInternalId): Promise<NoteRow[] | null> { | ||
| return await this.storage.getNoteRowbyNoteId(noteId); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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,33 +348,33 @@ 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 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Improve the comment please |
||
| * @param noteId - note id | ||
| * @returns Array of raw note rows (note with parent_id) | ||
| */ | ||
| public async getNoteHierarchybyNoteId(noteId: NoteInternalId): Promise<NoteHierarchy | null> { | ||
| public async getNoteRowbyNoteId(noteId: NoteInternalId): Promise<NoteRow[] | null> { | ||
| // 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 | ||
|
|
||
| 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,46 +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<NoteInternalId, NoteHierarchy>(); | ||
|
|
||
| let root: NoteHierarchy | null = null; | ||
|
|
||
| // Step 1: Parse and initialize all notes | ||
| notes.forEach((note) => { | ||
| notesMap.set(note.noteid, { | ||
| id: note.public_id, | ||
| content: 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; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.