Skip to content

Commit

Permalink
**smeller code **rollback master-erb
Browse files Browse the repository at this point in the history
  • Loading branch information
migueldesarrollosoftware committed Feb 9, 2024
1 parent 6d1cb35 commit e5d858a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
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
4 changes: 4 additions & 0 deletions src/context/virtual-drive/shared/domain/DelayQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit e5d858a

Please sign in to comment.