From 42cb421410114668acaa6670c1f21a3d9cab81b4 Mon Sep 17 00:00:00 2001 From: dependentmadani Date: Fri, 6 Sep 2024 18:37:35 +0100 Subject: [PATCH] update: first part of modification after review --- docker-compose.yml | 2 +- src/domain/entities/note.ts | 11 +++++++++-- .../storage/postgres/orm/sequelize/teams.ts | 14 ++++++++------ src/repository/team.repository.ts | 4 ++-- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 3573148d..6c9aacf3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,3 @@ -version: "3.2" services: api: build: @@ -8,6 +7,7 @@ services: - 127.0.0.1:1337:1337 volumes: - ./app-config.yaml:/usr/app/app-config.yaml + - ./app-config.local.yaml:/usr/app/app-config.local.yaml restart: unless-stopped postgres: diff --git a/src/domain/entities/note.ts b/src/domain/entities/note.ts index fbae28a2..0537c851 100644 --- a/src/domain/entities/note.ts +++ b/src/domain/entities/note.ts @@ -84,9 +84,11 @@ export interface Note { export type NoteCreationAttributes = Pick; /** - * Represents the content of a parent note. + * This type represents only note's content + * Used for work with just note's content in web part + * This type would be used as a part of the structure, that represents all parent notes of the current note */ -export type NoteParentContent = { +export type NoteIdAndContent = { /** * Note public id */ @@ -97,3 +99,8 @@ export type NoteParentContent = { */ content: Note['content']; }; + +/** + * This type represents the structure, that represents all parent notes of the current note + */ +export type NoteParentsStructure = NoteIdAndContent[]; diff --git a/src/repository/storage/postgres/orm/sequelize/teams.ts b/src/repository/storage/postgres/orm/sequelize/teams.ts index 35cd005e..bce9855f 100644 --- a/src/repository/storage/postgres/orm/sequelize/teams.ts +++ b/src/repository/storage/postgres/orm/sequelize/teams.ts @@ -6,8 +6,9 @@ import type { Team, TeamMemberCreationAttributes, TeamMember } from '@domain/ent import { UserModel } from './user.js'; import { MemberRole } from '@domain/entities/team.js'; import type User from '@domain/entities/user.js'; -import type { NoteInternalId, NoteParentContent } from '@domain/entities/note.js'; +import type { NoteInternalId, NoteParentsStructure } from '@domain/entities/note.js'; import type { NoteRelationsModel } from './noteRelations.js'; +import { isEmpty } from '@infrastructure/utils/empty.js'; /** * Class representing a teams model in database @@ -226,17 +227,17 @@ export default class TeamsSequelizeStorage { * @param noteId - the ID of the note. * @param userId - the ID of the user. */ - public async getAllNoteParents(noteId: NoteInternalId, userId: number): Promise { + public async getAllNoteParents(noteId: NoteInternalId, userId: number): Promise { if (!this.noteModel || !this.noteRelationModel) { throw new Error(`${this.noteModel !== null ? 'TeamStorage: Note relation model is not defined' : 'TeamStorage: Note model is not defined'}`); } - const parentNotes: NoteParentContent[] = []; + const parentNotes: NoteParentsStructure = []; let currentNoteId: NoteInternalId | null = noteId; /** * Store notes that user can not access, to check the inherited team if has access */ - let storeUnaccessibleNote: NoteParentContent[] = []; + let storeUnaccessibleNote: NoteParentsStructure = []; while (currentNoteId != null) { const teamMember = await this.model.findOne({ @@ -248,10 +249,11 @@ export default class TeamsSequelizeStorage { model: this.noteModel, as: this.noteModel.tableName, required: true, + attributes: ['publicId', 'content'], }, }); - if (teamMember && teamMember.notes !== undefined && teamMember.notes !== null) { + if (teamMember && !isEmpty(teamMember.notes)) { if (storeUnaccessibleNote.length > 0) { parentNotes.push(...storeUnaccessibleNote); storeUnaccessibleNote = []; @@ -260,7 +262,7 @@ export default class TeamsSequelizeStorage { noteId: teamMember.notes.publicId, content: teamMember.notes.content, }); - } else { + } else if (teamMember === null) { const note = await this.noteModel.findOne({ where: { id: currentNoteId }, attributes: ['publicId', 'content'], diff --git a/src/repository/team.repository.ts b/src/repository/team.repository.ts index 4d7e7809..c426c35f 100644 --- a/src/repository/team.repository.ts +++ b/src/repository/team.repository.ts @@ -1,6 +1,6 @@ import type TeamStorage from '@repository/storage/team.storage.js'; import type { Team, TeamMember, TeamMemberCreationAttributes, MemberRole } from '@domain/entities/team.js'; -import type { NoteInternalId, NoteParentContent } from '@domain/entities/note.js'; +import type { NoteInternalId, NoteParentsStructure } from '@domain/entities/note.js'; import type User from '@domain/entities/user.js'; /** @@ -63,7 +63,7 @@ export default class TeamRepository { * @param userId : user id to check access * @returns an array of note parents objects containing public id and content */ - public async getAllNotesParents(noteId: NoteInternalId, userId: number): Promise { + public async getAllNotesParents(noteId: NoteInternalId, userId: number): Promise { return await this.storage.getAllNoteParents(noteId, userId); }