2024-02-15 04:48:48 -05:00
|
|
|
import { findInTree } from '../util/find-in-tree'
|
|
|
|
import { Folder } from '../../../../../types/folder'
|
|
|
|
import { Doc } from '../../../../../types/doc'
|
|
|
|
import { FileRef } from '../../../../../types/file-ref'
|
|
|
|
|
|
|
|
export function isNameUniqueInFolder(
|
|
|
|
tree: Folder,
|
|
|
|
parentFolderId: string,
|
|
|
|
name: string
|
|
|
|
): boolean {
|
2024-07-24 09:38:51 -04:00
|
|
|
return !(
|
|
|
|
findFileByNameInFolder(tree, parentFolderId, name) ||
|
|
|
|
findFolderByNameInFolder(tree, parentFolderId, name)
|
|
|
|
)
|
2024-02-15 04:48:48 -05:00
|
|
|
}
|
|
|
|
|
2024-07-24 09:38:51 -04:00
|
|
|
export function findFileByNameInFolder(
|
2024-02-15 04:48:48 -05:00
|
|
|
tree: Folder,
|
|
|
|
parentFolderId: string,
|
|
|
|
name: string
|
2024-07-24 09:38:51 -04:00
|
|
|
): Doc | FileRef | undefined {
|
2024-02-15 04:48:48 -05:00
|
|
|
if (tree._id !== parentFolderId) {
|
|
|
|
tree = findInTree(tree, parentFolderId).entity
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
tree.docs.find(entity => entity.name === name) ||
|
2024-07-24 09:38:51 -04:00
|
|
|
tree.fileRefs.find(entity => entity.name === name)
|
2024-02-15 04:48:48 -05:00
|
|
|
)
|
|
|
|
}
|
2024-07-24 09:38:51 -04:00
|
|
|
|
|
|
|
export function findFolderByNameInFolder(
|
|
|
|
tree: Folder,
|
|
|
|
parentFolderId: string,
|
|
|
|
name: string
|
|
|
|
): Folder | undefined {
|
|
|
|
if (tree._id !== parentFolderId) {
|
|
|
|
tree = findInTree(tree, parentFolderId).entity
|
|
|
|
}
|
|
|
|
|
|
|
|
return tree.folders.find(entity => entity.name === name)
|
|
|
|
}
|