fix: multiple twenty orm issues & show an example of use (#5439)
This PR is fixing some issues and adding enhancement in TwentyORM: - [x] Composite fields in nested relations are not formatted properly - [x] Passing operators like `Any` in `where` condition is breaking the query - [x] Ability to auto load workspace-entities based on a regex path I've also introduced an example of use for `CalendarEventService`: https://github.com/twentyhq/twenty/pull/5439/files#diff-3a7dffc0dea57345d10e70c648e911f98fe237248bcea124dafa9c8deb1db748R15
This commit is contained in:
@ -0,0 +1,96 @@
|
||||
import { Relation } from 'src/engine/workspace-manager/workspace-sync-metadata/interfaces/relation.interface';
|
||||
|
||||
import { ACTIVITY_TARGET_STANDARD_FIELD_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids';
|
||||
import { STANDARD_OBJECT_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-ids';
|
||||
import { CustomWorkspaceEntity } from 'src/engine/twenty-orm/custom.workspace-entity';
|
||||
import { ActivityWorkspaceEntity } from 'src/modules/activity/standard-objects/activity.workspace-entity';
|
||||
import { CompanyWorkspaceEntity } from 'src/modules/company/standard-objects/company.workspace-entity';
|
||||
import { OpportunityWorkspaceEntity } from 'src/modules/opportunity/standard-objects/opportunity.workspace-entity';
|
||||
import { PersonWorkspaceEntity } from 'src/modules/person/standard-objects/person.workspace-entity';
|
||||
import { WorkspaceEntity } from 'src/engine/twenty-orm/decorators/workspace-entity.decorator';
|
||||
import { WorkspaceIsSystem } from 'src/engine/twenty-orm/decorators/workspace-is-system.decorator';
|
||||
import { WorkspaceIsNotAuditLogged } from 'src/engine/twenty-orm/decorators/workspace-is-not-audit-logged.decorator';
|
||||
import { WorkspaceIsNullable } from 'src/engine/twenty-orm/decorators/workspace-is-nullable.decorator';
|
||||
import { WorkspaceDynamicRelation } from 'src/engine/twenty-orm/decorators/workspace-dynamic-relation.decorator';
|
||||
import { RelationMetadataType } from 'src/engine/metadata-modules/relation-metadata/relation-metadata.entity';
|
||||
import { WorkspaceRelation } from 'src/engine/twenty-orm/decorators/workspace-relation.decorator';
|
||||
import { BaseWorkspaceEntity } from 'src/engine/twenty-orm/base.workspace-entity';
|
||||
|
||||
@WorkspaceEntity({
|
||||
standardId: STANDARD_OBJECT_IDS.activityTarget,
|
||||
namePlural: 'activityTargets',
|
||||
labelSingular: 'Activity Target',
|
||||
labelPlural: 'Activity Targets',
|
||||
description: 'An activity target',
|
||||
icon: 'IconCheckbox',
|
||||
})
|
||||
@WorkspaceIsSystem()
|
||||
@WorkspaceIsNotAuditLogged()
|
||||
export class ActivityTargetWorkspaceEntity extends BaseWorkspaceEntity {
|
||||
@WorkspaceRelation({
|
||||
standardId: ACTIVITY_TARGET_STANDARD_FIELD_IDS.activity,
|
||||
type: RelationMetadataType.MANY_TO_ONE,
|
||||
label: 'Activity',
|
||||
description: 'ActivityTarget activity',
|
||||
icon: 'IconNotes',
|
||||
joinColumn: 'activityId',
|
||||
inverseSideTarget: () => ActivityWorkspaceEntity,
|
||||
inverseSideFieldKey: 'activityTargets',
|
||||
})
|
||||
@WorkspaceIsNullable()
|
||||
activity: Relation<ActivityWorkspaceEntity>;
|
||||
|
||||
@WorkspaceRelation({
|
||||
standardId: ACTIVITY_TARGET_STANDARD_FIELD_IDS.person,
|
||||
type: RelationMetadataType.MANY_TO_ONE,
|
||||
label: 'Person',
|
||||
description: 'ActivityTarget person',
|
||||
icon: 'IconUser',
|
||||
joinColumn: 'personId',
|
||||
inverseSideTarget: () => PersonWorkspaceEntity,
|
||||
inverseSideFieldKey: 'activityTargets',
|
||||
})
|
||||
@WorkspaceIsNullable()
|
||||
person: Relation<PersonWorkspaceEntity>;
|
||||
|
||||
@WorkspaceRelation({
|
||||
standardId: ACTIVITY_TARGET_STANDARD_FIELD_IDS.company,
|
||||
type: RelationMetadataType.MANY_TO_ONE,
|
||||
label: 'Company',
|
||||
description: 'ActivityTarget company',
|
||||
icon: 'IconBuildingSkyscraper',
|
||||
joinColumn: 'companyId',
|
||||
inverseSideTarget: () => CompanyWorkspaceEntity,
|
||||
inverseSideFieldKey: 'activityTargets',
|
||||
})
|
||||
@WorkspaceIsNullable()
|
||||
company: Relation<CompanyWorkspaceEntity>;
|
||||
|
||||
@WorkspaceRelation({
|
||||
standardId: ACTIVITY_TARGET_STANDARD_FIELD_IDS.opportunity,
|
||||
type: RelationMetadataType.MANY_TO_ONE,
|
||||
label: 'Opportunity',
|
||||
description: 'ActivityTarget opportunity',
|
||||
icon: 'IconTargetArrow',
|
||||
joinColumn: 'opportunityId',
|
||||
inverseSideTarget: () => OpportunityWorkspaceEntity,
|
||||
inverseSideFieldKey: 'activityTargets',
|
||||
})
|
||||
@WorkspaceIsNullable()
|
||||
opportunity: Relation<OpportunityWorkspaceEntity>;
|
||||
|
||||
@WorkspaceDynamicRelation({
|
||||
type: RelationMetadataType.MANY_TO_ONE,
|
||||
argsFactory: (oppositeObjectMetadata) => ({
|
||||
standardId: ACTIVITY_TARGET_STANDARD_FIELD_IDS.custom,
|
||||
name: oppositeObjectMetadata.nameSingular,
|
||||
label: oppositeObjectMetadata.labelSingular,
|
||||
description: `ActivityTarget ${oppositeObjectMetadata.labelSingular}`,
|
||||
joinColumn: `${oppositeObjectMetadata.nameSingular}Id`,
|
||||
icon: 'IconBuildingSkyscraper',
|
||||
}),
|
||||
inverseSideTarget: () => CustomWorkspaceEntity,
|
||||
inverseSideFieldKey: 'activityTargets',
|
||||
})
|
||||
custom: Relation<CustomWorkspaceEntity>;
|
||||
}
|
||||
Reference in New Issue
Block a user