All files / app/src/entities/files/lib get-file-from-files.ts

9.09% Statements 1/11
100% Branches 0/0
0% Functions 0/2
9.09% Lines 1/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16      1x                        
import { FileModel } from '@/shared/@types'
import { Nullable } from '@tmk/ui-kit'
 
export function getFileFromFiles(files?: FileModel[], id?: string): Nullable<FileModel> {
  if (!id || !files) return null
  const isIri = id.includes('files')
  const fileId = isIri ? extractId(id) : id
  const fileObject = files.find(file => file.id === fileId)
  if (!fileObject) return null
  return fileObject
}
 
function extractId(filePath: string): string {
  return filePath.split('/').pop() as string
}