## Context ObjectMetadataService became quite large and handles too many responsibilities. I'm trying to refactor a bit this part in preparation of a larger work that will combine object-metadata services and sync-metadata logic - Created a STANDARD_OBJECT_ICONS that can be reused in relation creation to refer to a standard object icon. - Created a STANDARD_OBJECT_FIELD_IDS that can be used with an object name to get its standard field ids. - Moved migration, record and relation creations to dedicated services, refactored to improve performances and readability - Refactored some validation logic --------- Co-authored-by: Charles Bochet <charles@twenty.com>
64 lines
2.8 KiB
TypeScript
64 lines
2.8 KiB
TypeScript
import { Relation } from 'src/engine/workspace-manager/workspace-sync-metadata/interfaces/relation.interface';
|
|
|
|
import { FieldMetadataType } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
|
|
import { RelationMetadataType } from 'src/engine/metadata-modules/relation-metadata/relation-metadata.entity';
|
|
import { BaseWorkspaceEntity } from 'src/engine/twenty-orm/base.workspace-entity';
|
|
import { WorkspaceEntity } from 'src/engine/twenty-orm/decorators/workspace-entity.decorator';
|
|
import { WorkspaceField } from 'src/engine/twenty-orm/decorators/workspace-field.decorator';
|
|
import { WorkspaceIsSystem } from 'src/engine/twenty-orm/decorators/workspace-is-system.decorator';
|
|
import { WorkspaceJoinColumn } from 'src/engine/twenty-orm/decorators/workspace-join-column.decorator';
|
|
import { WorkspaceRelation } from 'src/engine/twenty-orm/decorators/workspace-relation.decorator';
|
|
import { COMMENT_STANDARD_FIELD_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids';
|
|
import { STANDARD_OBJECT_ICONS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-icons';
|
|
import { STANDARD_OBJECT_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-ids';
|
|
import { ActivityWorkspaceEntity } from 'src/modules/activity/standard-objects/activity.workspace-entity';
|
|
import { WorkspaceMemberWorkspaceEntity } from 'src/modules/workspace-member/standard-objects/workspace-member.workspace-entity';
|
|
|
|
@WorkspaceEntity({
|
|
standardId: STANDARD_OBJECT_IDS.comment,
|
|
namePlural: 'comments',
|
|
labelSingular: 'Comment',
|
|
labelPlural: 'Comments',
|
|
description: 'A comment',
|
|
icon: STANDARD_OBJECT_ICONS.comment,
|
|
})
|
|
@WorkspaceIsSystem()
|
|
export class CommentWorkspaceEntity extends BaseWorkspaceEntity {
|
|
@WorkspaceField({
|
|
standardId: COMMENT_STANDARD_FIELD_IDS.body,
|
|
type: FieldMetadataType.TEXT,
|
|
label: 'Body',
|
|
description: 'Comment body',
|
|
icon: 'IconLink',
|
|
})
|
|
body: string;
|
|
|
|
@WorkspaceRelation({
|
|
standardId: COMMENT_STANDARD_FIELD_IDS.author,
|
|
type: RelationMetadataType.MANY_TO_ONE,
|
|
label: 'Author',
|
|
description: 'Comment author',
|
|
icon: 'IconCircleUser',
|
|
inverseSideTarget: () => WorkspaceMemberWorkspaceEntity,
|
|
inverseSideFieldKey: 'authoredComments',
|
|
})
|
|
author: Relation<WorkspaceMemberWorkspaceEntity>;
|
|
|
|
@WorkspaceJoinColumn('author')
|
|
authorId: string;
|
|
|
|
@WorkspaceRelation({
|
|
standardId: COMMENT_STANDARD_FIELD_IDS.activity,
|
|
type: RelationMetadataType.MANY_TO_ONE,
|
|
label: 'Activity',
|
|
description: 'Comment activity',
|
|
icon: 'IconNotes',
|
|
inverseSideTarget: () => ActivityWorkspaceEntity,
|
|
inverseSideFieldKey: 'comments',
|
|
})
|
|
activity: Relation<ActivityWorkspaceEntity>;
|
|
|
|
@WorkspaceJoinColumn('activity')
|
|
activityId: string;
|
|
}
|