Skip to content

Commit 47a3056

Browse files
author
Abhishek Jasud
committed
Naming convention changes, added tests
1 parent 1acb937 commit 47a3056

9 files changed

Lines changed: 38 additions & 31 deletions

File tree

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { NoteContent, NotePublicId } from './note.js';
33
/**
44
* Note Tree entity
55
*/
6-
export interface NoteTree {
6+
export interface NoteHierarchy {
77

88
/**
99
* public note id
@@ -18,6 +18,6 @@ export interface NoteTree {
1818
/**
1919
* child notes
2020
*/
21-
childNotes: NoteTree[] | null;
21+
childNotes: NoteHierarchy[] | null;
2222

2323
}

src/domain/service/note.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type User from '@domain/entities/user.js';
99
import type { NoteList } from '@domain/entities/noteList.js';
1010
import type NoteHistoryRepository from '@repository/noteHistory.repository.js';
1111
import type { NoteHistoryMeta, NoteHistoryRecord, NoteHistoryPublic } from '@domain/entities/noteHistory.js';
12-
import type { NoteTree } from '@domain/entities/noteTree.js';
12+
import type { NoteHierarchy } from '@domain/entities/NoteHierarchy.js';
1313

1414
/**
1515
* Note service
@@ -460,14 +460,14 @@ export default class NoteService {
460460
* @param noteId - id of the note to get structure
461461
* @returns - Object of notes.
462462
*/
463-
public async getNoteHierarchy(noteId: NoteInternalId): Promise<NoteTree | null> {
464-
const ultimateParent = await this.noteRelationsRepository.getUltimateParent(noteId);
463+
public async getNoteHierarchy(noteId: NoteInternalId): Promise<NoteHierarchy | null> {
464+
const ultimateParent = await this.noteRelationsRepository.getUltimateParentNoteId(noteId);
465465

466466
// If there is no ultimate parent, the provided noteId is the ultimate parent
467467
const rootNoteId = ultimateParent ?? noteId;
468468

469-
const noteTree = await this.noteRepository.getNoteTreeByNoteId(rootNoteId);
469+
const noteHierarchy = await this.noteRepository.getNoteHierarchyByNoteId(rootNoteId);
470470

471-
return noteTree;
471+
return noteHierarchy;
472472
}
473473
}

src/presentation/http/http-api.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import { DomainError } from '@domain/entities/DomainError.js';
3333
import UploadRouter from './router/upload.js';
3434
import { ajvFilePlugin } from '@fastify/multipart';
3535
import { UploadSchema } from './schema/Upload.js';
36-
import { NoteTreeSchema } from './schema/NoteTree.js';
36+
import { NoteHierarchySchema } from './schema/NoteHierarchy.js';
3737

3838
const appServerLogger = getLogger('appServer');
3939

@@ -301,7 +301,7 @@ export default class HttpApi implements Api {
301301
this.server?.addSchema(JoinSchemaResponse);
302302
this.server?.addSchema(OauthSchema);
303303
this.server?.addSchema(UploadSchema);
304-
this.server?.addSchema(NoteTreeSchema);
304+
this.server?.addSchema(NoteHierarchySchema);
305305
}
306306

307307
/**

src/presentation/http/router/note.test.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2273,7 +2273,7 @@ describe('Note API', () => {
22732273
});
22742274
});
22752275

2276-
describe('GET /note/notehierarchy/:noteId', () => {
2276+
describe('GET /note/note-hierarchy/:noteId', () => {
22772277
let accessToken = '';
22782278
let user: User;
22792279

@@ -2297,13 +2297,14 @@ describe('Note API', () => {
22972297
headers: {
22982298
authorization: `Bearer ${accessToken}`,
22992299
},
2300-
url: `/note/notehierarchy/${note.publicId}`,
2300+
url: `/note/note-hierarchy/${note.publicId}`,
23012301
});
23022302

23032303
expect(response?.json().notehierarchy.id).toBe(note.publicId);
2304+
expect(response?.json().notehierarchy.childNotes).toHaveLength(0);
23042305
});
23052306

2306-
test('Get note hierarchy with parent or child', async () => {
2307+
test('Get note hierarchy with child', async () => {
23072308
/* create test child note */
23082309
const childNote = await global.db.insertNote({
23092310
creatorId: user.id,
@@ -2331,10 +2332,16 @@ describe('Note API', () => {
23312332
headers: {
23322333
authorization: `Bearer ${accessToken}`,
23332334
},
2334-
url: `/note/notehierarchy/${parentNote.publicId}`,
2335+
url: `/note/note-hierarchy/${parentNote.publicId}`,
23352336
});
23362337

2337-
expect(response?.json().notehierarchy.childNotes[0].id).toBe(childNote.publicId);
2338+
const childNoteObj = {
2339+
id: childNote.publicId,
2340+
content: childNote.content,
2341+
childNotes: [],
2342+
};
2343+
2344+
expect(response?.json().notehierarchy.childNotes[0]).toStrictEqual(childNoteObj);
23382345
});
23392346
});
23402347
});

src/presentation/http/router/note.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import type NoteVisitsService from '@domain/service/noteVisits.js';
1212
import type EditorToolsService from '@domain/service/editorTools.js';
1313
import type EditorTool from '@domain/entities/editorTools.js';
1414
import type { NoteHistoryMeta, NoteHistoryPublic, NoteHistoryRecord } from '@domain/entities/noteHistory.js';
15-
import type { NoteTree } from '@domain/entities/noteTree.js';
15+
import type { NoteHierarchy } from '@domain/entities/NoteHierarchy.js';
1616

1717
/**
1818
* Interface for the note router.
@@ -782,9 +782,9 @@ const NoteRouter: FastifyPluginCallback<NoteRouterOptions> = (fastify, opts, don
782782
notePublicId: NotePublicId;
783783
};
784784
Reply: {
785-
notehierarchy: NoteTree | null;
785+
notehierarchy: NoteHierarchy | null;
786786
} | ErrorResponse;
787-
}>('/notehierarchy/:notePublicId', {
787+
}>('/note-hierarchy/:notePublicId', {
788788
config: {
789789
policy: [
790790
'authRequired',
@@ -801,7 +801,7 @@ const NoteRouter: FastifyPluginCallback<NoteRouterOptions> = (fastify, opts, don
801801
type: 'object',
802802
properties: {
803803
notehierarchy: {
804-
$ref: 'NoteTreeSchema#',
804+
$ref: 'NoteHierarchySchema#',
805805
},
806806
},
807807
},

src/presentation/http/schema/NoteTree.ts renamed to src/presentation/http/schema/NoteHierarchy.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
export const NoteTreeSchema = {
2-
$id: 'NoteTreeSchema',
1+
export const NoteHierarchySchema = {
2+
$id: 'NoteHierarchySchema',
33
properties: {
44
id: {
55
type: 'string',
@@ -23,7 +23,7 @@ export const NoteTreeSchema = {
2323
},
2424
childNotes: {
2525
type: 'array',
26-
items: { $ref: 'NoteTreeSchema#' },
26+
items: { $ref: 'NoteHierarchySchema#' },
2727
nullable: true,
2828
},
2929
},

src/repository/note.repository.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Note, NoteCreationAttributes, NoteInternalId, NotePublicId } from '@domain/entities/note.js';
2-
import type { NoteTree } from '@domain/entities/noteTree.js';
2+
import type { NoteHierarchy } from '@domain/entities/NoteHierarchy.js';
33
import type NoteStorage from '@repository/storage/note.storage.js';
44

55
/**
@@ -95,9 +95,9 @@ export default class NoteRepository {
9595
/**
9696
* Gets the Note tree by note id
9797
* @param noteId - note id
98-
* @returns NoteTree structure
98+
* @returns NoteHierarchy structure
9999
*/
100-
public async getNoteTreeByNoteId(noteId: NoteInternalId): Promise<NoteTree | null> {
101-
return await this.storage.getNoteTreebyNoteId(noteId);
100+
public async getNoteHierarchyByNoteId(noteId: NoteInternalId): Promise<NoteHierarchy | null> {
101+
return await this.storage.getNoteHierarchybyNoteId(noteId);
102102
}
103103
}

src/repository/noteRelations.repository.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export default class NoteRelationsRepository {
8282
* @param noteId - note id to get ultimate parent
8383
* @returns - note id of the ultimate parent
8484
*/
85-
public async getUltimateParent(noteId: NoteInternalId): Promise<NoteInternalId | null> {
85+
public async getUltimateParentNoteId(noteId: NoteInternalId): Promise<NoteInternalId | null> {
8686
return await this.storage.getUltimateParentByNoteId(noteId);
8787
}
8888
}

src/repository/storage/postgres/orm/sequelize/note.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { UserModel } from '@repository/storage/postgres/orm/sequelize/user.js';
66
import type { NoteSettingsModel } from './noteSettings.js';
77
import type { NoteVisitsModel } from './noteVisits.js';
88
import type { NoteHistoryModel } from './noteHistory.js';
9-
import type { NoteTree } from '@domain/entities/noteTree.js';
9+
import type { NoteHierarchy } from '@domain/entities/NoteHierarchy.js';
1010

1111
/* eslint-disable @typescript-eslint/naming-convention */
1212

@@ -351,9 +351,9 @@ export default class NoteSequelizeStorage {
351351
/**
352352
* Creates a tree of notes
353353
* @param noteId - public note id
354-
* @returns NoteTree
354+
* @returns NoteHierarchy
355355
*/
356-
public async getNoteTreebyNoteId(noteId: NoteInternalId): Promise<NoteTree | null> {
356+
public async getNoteHierarchybyNoteId(noteId: NoteInternalId): Promise<NoteHierarchy | null> {
357357
// Fetch all notes and relations in a recursive query
358358
const query = `
359359
WITH RECURSIVE note_tree AS (
@@ -398,9 +398,9 @@ export default class NoteSequelizeStorage {
398398

399399
const notes = result as NoteRow[];
400400

401-
const notesMap = new Map<NoteInternalId, NoteTree>();
401+
const notesMap = new Map<NoteInternalId, NoteHierarchy>();
402402

403-
let root: NoteTree | null = null;
403+
let root: NoteHierarchy | null = null;
404404

405405
// Step 1: Parse and initialize all notes
406406
notes.forEach((note) => {

0 commit comments

Comments
 (0)