42c9ae1ebc
# 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
18 lines
612 B
TypeScript
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']
|
|
)[];
|
|
};
|