Files
twenty_crm/packages/twenty-server/src/modules/activity/standard-objects/comment.workspace-entity.ts
Jérémy M 8b5f79ddbf 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
2024-05-20 11:01:47 +02:00

60 lines
2.6 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 { COMMENT_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 { ActivityWorkspaceEntity } from 'src/modules/activity/standard-objects/activity.workspace-entity';
import { WorkspaceMemberWorkspaceEntity } from 'src/modules/workspace-member/standard-objects/workspace-member.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 { 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 { BaseWorkspaceEntity } from 'src/engine/twenty-orm/base.workspace-entity';
@WorkspaceEntity({
standardId: STANDARD_OBJECT_IDS.comment,
namePlural: 'comments',
labelSingular: 'Comment',
labelPlural: 'Comments',
description: 'A comment',
icon: 'IconMessageCircle',
})
@WorkspaceIsSystem()
@WorkspaceIsNotAuditLogged()
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',
joinColumn: 'authorId',
inverseSideTarget: () => WorkspaceMemberWorkspaceEntity,
inverseSideFieldKey: 'authoredComments',
})
author: Relation<WorkspaceMemberWorkspaceEntity>;
@WorkspaceRelation({
standardId: COMMENT_STANDARD_FIELD_IDS.activity,
type: RelationMetadataType.MANY_TO_ONE,
label: 'Activity',
description: 'Comment activity',
icon: 'IconNotes',
joinColumn: 'activityId',
inverseSideTarget: () => ActivityWorkspaceEntity,
inverseSideFieldKey: 'comments',
})
activity: Relation<ActivityWorkspaceEntity>;
}