feat: twenty orm sync (#5266)
This PR is updating all object metadata entities with the new decorators, and deleting the old ones. This way we can use the new TwentyORM with all the standard objects. --------- Co-authored-by: Weiko <corentin@twenty.com>
This commit is contained in:
@ -3,21 +3,23 @@ import { Relation } from 'src/engine/workspace-manager/workspace-sync-metadata/i
|
||||
import { FieldMetadataType } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
|
||||
import { ATTACHMENT_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 { CustomObjectMetadata } from 'src/engine/workspace-manager/workspace-sync-metadata/custom-objects/custom.object-metadata';
|
||||
import { DynamicRelationFieldMetadata } from 'src/engine/workspace-manager/workspace-sync-metadata/decorators/dynamic-field-metadata.interface';
|
||||
import { FieldMetadata } from 'src/engine/workspace-manager/workspace-sync-metadata/decorators/field-metadata.decorator';
|
||||
import { IsNullable } from 'src/engine/workspace-manager/workspace-sync-metadata/decorators/is-nullable.decorator';
|
||||
import { IsSystem } from 'src/engine/workspace-manager/workspace-sync-metadata/decorators/is-system.decorator';
|
||||
import { ObjectMetadata } from 'src/engine/workspace-manager/workspace-sync-metadata/decorators/object-metadata.decorator';
|
||||
import { CustomWorkspaceEntity } from 'src/engine/twenty-orm/custom.workspace-entity';
|
||||
import { ActivityObjectMetadata } from 'src/modules/activity/standard-objects/activity.object-metadata';
|
||||
import { BaseObjectMetadata } from 'src/engine/workspace-manager/workspace-sync-metadata/standard-objects/base.object-metadata';
|
||||
import { CompanyObjectMetadata } from 'src/modules/company/standard-objects/company.object-metadata';
|
||||
import { OpportunityObjectMetadata } from 'src/modules/opportunity/standard-objects/opportunity.object-metadata';
|
||||
import { PersonObjectMetadata } from 'src/modules/person/standard-objects/person.object-metadata';
|
||||
import { WorkspaceMemberObjectMetadata } from 'src/modules/workspace-member/standard-objects/workspace-member.object-metadata';
|
||||
import { IsNotAuditLogged } from 'src/engine/workspace-manager/workspace-sync-metadata/decorators/is-not-audit-logged.decorator';
|
||||
import { WorkspaceEntity } from 'src/engine/twenty-orm/decorators/workspace-object.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 { WorkspaceField } from 'src/engine/twenty-orm/decorators/workspace-field.decorator';
|
||||
import { WorkspaceRelation } from 'src/engine/twenty-orm/decorators/workspace-relation.decorator';
|
||||
import { RelationMetadataType } from 'src/engine/metadata-modules/relation-metadata/relation-metadata.entity';
|
||||
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 { BaseWorkspaceEntity } from 'src/engine/twenty-orm/base.workspace-entity';
|
||||
|
||||
@ObjectMetadata({
|
||||
@WorkspaceEntity({
|
||||
standardId: STANDARD_OBJECT_IDS.attachment,
|
||||
namePlural: 'attachments',
|
||||
labelSingular: 'Attachment',
|
||||
@ -25,10 +27,10 @@ import { IsNotAuditLogged } from 'src/engine/workspace-manager/workspace-sync-me
|
||||
description: 'An attachment',
|
||||
icon: 'IconFileImport',
|
||||
})
|
||||
@IsSystem()
|
||||
@IsNotAuditLogged()
|
||||
export class AttachmentObjectMetadata extends BaseObjectMetadata {
|
||||
@FieldMetadata({
|
||||
@WorkspaceIsSystem()
|
||||
@WorkspaceIsNotAuditLogged()
|
||||
export class AttachmentObjectMetadata extends BaseWorkspaceEntity {
|
||||
@WorkspaceField({
|
||||
standardId: ATTACHMENT_STANDARD_FIELD_IDS.name,
|
||||
type: FieldMetadataType.TEXT,
|
||||
label: 'Name',
|
||||
@ -37,7 +39,7 @@ export class AttachmentObjectMetadata extends BaseObjectMetadata {
|
||||
})
|
||||
name: string;
|
||||
|
||||
@FieldMetadata({
|
||||
@WorkspaceField({
|
||||
standardId: ATTACHMENT_STANDARD_FIELD_IDS.fullPath,
|
||||
type: FieldMetadataType.TEXT,
|
||||
label: 'Full path',
|
||||
@ -46,7 +48,7 @@ export class AttachmentObjectMetadata extends BaseObjectMetadata {
|
||||
})
|
||||
fullPath: string;
|
||||
|
||||
@FieldMetadata({
|
||||
@WorkspaceField({
|
||||
standardId: ATTACHMENT_STANDARD_FIELD_IDS.type,
|
||||
type: FieldMetadataType.TEXT,
|
||||
label: 'Type',
|
||||
@ -55,67 +57,82 @@ export class AttachmentObjectMetadata extends BaseObjectMetadata {
|
||||
})
|
||||
type: string;
|
||||
|
||||
@FieldMetadata({
|
||||
@WorkspaceRelation({
|
||||
standardId: ATTACHMENT_STANDARD_FIELD_IDS.author,
|
||||
type: FieldMetadataType.RELATION,
|
||||
type: RelationMetadataType.MANY_TO_ONE,
|
||||
label: 'Author',
|
||||
description: 'Attachment author',
|
||||
icon: 'IconCircleUser',
|
||||
joinColumn: 'authorId',
|
||||
inverseSideTarget: () => WorkspaceMemberObjectMetadata,
|
||||
inverseSideFieldKey: 'authoredAttachments',
|
||||
})
|
||||
author: Relation<WorkspaceMemberObjectMetadata>;
|
||||
|
||||
@FieldMetadata({
|
||||
@WorkspaceRelation({
|
||||
standardId: ATTACHMENT_STANDARD_FIELD_IDS.activity,
|
||||
type: FieldMetadataType.RELATION,
|
||||
type: RelationMetadataType.MANY_TO_ONE,
|
||||
label: 'Activity',
|
||||
description: 'Attachment activity',
|
||||
icon: 'IconNotes',
|
||||
joinColumn: 'activityId',
|
||||
inverseSideTarget: () => ActivityObjectMetadata,
|
||||
inverseSideFieldKey: 'attachments',
|
||||
})
|
||||
@IsNullable()
|
||||
@WorkspaceIsNullable()
|
||||
activity: Relation<ActivityObjectMetadata>;
|
||||
|
||||
@FieldMetadata({
|
||||
@WorkspaceRelation({
|
||||
standardId: ATTACHMENT_STANDARD_FIELD_IDS.person,
|
||||
type: FieldMetadataType.RELATION,
|
||||
type: RelationMetadataType.MANY_TO_ONE,
|
||||
label: 'Person',
|
||||
description: 'Attachment person',
|
||||
icon: 'IconUser',
|
||||
joinColumn: 'personId',
|
||||
inverseSideTarget: () => PersonObjectMetadata,
|
||||
inverseSideFieldKey: 'attachments',
|
||||
})
|
||||
@IsNullable()
|
||||
@WorkspaceIsNullable()
|
||||
person: Relation<PersonObjectMetadata>;
|
||||
|
||||
@FieldMetadata({
|
||||
@WorkspaceRelation({
|
||||
standardId: ATTACHMENT_STANDARD_FIELD_IDS.company,
|
||||
type: FieldMetadataType.RELATION,
|
||||
type: RelationMetadataType.MANY_TO_ONE,
|
||||
label: 'Company',
|
||||
description: 'Attachment company',
|
||||
icon: 'IconBuildingSkyscraper',
|
||||
joinColumn: 'companyId',
|
||||
inverseSideTarget: () => CompanyObjectMetadata,
|
||||
inverseSideFieldKey: 'attachments',
|
||||
})
|
||||
@IsNullable()
|
||||
@WorkspaceIsNullable()
|
||||
company: Relation<CompanyObjectMetadata>;
|
||||
|
||||
@FieldMetadata({
|
||||
@WorkspaceRelation({
|
||||
standardId: ATTACHMENT_STANDARD_FIELD_IDS.opportunity,
|
||||
type: FieldMetadataType.RELATION,
|
||||
type: RelationMetadataType.MANY_TO_ONE,
|
||||
label: 'Opportunity',
|
||||
description: 'Attachment opportunity',
|
||||
icon: 'IconBuildingSkyscraper',
|
||||
joinColumn: 'opportunityId',
|
||||
inverseSideTarget: () => OpportunityObjectMetadata,
|
||||
inverseSideFieldKey: 'attachments',
|
||||
})
|
||||
@IsNullable()
|
||||
@WorkspaceIsNullable()
|
||||
opportunity: Relation<OpportunityObjectMetadata>;
|
||||
|
||||
@DynamicRelationFieldMetadata((oppositeObjectMetadata) => ({
|
||||
standardId: ATTACHMENT_STANDARD_FIELD_IDS.custom,
|
||||
name: oppositeObjectMetadata.nameSingular,
|
||||
label: oppositeObjectMetadata.labelSingular,
|
||||
description: `Attachment ${oppositeObjectMetadata.labelSingular}`,
|
||||
joinColumn: `${oppositeObjectMetadata.nameSingular}Id`,
|
||||
icon: 'IconBuildingSkyscraper',
|
||||
}))
|
||||
custom: Relation<CustomObjectMetadata>;
|
||||
@WorkspaceDynamicRelation({
|
||||
type: RelationMetadataType.MANY_TO_ONE,
|
||||
argsFactory: (oppositeObjectMetadata) => ({
|
||||
standardId: ATTACHMENT_STANDARD_FIELD_IDS.custom,
|
||||
name: oppositeObjectMetadata.nameSingular,
|
||||
label: oppositeObjectMetadata.labelSingular,
|
||||
description: `Attachment ${oppositeObjectMetadata.labelSingular}`,
|
||||
joinColumn: `${oppositeObjectMetadata.nameSingular}Id`,
|
||||
icon: 'IconBuildingSkyscraper',
|
||||
}),
|
||||
inverseSideTarget: () => CustomWorkspaceEntity,
|
||||
inverseSideFieldKey: 'attachments',
|
||||
})
|
||||
custom: Relation<CustomWorkspaceEntity>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user