From 8e2b062ddbccd642fbe6e04b72b59a174c36adee Mon Sep 17 00:00:00 2001 From: migueldev01 Date: Mon, 22 Jan 2024 14:15:55 -0500 Subject: [PATCH] resolve comments about nitpicks --- .../application/FileFolderContainerDetector.ts | 13 +++++++++---- .../folders/application/FolderFinder.ts | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/context/virtual-drive/files/application/FileFolderContainerDetector.ts b/src/context/virtual-drive/files/application/FileFolderContainerDetector.ts index b9b2cd822..b27794f66 100644 --- a/src/context/virtual-drive/files/application/FileFolderContainerDetector.ts +++ b/src/context/virtual-drive/files/application/FileFolderContainerDetector.ts @@ -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( @@ -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; } } diff --git a/src/context/virtual-drive/folders/application/FolderFinder.ts b/src/context/virtual-drive/folders/application/FolderFinder.ts index 6db686c50..5aaae4d39 100644 --- a/src/context/virtual-drive/folders/application/FolderFinder.ts +++ b/src/context/virtual-drive/folders/application/FolderFinder.ts @@ -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');