Skip to content
Snippets Groups Projects
Select Git revision
  • 39de99511fb859b4a9aa16ad1bd9d80edcbe591c
  • main default protected
  • Issue/3192-gitlabTokenUpdateNotPossible
  • dev protected
  • Issue/3175-uiQuotaSettingAndDisplayBug
  • Issue/3090-tosProblems
  • Issue/3178-iconColorBug
  • Issue/3176-addNewNFDI4INGLogo
  • Issue/3141-rdsNoLonga
  • Issue/3180-fixMetadataNotLoading
  • Issue/3177-resourceTypeDescriptionTexts
  • Issue/3160-deactivateDownloadForFolders
  • Issue/3111-fixLoadingGitLabResource
  • Issue/3133-subProjectsChanges
  • Issue/3139-dsnrw
  • Issue/3167-changeTextAndAddLink
  • Issue/3070-newIconsForResourceTypes
  • Issue/3145-redesignLoginPage
  • Issue/3093-moreInformationInTheDeletionEmails
  • Issue/3040-closeTokenWindowWithXButton
  • Issue/3152-fixResourceStore
  • v3.19.1
  • v3.19.0
  • v3.18.0
  • v3.17.2
  • v3.17.1
  • v3.17.0
  • v3.16.1
  • v3.16.0
  • v3.15.6
  • v3.15.5
  • v3.15.4
  • v3.15.3
  • v3.15.2
  • v3.15.1
  • v3.15.0
  • v3.14.0
  • v3.13.1
  • v3.13.0
  • v3.12.0
  • v3.11.0
41 results

tree.ts

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    tree.ts 1.93 KiB
    import { MapperConfiguration, MappingPair } from "@dynamic-mapper/mapper";
    import { v4 as uuidv4 } from "uuid";
    
    import type {
      TreeDataType,
      FileTreeDto,
    } from "@coscine/api-client/dist/types/Coscine.Api";
    import type {
      FileInformation,
      FolderInformation,
    } from "@/modules/resource/types";
    
    export const TreeDto2FileInformation = new MappingPair<
      FileTreeDto,
      FileInformation
    >();
    
    export const TreeDto2FolderInformation = new MappingPair<
      FileTreeDto,
      FolderInformation
    >();
    
    const configuration = new MapperConfiguration((cfg) => {
      cfg.createMap(TreeDto2FileInformation, {
        id: (opt) => opt.mapFrom((_) => uuidv4()),
        name: (opt) => opt.mapFrom((dto) => dto.name ?? ""),
        parentDirectory: (opt) => opt.mapFrom((dto) => dto.directory ?? ""),
        path: (opt) => opt.mapFrom((dto) => dto.path ?? ""),
        type: (opt) => opt.mapFrom((_) => "Leaf" as TreeDataType.Leaf),
        isFolder: (opt) => opt.mapFrom((_) => false),
        createdAt: (opt) => opt.mapFrom((dto) => dto.creationDate ?? undefined),
        lastModified: (opt) => opt.mapFrom((dto) => dto.changeDate),
        size: (opt) => opt.mapFrom((dto) => dto.size ?? 0),
        version: (opt) => opt.mapFrom((_) => `${+new Date()}`),
        metadata: (opt) => opt.mapFrom((_) => null), // Set outside of the mapper
      });
    
      cfg.createMap(TreeDto2FolderInformation, {
        id: (opt) => opt.mapFrom((_) => uuidv4()),
        name: (opt) => opt.mapFrom((dto) => dto.name ?? ""),
        parentDirectory: (opt) => opt.mapFrom((dto) => dto.directory ?? ""),
        path: (opt) => opt.mapFrom((dto) => dto.path ?? ""),
        type: (opt) => opt.mapFrom((_) => "Tree" as TreeDataType.Tree),
        isFolder: (opt) => opt.mapFrom((_) => true),
        createdAt: (opt) => opt.mapFrom((dto) => dto.creationDate ?? undefined),
        lastModified: (opt) => opt.mapFrom((dto) => dto.changeDate),
        metadata: (opt) => opt.mapFrom((_) => null), // Set outside of the mapper
      });
    });
    
    export const treeMapper = configuration.createMapper();