Skip to content

Commit

Permalink
update (note parents): only include the parents note without the main…
Browse files Browse the repository at this point in the history
… note
  • Loading branch information
dependentmadani committed Oct 15, 2024
1 parent aa93ee2 commit ed49e60
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 25 deletions.
21 changes: 2 additions & 19 deletions src/presentation/http/router/note.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -564,10 +564,6 @@ describe('Note API', () => {
id: parentNote.publicId,
content: parentNote.content,
},
{
id: childNote.publicId,
content: childNote.content,
},
],
});
});
Expand Down Expand Up @@ -632,10 +628,6 @@ describe('Note API', () => {
id: parentNote.publicId,
content: parentNote.content,
},
{
id: childNote.publicId,
content: childNote.content,
},
],
});
});
Expand Down Expand Up @@ -688,15 +680,11 @@ describe('Note API', () => {
id: parentNote.publicId,
content: parentNote.content,
},
{
id: childNote.publicId,
content: childNote.content,
},
],
});
});

test('Returns one note in case where there is no relation exist for the note with status 200', async () => {
test('Returns no note in case where there is no relation exist for the note with status 200', async () => {
/** Create test user */
const user = await global.db.insertUser();

Expand Down Expand Up @@ -725,12 +713,7 @@ describe('Note API', () => {
expect(response?.statusCode).toBe(200);

expect(response?.json()).toMatchObject({
parents: [
{
id: note.publicId,
content: note.content,
},
],
parents: [],
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,8 @@ export default class NoteRelationsSequelizeStorage {
});

// eslint-disable-next-line @typescript-eslint/naming-convention
const output = (result as { note_id: number; parent_id: number }[])?.map(note => note.parent_id) ?? [];
parentNotes = (result as { note_id: number; parent_id: number }[])?.map(note => note.parent_id) ?? [];

if (output.find(note => (note == noteId)) == undefined) {
parentNotes = [noteId, ...output];
} else {
parentNotes = output;
}
parentNotes.reverse();
} catch {
console.log(`something wrong happened with sql query`);
Expand Down

0 comments on commit ed49e60

Please sign in to comment.