Files
twenty/packages/twenty-server/src/engine/metadata-modules/flat-entity/utils/get-metadata-entity-relation-properties.util.ts
T
Paul Rastoin 42c9ae1ebc Centralize metadata relations constant + simplification (#16901)
# Introduction
As we introduced a new grain on relation extraction thanks to low level
`SyncableEntity` and `WorkspaceRelatedEntity` we're able to strictly
typesafe extract metadata entity

The new constant centralizes both many to one and one to many constants
metadata entity constants in a more strictly typesafe way. Remains only
the flatEntityForeignKey aggregator which has to be chosen manually
across all available targeted flat entity ids properties
2026-01-02 16:49:06 +01:00

18 lines
612 B
TypeScript

import { type AllMetadataName } from 'twenty-shared/metadata';
import { ALL_METADATA_RELATIONS } from 'src/engine/metadata-modules/flat-entity/constant/all-metadata-relations.constant';
export const getMetadataEntityRelationProperties = <T extends AllMetadataName>(
metadataName: T,
) => {
const relationProperties = ALL_METADATA_RELATIONS[metadataName];
return [
...Object.keys(relationProperties.manyToOne),
...Object.keys(relationProperties.oneToMany),
] as (
| keyof (typeof ALL_METADATA_RELATIONS)[T]['manyToOne']
| keyof (typeof ALL_METADATA_RELATIONS)[T]['oneToMany']
)[];
};