Skip to content

Commit

Permalink
fix: finish the review modifications
Browse files Browse the repository at this point in the history
  • Loading branch information
dependentmadani committed Sep 4, 2024
1 parent a5adcc2 commit bccf7b1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
4 changes: 0 additions & 4 deletions src/presentation/http/router/note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,6 @@ const NoteRouter: FastifyPluginCallback<NoteRouterOptions> = (fastify, opts, don
*/
const canEdit = memberRole === MemberRole.Write;

const noteParentContent = await noteService.getNoteParentStructure(noteId, userId!);

console.log('noteParentContent', noteParentContent);

return reply.send({
note: notePublic,
parentNote: parentNote,
Expand Down
21 changes: 20 additions & 1 deletion src/repository/storage/postgres/orm/sequelize/teams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,12 @@ export default class TeamsSequelizeStorage {

const parentNotes: NoteParentContent[] = [];
let currentNoteId: NoteInternalId | null = noteId;
/**
* Store notes that user can not access, to check the inherited team if has access
*/
let storeUnaccessibleNote: NoteParentContent[] = [];

while (currentNoteId != null) {
// Check if the user has access to the current note
const teamMember = await this.model.findOne({
where: {
noteId: currentNoteId,
Expand All @@ -249,10 +252,26 @@ export default class TeamsSequelizeStorage {
});

if (teamMember && teamMember.notes !== undefined && teamMember.notes !== null) {
if (storeUnaccessibleNote.length > 0) {
parentNotes.push(...storeUnaccessibleNote);
storeUnaccessibleNote = [];
}
parentNotes.push({
noteId: teamMember.notes.publicId,
content: teamMember.notes.content,
});
} else {
const note = await this.noteModel.findOne({
where: { id: currentNoteId },
attributes: ['publicId', 'content'],
});

if (note !== null) {
storeUnaccessibleNote.push({
noteId: note.publicId,
content: note.content,
});
}
}

// Retrieve the parent note
Expand Down

0 comments on commit bccf7b1

Please sign in to comment.