Skip to content

Commit

Permalink
update: first part of modification after review
Browse files Browse the repository at this point in the history
  • Loading branch information
dependentmadani committed Sep 6, 2024
1 parent bccf7b1 commit 42cb421
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: "3.2"
services:
api:
build:
Expand All @@ -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:
Expand Down
11 changes: 9 additions & 2 deletions src/domain/entities/note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,11 @@ export interface Note {
export type NoteCreationAttributes = Pick<Note, 'publicId' | 'content' | 'creatorId' | 'tools'>;

/**
* 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
*/
Expand All @@ -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[];
14 changes: 8 additions & 6 deletions src/repository/storage/postgres/orm/sequelize/teams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<NoteParentContent[]> {
public async getAllNoteParents(noteId: NoteInternalId, userId: number): Promise<NoteParentsStructure> {
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({
Expand All @@ -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 = [];
Expand All @@ -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'],
Expand Down
4 changes: 2 additions & 2 deletions src/repository/team.repository.ts
Original file line number Diff line number Diff line change
@@ -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';

/**
Expand Down Expand Up @@ -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<NoteParentContent[]> {
public async getAllNotesParents(noteId: NoteInternalId, userId: number): Promise<NoteParentsStructure> {
return await this.storage.getAllNoteParents(noteId, userId);
}

Expand Down

0 comments on commit 42cb421

Please sign in to comment.