-
Notifications
You must be signed in to change notification settings - Fork 1
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
feat(parent structure): add method that return note parent structure #276
base: main
Are you sure you want to change the base?
Changes from 13 commits
df44b32
0551b9f
a5adcc2
bccf7b1
42cb421
bb6caff
a11d1f8
0e3e8f0
3adff28
d6c9ded
6bdc56a
6cf3d4c
1809ca1
ca7a9a2
e14d948
5c6cfc0
5bb6be5
fee9bbf
d65c589
14234a1
c09ad3a
9872d5e
5a9fad2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
version: "3.2" | ||
services: | ||
api: | ||
build: | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -9,6 +9,8 @@ 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, NoteHistoryPublic } from '@domain/entities/noteHistory.js'; | ||||||
import type TeamRepository from '@repository/team.repository.js'; | ||||||
import type { NotePublic } from '@domain/entities/notePublic.js'; | ||||||
|
||||||
/** | ||||||
* Note service | ||||||
|
@@ -39,6 +41,11 @@ export default class NoteService { | |||||
*/ | ||||||
public noteHistoryRepository: NoteHistoryRepository; | ||||||
|
||||||
/** | ||||||
* Team repository | ||||||
*/ | ||||||
public teamRepository: TeamRepository; | ||||||
|
||||||
/** | ||||||
* Number of the notes to be displayed on one page | ||||||
* it is used to calculate offset and limit for getting notes that the user has recently opened | ||||||
|
@@ -57,13 +64,15 @@ export default class NoteService { | |||||
* @param noteVisitsRepository - note visits repository | ||||||
* @param editorToolsRepository - editor tools repositoryn | ||||||
* @param noteHistoryRepository - note history repository | ||||||
* @param teamRepository - team note repository | ||||||
*/ | ||||||
constructor(noteRepository: NoteRepository, noteRelationsRepository: NoteRelationsRepository, noteVisitsRepository: NoteVisitsRepository, editorToolsRepository: EditorToolsRepository, noteHistoryRepository: NoteHistoryRepository) { | ||||||
constructor(noteRepository: NoteRepository, noteRelationsRepository: NoteRelationsRepository, noteVisitsRepository: NoteVisitsRepository, editorToolsRepository: EditorToolsRepository, noteHistoryRepository: NoteHistoryRepository, teamRepository: TeamRepository) { | ||||||
this.noteRepository = noteRepository; | ||||||
this.noteRelationsRepository = noteRelationsRepository; | ||||||
this.noteVisitsRepository = noteVisitsRepository; | ||||||
this.editorToolsRepository = editorToolsRepository; | ||||||
this.noteHistoryRepository = noteHistoryRepository; | ||||||
this.teamRepository = teamRepository; | ||||||
neSpecc marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
} | ||||||
|
||||||
/** | ||||||
|
@@ -441,4 +450,15 @@ export default class NoteService { | |||||
|
||||||
return noteHistoryPublic; | ||||||
} | ||||||
|
||||||
/** | ||||||
* Get note parent structure recursively by note id and user id | ||||||
* and check if user has access to the parent note. | ||||||
* @param noteId - id of the note to get parent structure | ||||||
* @param userId - id of the user that is requesting the parent structure | ||||||
* @returns - array of notes that are parent structure of the note | ||||||
*/ | ||||||
public async getNoteParentStructure(noteId: NoteInternalId, userId: number): Promise<NotePublic[]> { | ||||||
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.
Suggested change
|
||||||
return await this.noteRepository.getAllNotesParents(noteId, userId); | ||||||
} | ||||||
} |
neSpecc marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -518,6 +518,299 @@ describe('Note API', () => { | |
|
||
expect(response?.json().message).toStrictEqual(expectedMessage); | ||
}); | ||
|
||
e11sy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
test('Returns two parents in case of relation between child and parent notes with 200 status', async () => { | ||
/** Create test user */ | ||
const user = await global.db.insertUser(); | ||
|
||
e11sy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/** Create acces token for the user */ | ||
const accessToken = global.auth(user.id); | ||
|
||
/** Create test note - a parent note */ | ||
const parentNote = await global.db.insertNote({ | ||
creatorId: user.id, | ||
}); | ||
|
||
/** Create test note - a child note */ | ||
const childNote = await global.db.insertNote({ | ||
creatorId: user.id, | ||
}); | ||
|
||
/** Create test note settings */ | ||
await global.db.insertNoteSetting({ | ||
noteId: childNote.id, | ||
isPublic: true, | ||
}); | ||
|
||
/** Create test note relation */ | ||
await global.db.insertNoteRelation({ | ||
parentId: parentNote.id, | ||
noteId: childNote.id, | ||
}); | ||
|
||
const response = await global.api?.fakeRequest({ | ||
method: 'GET', | ||
headers: { | ||
authorization: `Bearer ${accessToken}`, | ||
}, | ||
url: `/note/${childNote.publicId}`, | ||
}); | ||
|
||
expect(response?.statusCode).toBe(200); | ||
|
||
expect(response?.json()).toMatchObject({ | ||
parents: [ | ||
{ | ||
id: parentNote.publicId, | ||
content: parentNote.content, | ||
}, | ||
{ | ||
id: childNote.publicId, | ||
content: childNote.content, | ||
}, | ||
Comment on lines
+563
to
+570
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.
so why there are two notes? 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.
|
||
], | ||
}); | ||
}); | ||
|
||
test('Returns multiple parents in case of multiple notes relations with user presence in team in each note with 200 status', async () => { | ||
/** Create test user */ | ||
const user = await global.db.insertUser(); | ||
|
||
/** Create acces token for the user */ | ||
const accessToken = global.auth(user.id); | ||
|
||
/** Create test note - a parent note */ | ||
const parentNote = await global.db.insertNote({ | ||
creatorId: user.id, | ||
}); | ||
|
||
/** Create test note - a child note */ | ||
const childNote = await global.db.insertNote({ | ||
creatorId: user.id, | ||
}); | ||
|
||
/** Create test note - a grandchild note */ | ||
const grandchildNote = await global.db.insertNote({ | ||
creatorId: user.id, | ||
}); | ||
|
||
/** Create test note settings */ | ||
await global.db.insertNoteSetting({ | ||
noteId: grandchildNote.id, | ||
isPublic: true, | ||
}); | ||
|
||
/** Create test note relation */ | ||
await global.db.insertNoteRelation({ | ||
parentId: parentNote.id, | ||
noteId: childNote.id, | ||
}); | ||
|
||
await global.db.insertNoteRelation({ | ||
parentId: childNote.id, | ||
noteId: grandchildNote.id, | ||
}); | ||
|
||
const response = await global.api?.fakeRequest({ | ||
method: 'GET', | ||
headers: { | ||
authorization: `Bearer ${accessToken}`, | ||
}, | ||
url: `/note/${grandchildNote.publicId}`, | ||
}); | ||
|
||
expect(response?.statusCode).toBe(200); | ||
|
||
expect(response?.json()).toMatchObject({ | ||
parents: [ | ||
{ | ||
id: parentNote.publicId, | ||
content: parentNote.content, | ||
}, | ||
{ | ||
id: childNote.publicId, | ||
content: childNote.content, | ||
}, | ||
{ | ||
id: grandchildNote.publicId, | ||
content: grandchildNote.content, | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
test('Returns one parent in case where there is no note relation with 200 status', async () => { | ||
/** Create test user */ | ||
const user = await global.db.insertUser(); | ||
|
||
/** Create acces token for the user */ | ||
const accessToken = global.auth(user.id); | ||
/** Create test note */ | ||
const note = await global.db.insertNote({ | ||
creatorId: user.id, | ||
}); | ||
|
||
/** Create test note settings */ | ||
await global.db.insertNoteSetting({ | ||
noteId: note.id, | ||
isPublic: true, | ||
}); | ||
|
||
const response = await global.api?.fakeRequest({ | ||
method: 'GET', | ||
headers: { | ||
authorization: `Bearer ${accessToken}`, | ||
}, | ||
url: `/note/${note.publicId}`, | ||
}); | ||
|
||
expect(response?.statusCode).toBe(200); | ||
|
||
expect(response?.json()).toMatchObject({ | ||
parents: [ | ||
{ | ||
id: note.publicId, | ||
content: note.content, | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
test('Returns mutiple parents in case where user is not in the team of a note with 200 status', async () => { | ||
/** Create test user */ | ||
const user1 = await global.db.insertUser(); | ||
const user2 = await global.db.insertUser(); | ||
|
||
/** Create acces token for the user */ | ||
const accessToken = global.auth(user1.id); | ||
|
||
/** Create test base note */ | ||
const grandChildNote = await global.db.insertNote({ | ||
creatorId: user1.id, | ||
}); | ||
|
||
/** Create base note parent */ | ||
const childNote = await global.db.insertNote({ | ||
creatorId: user2.id, | ||
}); | ||
|
||
/** Create base note grand parent */ | ||
const parentNote = await global.db.insertNote({ | ||
creatorId: user1.id, | ||
}); | ||
|
||
/** Create base note settings */ | ||
await global.db.insertNoteSetting({ | ||
noteId: grandChildNote.id, | ||
isPublic: true, | ||
}); | ||
|
||
/** Create note relations */ | ||
await global.db.insertNoteRelation({ | ||
parentId: parentNote.id, | ||
noteId: childNote.id, | ||
}); | ||
|
||
await global.db.insertNoteRelation({ | ||
parentId: childNote.id, | ||
noteId: grandChildNote.id, | ||
}); | ||
|
||
const response = await global.api?.fakeRequest({ | ||
method: 'GET', | ||
headers: { | ||
authorization: `Bearer ${accessToken}`, | ||
}, | ||
url: `/note/${grandChildNote.publicId}`, | ||
}); | ||
|
||
expect(response?.statusCode).toBe(200); | ||
|
||
expect(response?.json()).toMatchObject({ | ||
parents: [ | ||
{ | ||
id: parentNote.publicId, | ||
content: parentNote.content, | ||
}, | ||
{ | ||
id: childNote.publicId, | ||
content: childNote.content, | ||
}, | ||
{ | ||
id: grandChildNote.publicId, | ||
content: grandChildNote.content, | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
test('Returns multiple parents in case when note is not public with 200 status', async () => { | ||
/** Create test user */ | ||
const user1 = await global.db.insertUser(); | ||
const user2 = await global.db.insertUser(); | ||
|
||
/** Create acces token for the user */ | ||
const accessToken = global.auth(user1.id); | ||
|
||
/** Create test base note */ | ||
const grandChildNote = await global.db.insertNote({ | ||
creatorId: user1.id, | ||
}); | ||
|
||
/** Create base note parent */ | ||
const childNote = await global.db.insertNote({ | ||
creatorId: user2.id, | ||
}); | ||
|
||
/** Create base note grand parent */ | ||
const parentNote = await global.db.insertNote({ | ||
creatorId: user1.id, | ||
}); | ||
|
||
/** Create base note settings */ | ||
await global.db.insertNoteSetting({ | ||
noteId: grandChildNote.id, | ||
isPublic: false, | ||
}); | ||
|
||
/** Create note relations */ | ||
await global.db.insertNoteRelation({ | ||
parentId: parentNote.id, | ||
noteId: childNote.id, | ||
}); | ||
|
||
await global.db.insertNoteRelation({ | ||
parentId: childNote.id, | ||
noteId: grandChildNote.id, | ||
}); | ||
|
||
const response = await global.api?.fakeRequest({ | ||
method: 'GET', | ||
headers: { | ||
authorization: `Bearer ${accessToken}`, | ||
}, | ||
url: `/note/${grandChildNote.publicId}`, | ||
}); | ||
|
||
expect(response?.statusCode).toBe(200); | ||
|
||
expect(response?.json()).toMatchObject({ | ||
parents: [ | ||
{ | ||
id: parentNote.publicId, | ||
content: parentNote.content, | ||
}, | ||
{ | ||
id: childNote.publicId, | ||
content: childNote.content, | ||
}, | ||
{ | ||
id: grandChildNote.publicId, | ||
content: grandChildNote.content, | ||
}, | ||
], | ||
}); | ||
}); | ||
}); | ||
|
||
describe('PATCH note/:notePublicId ', () => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unexpected change