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>
123 lines
4.7 KiB
TypeScript
123 lines
4.7 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,
|
|
RelationOnDeleteAction,
|
|
} from 'src/engine/metadata-modules/relation-metadata/relation-metadata.entity';
|
|
import { MESSAGE_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 { MessageChannelMessageAssociationObjectMetadata } from 'src/modules/messaging/standard-objects/message-channel-message-association.object-metadata';
|
|
import { MessageParticipantObjectMetadata } from 'src/modules/messaging/standard-objects/message-participant.object-metadata';
|
|
import { MessageThreadObjectMetadata } from 'src/modules/messaging/standard-objects/message-thread.object-metadata';
|
|
import { BaseWorkspaceEntity } from 'src/engine/twenty-orm/base.workspace-entity';
|
|
import { WorkspaceEntity } from 'src/engine/twenty-orm/decorators/workspace-object.decorator';
|
|
import { WorkspaceIsNotAuditLogged } from 'src/engine/twenty-orm/decorators/workspace-is-not-audit-logged.decorator';
|
|
import { WorkspaceIsSystem } from 'src/engine/twenty-orm/decorators/workspace-is-system.decorator';
|
|
import { WorkspaceField } from 'src/engine/twenty-orm/decorators/workspace-field.decorator';
|
|
import { WorkspaceIsNullable } from 'src/engine/twenty-orm/decorators/workspace-is-nullable.decorator';
|
|
import { WorkspaceRelation } from 'src/engine/twenty-orm/decorators/workspace-relation.decorator';
|
|
|
|
@WorkspaceEntity({
|
|
standardId: STANDARD_OBJECT_IDS.message,
|
|
namePlural: 'messages',
|
|
labelSingular: 'Message',
|
|
labelPlural: 'Messages',
|
|
description: 'Message',
|
|
icon: 'IconMessage',
|
|
})
|
|
@WorkspaceIsNotAuditLogged()
|
|
@WorkspaceIsSystem()
|
|
export class MessageObjectMetadata extends BaseWorkspaceEntity {
|
|
@WorkspaceField({
|
|
standardId: MESSAGE_STANDARD_FIELD_IDS.headerMessageId,
|
|
type: FieldMetadataType.TEXT,
|
|
label: 'Header message Id',
|
|
description: 'Message id from the message header',
|
|
icon: 'IconHash',
|
|
})
|
|
headerMessageId: string;
|
|
|
|
@WorkspaceField({
|
|
standardId: MESSAGE_STANDARD_FIELD_IDS.direction,
|
|
type: FieldMetadataType.SELECT,
|
|
label: 'Direction',
|
|
description: 'Message Direction',
|
|
icon: 'IconDirection',
|
|
options: [
|
|
{ value: 'incoming', label: 'Incoming', position: 0, color: 'green' },
|
|
{ value: 'outgoing', label: 'Outgoing', position: 1, color: 'blue' },
|
|
],
|
|
defaultValue: "'incoming'",
|
|
})
|
|
direction: string;
|
|
|
|
@WorkspaceField({
|
|
standardId: MESSAGE_STANDARD_FIELD_IDS.subject,
|
|
type: FieldMetadataType.TEXT,
|
|
label: 'Subject',
|
|
description: 'Subject',
|
|
icon: 'IconMessage',
|
|
})
|
|
subject: string;
|
|
|
|
@WorkspaceField({
|
|
standardId: MESSAGE_STANDARD_FIELD_IDS.text,
|
|
type: FieldMetadataType.TEXT,
|
|
label: 'Text',
|
|
description: 'Text',
|
|
icon: 'IconMessage',
|
|
})
|
|
text: string;
|
|
|
|
@WorkspaceField({
|
|
standardId: MESSAGE_STANDARD_FIELD_IDS.receivedAt,
|
|
type: FieldMetadataType.DATE_TIME,
|
|
label: 'Received At',
|
|
description: 'The date the message was received',
|
|
icon: 'IconCalendar',
|
|
})
|
|
@WorkspaceIsNullable()
|
|
receivedAt: string;
|
|
|
|
@WorkspaceRelation({
|
|
standardId: MESSAGE_STANDARD_FIELD_IDS.messageThread,
|
|
type: RelationMetadataType.MANY_TO_ONE,
|
|
label: 'Message Thread Id',
|
|
description: 'Message Thread Id',
|
|
icon: 'IconHash',
|
|
joinColumn: 'messageThreadId',
|
|
inverseSideTarget: () => MessageThreadObjectMetadata,
|
|
inverseSideFieldKey: 'messages',
|
|
onDelete: RelationOnDeleteAction.CASCADE,
|
|
})
|
|
@WorkspaceIsNullable()
|
|
messageThread: Relation<MessageThreadObjectMetadata>;
|
|
|
|
@WorkspaceRelation({
|
|
standardId: MESSAGE_STANDARD_FIELD_IDS.messageParticipants,
|
|
type: RelationMetadataType.ONE_TO_MANY,
|
|
label: 'Message Participants',
|
|
description: 'Message Participants',
|
|
icon: 'IconUserCircle',
|
|
inverseSideTarget: () => MessageParticipantObjectMetadata,
|
|
onDelete: RelationOnDeleteAction.CASCADE,
|
|
})
|
|
@WorkspaceIsNullable()
|
|
messageParticipants: Relation<MessageParticipantObjectMetadata[]>;
|
|
|
|
@WorkspaceRelation({
|
|
standardId: MESSAGE_STANDARD_FIELD_IDS.messageChannelMessageAssociations,
|
|
type: RelationMetadataType.ONE_TO_MANY,
|
|
label: 'Message Channel Association',
|
|
description: 'Messages from the channel.',
|
|
icon: 'IconMessage',
|
|
inverseSideTarget: () => MessageChannelMessageAssociationObjectMetadata,
|
|
onDelete: RelationOnDeleteAction.CASCADE,
|
|
})
|
|
@WorkspaceIsNullable()
|
|
messageChannelMessageAssociations: Relation<
|
|
MessageChannelMessageAssociationObjectMetadata[]
|
|
>;
|
|
}
|