From e5d858aebcb42aa411ae3a9879a53cedb33e160f Mon Sep 17 00:00:00 2001 From: migueldev01 Date: Thu, 8 Feb 2024 23:19:01 -0500 Subject: [PATCH] **smeller code **rollback master-erb --- .../controllers/DeleteController.ts | 3 +-- .../application/FileFolderContainerDetector.ts | 13 +++++++++---- .../folders/application/FolderFinder.ts | 2 +- .../virtual-drive/shared/domain/DelayQueue.ts | 4 ++++ 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/apps/sync-engine/callbacks-controllers/controllers/DeleteController.ts b/src/apps/sync-engine/callbacks-controllers/controllers/DeleteController.ts index f6be1e79d..defc439df 100644 --- a/src/apps/sync-engine/callbacks-controllers/controllers/DeleteController.ts +++ b/src/apps/sync-engine/callbacks-controllers/controllers/DeleteController.ts @@ -89,8 +89,7 @@ export class DeleteController extends CallbackController { } private CleanQueueFolder(folderUuid: Folder['uuid']) { - const folders = this.foldersQueue.values; - const reversedFolders = folders.reverse(); + const reversedFolders = this.foldersQueue.reversedValues; reversedFolders.forEach((folder) => { const isParentFolder = this.folderContainerDetector.run( folder, 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'); diff --git a/src/context/virtual-drive/shared/domain/DelayQueue.ts b/src/context/virtual-drive/shared/domain/DelayQueue.ts index 19b31f561..63f17a6e8 100644 --- a/src/context/virtual-drive/shared/domain/DelayQueue.ts +++ b/src/context/virtual-drive/shared/domain/DelayQueue.ts @@ -68,6 +68,10 @@ export class DelayQueue { return Array.from(this.queue.keys()); } + get reversedValues(): string[] { + return Array.from(this.queue.keys()).reverse(); + } + get isEmpty(): boolean { return this.queue.size === 0; }