Files
twenty/packages/twenty-server/test/integration/metadata/suites/object-metadata/utils/create-relation-between-objects.util.ts
T
Paul RastoinandGitHub 47b60bd49f Deprecate FieldMetadataInterface (#13264)
# Introduction

From the moment replaced the FieldMetadataInterface definition to:
```ts
import { FieldMetadataType } from 'twenty-shared/types';

import { FieldMetadataEntity } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';

export type FieldMetadataInterface<
  T extends FieldMetadataType = FieldMetadataType,
> = FieldMetadataEntity<T>;
```
After this PR merge will create a new one removing the type and
replacing it to `FieldMetadataEntity`.
Did not renamed it here to avoid conflicts on naming + type issues fixs
within the same PR

## Field metadata entity RELATION or MORPH
Relations fields cannot be null for those field metadata entity instance
anymore, but are never for the others see
`packages/twenty-server/src/engine/metadata-modules/field-metadata/types/field-metadata-entity-test.type.ts`
( introduced TypeScript tests )

## Concerns
- TS_VECTOR is the most at risk with the `generatedType` and
`asExpression` removal from interface

## What's next
- `FielMetadataInterface` removal and rename ( see introduction )
- Depcrecating `ObjectMetadataInterface`
- Refactor `FieldMetadataEntity` optional fiels to be nullable only
- TO DIG `never` occurences on settings, defaultValue etc
- Some interfaces will be replaced by the `FlatFieldMetadata` when
deprecating the current sync and comparators tools
2025-07-21 11:30:18 +02:00

88 lines
2.5 KiB
TypeScript

import { CreateOneFieldFactoryInput } from 'test/integration/metadata/suites/field-metadata/utils/create-one-field-metadata-query-factory.util';
import { createOneFieldMetadata } from 'test/integration/metadata/suites/field-metadata/utils/create-one-field-metadata.util';
import { FieldMetadataType } from 'twenty-shared/types';
import { RelationType } from 'src/engine/metadata-modules/field-metadata/interfaces/relation-type.interface';
import { FieldMetadataDTO } from 'src/engine/metadata-modules/field-metadata/dtos/field-metadata.dto';
import { RelationDTO } from 'src/engine/metadata-modules/field-metadata/dtos/relation.dto';
export const createRelationBetweenObjects = async <
T extends FieldMetadataType.RELATION | FieldMetadataType.MORPH_RELATION,
>({
objectMetadataId,
targetObjectMetadataId,
type,
relationType,
name,
label,
isLabelSyncedWithName,
targetFieldLabel,
targetFieldIcon,
}: {
objectMetadataId: string;
targetObjectMetadataId: string;
type: T;
relationType: RelationType;
name?: string;
label?: string;
isLabelSyncedWithName?: boolean;
targetFieldLabel?: string;
targetFieldIcon?: string;
}) => {
const createFieldInput: CreateOneFieldFactoryInput = {
name: name || 'person',
label: label || 'person field',
type: type,
objectMetadataId: objectMetadataId,
isLabelSyncedWithName: isLabelSyncedWithName || false,
relationCreationPayload: {
targetObjectMetadataId: targetObjectMetadataId,
targetFieldLabel: targetFieldLabel || 'opportunity',
targetFieldIcon: targetFieldIcon || 'IconListOpportunity',
type: relationType,
},
};
const { data } = await createOneFieldMetadata<typeof type>({
input: createFieldInput,
gqlFields: `
id
name
label
isLabelSyncedWithName
settings
relation {
type
sourceObjectMetadata {
id
nameSingular
namePlural
}
targetObjectMetadata {
id
nameSingular
namePlural
}
sourceFieldMetadata {
id
name
}
targetFieldMetadata {
id
name
}
}
object {
id
nameSingular
}
`,
expectToFail: false,
});
return data.createOneField as unknown as FieldMetadataDTO<T> & {
relation: RelationDTO;
};
};