Skip to content
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

Merged
merged 32 commits into from
Oct 26, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
df44b32
feat(parent structure): add method that return note parent structure
dependentmadani Aug 29, 2024
0551b9f
update: start doing the search in team storage
dependentmadani Sep 1, 2024
a5adcc2
update: first part of code review is done
dependentmadani Sep 4, 2024
bccf7b1
fix: finish the review modifications
dependentmadani Sep 4, 2024
42cb421
update: first part of modification after review
dependentmadani Sep 6, 2024
bb6caff
fix: build problem fixed
dependentmadani Sep 6, 2024
a11d1f8
update(note request): update the content send in get request of note …
dependentmadani Sep 7, 2024
0e3e8f0
update(tests): add different tests for the note parent structure
dependentmadani Sep 8, 2024
3adff28
update(tests): tests are now functional
dependentmadani Sep 9, 2024
d6c9ded
update (parents note): modification based on the reviews, still tests…
dependentmadani Sep 14, 2024
6bdc56a
update: fix lint
dependentmadani Sep 14, 2024
6cf3d4c
update (note parents): few modification in the return value type, add…
dependentmadani Sep 15, 2024
1809ca1
update: add a test
dependentmadani Sep 15, 2024
ca7a9a2
update (note parents): modifications based on reviews, use test.each …
dependentmadani Sep 18, 2024
e14d948
update (parent note test): modification based on previous reviews
dependentmadani Sep 19, 2024
5c6cfc0
update (parent notes): few modification done, still work to be done
dependentmadani Sep 23, 2024
5bb6be5
update (note parents): fix the issue of tests, working good
dependentmadani Sep 24, 2024
fee9bbf
update (note parents): modification based on previous review, chore m…
dependentmadani Sep 26, 2024
d65c589
update (note parents tests): the issue of test failure is fixed
dependentmadani Sep 26, 2024
14234a1
udpate (note parents): based on last review
dependentmadani Sep 27, 2024
c09ad3a
Merge branch 'feat/return-note' of github.com:codex-team/notes.api in…
dependentmadani Sep 27, 2024
9872d5e
update (test cases): the issue is fixed due to missing an id
dependentmadani Sep 28, 2024
5a9fad2
update (test case): change the naming of a test case
dependentmadani Sep 29, 2024
4ccb075
update(note parents): based on last review, still work on sql
dependentmadani Oct 13, 2024
aa93ee2
update (parent note): add sql query to retrieve all the parents note …
dependentmadani Oct 15, 2024
ed49e60
update (note parents): only include the parents note without the main…
dependentmadani Oct 15, 2024
7bfe0eb
update (note parents): modify based on last review
dependentmadani Oct 16, 2024
dd1bcdc
update (note relation): return noteId and parentId from the sql query
dependentmadani Oct 16, 2024
92c8569
update (note parents): update the search of note ids to respect the o…
dependentmadani Oct 17, 2024
7efadf5
update (note parents): add comment about the query
dependentmadani Oct 22, 2024
47680d6
update (note parents): small modification of function description and…
dependentmadani Oct 24, 2024
31aeb92
remove (note parents test): an unecessary test case has been removed
dependentmadani Oct 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion docker-compose.yml
neSpecc marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: "3.2"
services:
api:
build:
Expand Down
2 changes: 1 addition & 1 deletion src/domain/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export function init(repositories: Repositories, appConfig: AppConfig): DomainSe
/**
* @todo use shared methods for uncoupling repositories unrelated to note service
*/
const noteService = new NoteService(repositories.noteRepository, repositories.noteRelationsRepository, repositories.noteVisitsRepository, repositories.editorToolsRepository, repositories.noteHistoryRepository);
const noteService = new NoteService(repositories.noteRepository, repositories.noteRelationsRepository, repositories.noteVisitsRepository, repositories.editorToolsRepository, repositories.noteHistoryRepository, repositories.teamRepository);
const noteVisitsService = new NoteVisitsService(repositories.noteVisitsRepository);
const authService = new AuthService(
appConfig.auth.accessSecret,
Expand Down
22 changes: 21 additions & 1 deletion src/domain/service/note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
}

/**
Expand Down Expand Up @@ -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.
neSpecc marked this conversation as resolved.
Show resolved Hide resolved
* @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[]> {
neSpecc marked this conversation as resolved.
Show resolved Hide resolved
return await this.noteRepository.getAllNotesParents(noteId, userId);
}
}
293 changes: 293 additions & 0 deletions src/presentation/http/router/note.test.ts
neSpecc marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
neSpecc marked this conversation as resolved.
Show resolved Hide resolved
],
});
});

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 ', () => {
Expand Down
Loading
Loading