Skip to content

The open alternative to Salesforce, designed for AI.

1.9 KB
Raw Blame
import { type FlatObjectMetadata } from 'src/engine/metadata-modules/flat-object-metadata/types/flat-object-metadata.type';
import { type ObjectMetadataDTO } from 'src/engine/metadata-modules/object-metadata/dtos/object-metadata.dto';
import { resolveEffectiveFlatEntityProperty } from 'src/engine/metadata-modules/overrides/utils/resolve-effective-flat-entity-property.util';

export const fromFlatObjectMetadataToObjectMetadataDto = (
  flatObjectMetadata: FlatObjectMetadata,
): ObjectMetadataDTO => {
  const {
    createdAt,
    updatedAt,
    color,
    description,
    icon,
    overrides,
    shortcut,
    duplicateCriteria,
    id,
    universalIdentifier,
    isLabelSyncedWithName,
    isRemote,
    isSearchable,
    openRecordIn,
    disabledObjectPermissionActions,
    isSystem,
    isAuditLogged,
    isUIEditable,
    isUICreatable,
    labelPlural,
    labelSingular,
    namePlural,
    nameSingular,
    workspaceId,
    imageIdentifierFieldMetadataId,
    labelIdentifierFieldMetadataId,
    applicationId,
  } = flatObjectMetadata;

  return {
    id,
    universalIdentifier,
    isActive: resolveEffectiveFlatEntityProperty({
      metadataName: 'objectMetadata',
      flatEntity: flatObjectMetadata,
      property: 'isActive',
    }),
    isLabelSyncedWithName,
    isRemote,
    isSearchable,
    openRecordIn,
    disabledObjectPermissionActions,
    isSystem,
    isAuditLogged,
    isUIEditable,
    isUICreatable,
    isUIReadOnly: !isUIEditable,
    labelPlural,
    labelSingular,
    namePlural,
    nameSingular,
    workspaceId,
    imageIdentifierFieldMetadataId,
    labelIdentifierFieldMetadataId,
    createdAt: new Date(createdAt),
    updatedAt: new Date(updatedAt),
    color: color ?? undefined,
    description: description ?? undefined,
    icon: icon ?? undefined,
    overrides: overrides ?? undefined,
    shortcut: shortcut ?? undefined,
    duplicateCriteria: duplicateCriteria ?? undefined,
    applicationId,
  };
};