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(routes): get all notes by parent note id #282

Closed

Conversation

Tushar504
Copy link

@Tushar504 Tushar504 commented Nov 5, 2024

  • This PR adds the api endpoint and tests to get all notes by parent note as described in Issue Closes (First task): add GET all notes by parentNote endpoint #279 .
  • Added getNoteListByParentNote() method for NoteService
  • Added getNoteListByParentNote() method for NoteRepository
  • Added getNoteListByParentNote() method for NoteStorage
  • Updated getTeamMembersWithUserInfoByNoteId() method for teamStorage (to include UserId)
  • Added tests for the route

@Tushar504 Tushar504 requested a review from e11sy November 5, 2024 09:49
Copy link

github-actions bot commented Nov 5, 2024

Coverage Report

Status Category Percentage Covered / Total
🟢 Lines 86.14% (🎯 80%)
⬆️ +0.21%
8743 / 10149
🟢 Statements 86.14% (🎯 80%)
⬆️ +0.21%
8743 / 10149
🔴 Functions 79.47% (🎯 80%)
⬆️ +0.25%
271 / 341
🟢 Branches 85.38% (🎯 80%)
⬇️ -0.02%
438 / 513
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/domain/service/note.ts 96.17%
⬆️ +0.12%
85%
⬆️ +0.26%
100%
🟰 ±0%
96.17%
⬆️ +0.12%
99-100, 126-127, 138-139, 167-168, 189-190, 291-292, 380-381, 397-398, 439-440
src/presentation/http/http-api.ts 96.05%
⬆️ +0.01%
90.32%
🟰 ±0%
93.75%
🟰 ±0%
96.05%
⬆️ +0.01%
101-109, 120-121, 323-324, 347-348
src/presentation/http/router/noteList.ts 100%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
src/repository/index.ts 100%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
src/repository/note.repository.ts 100%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
src/repository/storage/postgres/orm/sequelize/note.ts 97.13%
⬇️ -0.57%
76%
⬇️ -4.00%
100%
🟰 ±0%
97.13%
⬇️ -0.57%
202-203, 246-247, 250-251, 306-307, 369-370, 373-374
src/repository/storage/postgres/orm/sequelize/teams.ts 99.17%
🟰 ±0%
85.71%
🟰 ±0%
100%
🟰 ±0%
99.17%
🟰 ±0%
190-191
Generated in workflow #863 for commit ad8b82b by the Vitest Coverage Report Action

Comment on lines 121 to 124
policy: [
'authRequired',
'notePublicOrUserInTeam',
],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

notePublicOrUserInTeam checks permission, for the note which is resolved by noteResolver. noteResolver resolves note by publicId, that means, that it checks for notePublicId field, your request would not have notePublicId so policy would return notAcceptable when note is not public

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i have updated the notResolver to consider parentId as well

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think that this is not a case for noteResolver usage, because in some case user can pass noteId and noteParentId in one request

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let me know, which policies required here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think that we should check it without policy and send reply.forbidden if user is not in team of the parent note

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

request you to review new changes

@@ -144,3 +144,130 @@ describe('GET /notes?page', () => {
}
});
});

describe('GET /notes/:parentNoteId?page', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no tests for userInTeam policy

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added tests, review it

src/presentation/http/router/noteList.ts Outdated Show resolved Hide resolved
Comment on lines +142 to 143
noteStorage.createAssociationWithNoteRelationsModel(noteRelationshipStorage.model);
noteRelationshipStorage.createAssociationWithNoteModel(noteStorage.model);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this line needed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need that association to use include clause(join table)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as i can see, we already linked noteRelationshipStorage with noteStorage

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should i implement this getNoteListByParentNote() method in noteRelationshipStorage

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, but do you actually need to make another assotiation in addition to the existing?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is required, i refered other relationships implemenation(noteVisits, noteSetting)

Comment on lines 376 to 397
const childNotes = await this.relationsModel.findAll({
where: { parentId },
attributes: ['noteId'],
});

const noteIds = childNotes.map(relation => relation.noteId);

const reply = await this.model.findAll({
where: {
id: {
[Op.in]: noteIds,
},
},
include: [{
model: this.settingsModel,
as: 'noteSettings',
attributes: ['cover'],
duplicating: false,
}],
offset,
limit,
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's better to do it via one request

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

request you review it

@Tushar504 Tushar504 changed the title 279 first task add get all notes by parentnote endpoint feat(routes): get all notes by parent note id Nov 6, 2024
@Tushar504 Tushar504 closed this Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(First task): add GET all notes by parentNote endpoint
2 participants