Skip to content

Commit

Permalink
resolve comments about nitpicks
Browse files Browse the repository at this point in the history
  • Loading branch information
migueldesarrollosoftware committed Jan 22, 2024
1 parent 871505f commit 8e2b062
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { FolderFinder } from '../../folders/application/FolderFinder';
import { File } from '../../files/domain/File';
import { Folder } from '../../folders/domain/Folder';
import { FileRepository } from '../domain/FileRepository';
import { FileNotFoundError } from '../domain/errors/FileNotFoundError';

export class FileFolderContainerDetector {
constructor(
Expand All @@ -10,9 +11,13 @@ export class FileFolderContainerDetector {
) {}

run(contentId: File['contentsId'], folderContentId: Folder['uuid']): boolean {
const file = this.repository.searchByPartial({ contentsId: contentId });
const folder = this.folderFinder.findFromId(file?.folderId);
const [_, folderUuid] = folder.placeholderId.split(':');
return folderUuid === folderContentId;
const file = this.repository.searchByPartial({
contentsId: contentId,
});
if (!file) {
throw new FileNotFoundError(contentId);
}
const folder = this.folderFinder.findFromId(file.folderId);
return folder.uuid === folderContentId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class FolderFinder {
return folder;
}

findFromId(id: Folder['id'] | undefined): Folder {
findFromId(id: Folder['id']): Folder {
const folder = this.repository.searchByPartial({ id });
if (!folder) {
throw new Error('Folder not found');
Expand Down

0 comments on commit 8e2b062

Please sign in to comment.