From b2708438d1d4a4c0396ec3fce901db163cd04f53 Mon Sep 17 00:00:00 2001 From: bosiraphael <71827178+bosiraphael@users.noreply.github.com> Date: Wed, 6 Mar 2024 18:05:40 +0100 Subject: [PATCH] 4283 create calendareventattendee data model (#4333) * add person relation * add workspaceMember relation * done * update channel * update event data-model * add relation * done * changes after review * update model --- .../calendar-channel.object-metadata.ts | 23 +++- ...calendar-event-attendee.object-metadata.ts | 118 ++++++++++++++++++ .../calendar-event.object-metadata.ts | 56 ++++----- .../standard-objects/index.ts | 2 + .../person.object-metadata.ts | 24 +++- .../workspace-member.object-metadata.ts | 28 +++-- 6 files changed, 197 insertions(+), 54 deletions(-) create mode 100644 packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/calendar-event-attendee.object-metadata.ts diff --git a/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/calendar-channel.object-metadata.ts b/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/calendar-channel.object-metadata.ts index a543d70e6980..267844cc57af 100644 --- a/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/calendar-channel.object-metadata.ts +++ b/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/calendar-channel.object-metadata.ts @@ -7,6 +7,11 @@ import { ObjectMetadata } from 'src/workspace/workspace-sync-metadata/decorators import { BaseObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/base.object-metadata'; import { ConnectedAccountObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/connected-account.object-metadata'; +export enum CalendarChannelVisibility { + METADATA = 'METADATA', + SHARE_EVERYTHING = 'SHARE_EVERYTHING', +} + @ObjectMetadata({ namePlural: 'calendarChannels', labelSingular: 'Calendar Channel', @@ -42,15 +47,20 @@ export class CalendarChannelObjectMetadata extends BaseObjectMetadata { description: 'Visibility', icon: 'IconEyeglass', options: [ - { value: 'metadata', label: 'Metadata', position: 0, color: 'green' }, { - value: 'share_everything', + value: CalendarChannelVisibility.METADATA, + label: 'Metadata', + position: 0, + color: 'green', + }, + { + value: CalendarChannelVisibility.SHARE_EVERYTHING, label: 'Share Everything', position: 1, color: 'orange', }, ], - defaultValue: { value: 'share_everything' }, + defaultValue: { value: CalendarChannelVisibility.SHARE_EVERYTHING }, }) visibility: string; @@ -74,9 +84,10 @@ export class CalendarChannelObjectMetadata extends BaseObjectMetadata { @FieldMetadata({ type: FieldMetadataType.TEXT, - label: 'Next Sync Token', - description: 'Next Sync Token', + label: 'Sync Cursor', + description: + 'Sync Cursor. Used for syncing events from the calendar provider', icon: 'IconReload', }) - nextSyncToken: string; + syncCursor: string; } diff --git a/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/calendar-event-attendee.object-metadata.ts b/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/calendar-event-attendee.object-metadata.ts new file mode 100644 index 000000000000..29efc22d3980 --- /dev/null +++ b/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/calendar-event-attendee.object-metadata.ts @@ -0,0 +1,118 @@ +import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity'; +import { FieldMetadata } from 'src/workspace/workspace-sync-metadata/decorators/field-metadata.decorator'; +import { Gate } from 'src/workspace/workspace-sync-metadata/decorators/gate.decorator'; +import { IsNullable } from 'src/workspace/workspace-sync-metadata/decorators/is-nullable.decorator'; +import { IsSystem } from 'src/workspace/workspace-sync-metadata/decorators/is-system.decorator'; +import { ObjectMetadata } from 'src/workspace/workspace-sync-metadata/decorators/object-metadata.decorator'; +import { BaseObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/base.object-metadata'; +import { CalendarEventObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/calendar-event.object-metadata'; +import { PersonObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/person.object-metadata'; +import { WorkspaceMemberObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/workspace-member.object-metadata'; + +export enum CalendarEventAttendeeResponseStatus { + NEEDS_ACTION = 'NEEDS_ACTION', + DECLINED = 'DECLINED', + TENTATIVE = 'TENTATIVE', + ACCEPTED = 'ACCEPTED', +} + +@ObjectMetadata({ + namePlural: 'calendarEventAttendees', + labelSingular: 'Calendar event attendee', + labelPlural: 'Calendar event attendees', + description: 'Calendar event attendees', + icon: 'IconCalendar', +}) +@IsSystem() +@Gate({ + featureFlag: 'IS_CALENDAR_ENABLED', +}) +export class CalendarEventAttendeeObjectMetadata extends BaseObjectMetadata { + @FieldMetadata({ + type: FieldMetadataType.RELATION, + label: 'Event ID', + description: 'Event ID', + icon: 'IconCalendar', + joinColumn: 'calendarEventId', + }) + calendarEvent: CalendarEventObjectMetadata; + + @FieldMetadata({ + type: FieldMetadataType.TEXT, + label: 'Handle', + description: 'Handle', + icon: 'IconMail', + }) + handle: string; + + @FieldMetadata({ + type: FieldMetadataType.TEXT, + label: 'Display Name', + description: 'Display Name', + icon: 'IconUser', + }) + displayName: string; + + @FieldMetadata({ + type: FieldMetadataType.BOOLEAN, + label: 'Is Organizer', + description: 'Is Organizer', + icon: 'IconUser', + }) + isOrganizer: boolean; + + @FieldMetadata({ + type: FieldMetadataType.SELECT, + label: 'Response Status', + description: 'Response Status', + icon: 'IconUser', + options: [ + { + value: CalendarEventAttendeeResponseStatus.NEEDS_ACTION, + label: 'Needs Action', + position: 0, + color: 'orange', + }, + { + value: CalendarEventAttendeeResponseStatus.DECLINED, + label: 'Declined', + position: 1, + color: 'red', + }, + { + value: CalendarEventAttendeeResponseStatus.TENTATIVE, + label: 'Tentative', + position: 2, + color: 'yellow', + }, + { + value: CalendarEventAttendeeResponseStatus.ACCEPTED, + label: 'Accepted', + position: 3, + color: 'green', + }, + ], + defaultValue: { value: CalendarEventAttendeeResponseStatus.NEEDS_ACTION }, + }) + responseStatus: string; + + @FieldMetadata({ + type: FieldMetadataType.RELATION, + label: 'Person', + description: 'Person', + icon: 'IconUser', + joinColumn: 'personId', + }) + @IsNullable() + person: PersonObjectMetadata; + + @FieldMetadata({ + type: FieldMetadataType.RELATION, + label: 'Workspace Member', + description: 'Workspace Member', + icon: 'IconUser', + joinColumn: 'workspaceMemberId', + }) + @IsNullable() + workspaceMember: WorkspaceMemberObjectMetadata; +} diff --git a/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/calendar-event.object-metadata.ts b/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/calendar-event.object-metadata.ts index 927fb5d0b596..ef45311ecbb5 100644 --- a/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/calendar-event.object-metadata.ts +++ b/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/calendar-event.object-metadata.ts @@ -1,16 +1,16 @@ +import { RelationMetadata } from 'src/workspace/workspace-sync-metadata/decorators/relation-metadata.decorator'; import { FeatureFlagKeys } from 'src/core/feature-flag/feature-flag.entity'; import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity'; +import { + RelationMetadataType, + RelationOnDeleteAction, +} from 'src/metadata/relation-metadata/relation-metadata.entity'; import { FieldMetadata } from 'src/workspace/workspace-sync-metadata/decorators/field-metadata.decorator'; import { Gate } from 'src/workspace/workspace-sync-metadata/decorators/gate.decorator'; import { IsSystem } from 'src/workspace/workspace-sync-metadata/decorators/is-system.decorator'; import { ObjectMetadata } from 'src/workspace/workspace-sync-metadata/decorators/object-metadata.decorator'; import { BaseObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/base.object-metadata'; - -export enum CalendarEventStatus { - CONFIRMED = 'CONFIRMED', - TENTATIVE = 'TENTATIVE', - CANCELED = 'CANCELED', -} +import { CalendarEventAttendeeObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/calendar-event-attendee.object-metadata'; @ObjectMetadata({ namePlural: 'calendarEvents', @@ -33,33 +33,12 @@ export class CalendarEventObjectMetadata extends BaseObjectMetadata { title: string; @FieldMetadata({ - type: FieldMetadataType.SELECT, - label: 'Status', - description: 'Status', - icon: 'IconCheckbox', - options: [ - { - value: CalendarEventStatus.CONFIRMED, - label: 'Confirmed', - position: 0, - color: 'green', - }, - { - value: CalendarEventStatus.TENTATIVE, - label: 'Tentative', - position: 1, - color: 'blue', - }, - { - value: CalendarEventStatus.CANCELED, - label: 'Canceled', - position: 2, - color: 'red', - }, - ], - defaultValue: { value: CalendarEventStatus.CONFIRMED }, + type: FieldMetadataType.BOOLEAN, + label: 'Is canceled', + description: 'Is canceled', + icon: 'IconCalendarCancel', }) - status: string; + isCanceled: boolean; @FieldMetadata({ type: FieldMetadataType.BOOLEAN, @@ -148,4 +127,17 @@ export class CalendarEventObjectMetadata extends BaseObjectMetadata { icon: 'IconHistory', }) recurringEventExternalId: string; + + @FieldMetadata({ + type: FieldMetadataType.RELATION, + label: 'Event Attendees', + description: 'Event Attendees', + icon: 'IconUserCircle', + }) + @RelationMetadata({ + type: RelationMetadataType.ONE_TO_MANY, + objectName: 'calendarEventAttendee', + onDelete: RelationOnDeleteAction.CASCADE, + }) + eventAttendees: CalendarEventAttendeeObjectMetadata[]; } diff --git a/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/index.ts b/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/index.ts index 54d4c66f95fe..79120e30a088 100644 --- a/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/index.ts +++ b/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/index.ts @@ -5,6 +5,7 @@ import { AttachmentObjectMetadata } from 'src/workspace/workspace-sync-metadata/ import { BlocklistObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/blocklist.object-metadata'; import { CalendarEventObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/calendar-event.object-metadata'; import { CalendarChannelObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/calendar-channel.object-metadata'; +import { CalendarEventAttendeeObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/calendar-event-attendee.object-metadata'; import { CommentObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/comment.object-metadata'; import { CompanyObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/company.object-metadata'; import { ConnectedAccountObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/connected-account.object-metadata'; @@ -50,4 +51,5 @@ export const standardObjectMetadataCollection = [ MessageChannelMessageAssociationObjectMetadata, CalendarEventObjectMetadata, CalendarChannelObjectMetadata, + CalendarEventAttendeeObjectMetadata, ]; diff --git a/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/person.object-metadata.ts b/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/person.object-metadata.ts index e067212c12de..165e96b03934 100644 --- a/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/person.object-metadata.ts +++ b/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/person.object-metadata.ts @@ -6,6 +6,7 @@ import { RelationOnDeleteAction, } from 'src/metadata/relation-metadata/relation-metadata.entity'; import { FieldMetadata } from 'src/workspace/workspace-sync-metadata/decorators/field-metadata.decorator'; +import { Gate } from 'src/workspace/workspace-sync-metadata/decorators/gate.decorator'; import { IsNullable } from 'src/workspace/workspace-sync-metadata/decorators/is-nullable.decorator'; import { IsSystem } from 'src/workspace/workspace-sync-metadata/decorators/is-system.decorator'; import { ObjectMetadata } from 'src/workspace/workspace-sync-metadata/decorators/object-metadata.decorator'; @@ -13,6 +14,7 @@ import { RelationMetadata } from 'src/workspace/workspace-sync-metadata/decorato import { ActivityTargetObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/activity-target.object-metadata'; import { AttachmentObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/attachment.object-metadata'; import { BaseObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/base.object-metadata'; +import { CalendarEventAttendeeObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/calendar-event-attendee.object-metadata'; import { CompanyObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/company.object-metadata'; import { FavoriteObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/favorite.object-metadata'; import { MessageParticipantObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/message-participant.object-metadata'; @@ -112,7 +114,6 @@ export class PersonObjectMetadata extends BaseObjectMetadata { icon: 'IconBuildingSkyscraper', joinColumn: 'companyId', }) - @IsNullable() company: CompanyObjectMetadata; @FieldMetadata({ @@ -126,7 +127,6 @@ export class PersonObjectMetadata extends BaseObjectMetadata { objectName: 'opportunity', inverseSideFieldName: 'pointOfContact', }) - @IsNullable() pointOfContactForOpportunities: OpportunityObjectMetadata[]; @FieldMetadata({ @@ -140,7 +140,6 @@ export class PersonObjectMetadata extends BaseObjectMetadata { objectName: 'activityTarget', onDelete: RelationOnDeleteAction.CASCADE, }) - @IsNullable() activityTargets: ActivityTargetObjectMetadata[]; @FieldMetadata({ @@ -154,7 +153,6 @@ export class PersonObjectMetadata extends BaseObjectMetadata { objectName: 'favorite', onDelete: RelationOnDeleteAction.CASCADE, }) - @IsNullable() favorites: FavoriteObjectMetadata[]; @FieldMetadata({ @@ -168,7 +166,6 @@ export class PersonObjectMetadata extends BaseObjectMetadata { objectName: 'attachment', onDelete: RelationOnDeleteAction.CASCADE, }) - @IsNullable() attachments: AttachmentObjectMetadata[]; @FieldMetadata({ @@ -182,6 +179,21 @@ export class PersonObjectMetadata extends BaseObjectMetadata { objectName: 'messageParticipant', inverseSideFieldName: 'person', }) - @IsNullable() messageParticipants: MessageParticipantObjectMetadata[]; + + @FieldMetadata({ + type: FieldMetadataType.RELATION, + label: 'Calendar Event Attendees', + description: 'Calendar Event Attendees', + icon: 'IconCalendar', + }) + @RelationMetadata({ + type: RelationMetadataType.ONE_TO_MANY, + objectName: 'calendarEventAttendee', + inverseSideFieldName: 'person', + }) + @Gate({ + featureFlag: 'IS_CALENDAR_ENABLED', + }) + calendarEventAttendees: CalendarEventAttendeeObjectMetadata[]; } diff --git a/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/workspace-member.object-metadata.ts b/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/workspace-member.object-metadata.ts index 2ddf038d5128..fe213ca38a57 100644 --- a/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/workspace-member.object-metadata.ts +++ b/packages/twenty-server/src/workspace/workspace-sync-metadata/standard-objects/workspace-member.object-metadata.ts @@ -5,6 +5,7 @@ import { RelationOnDeleteAction, } from 'src/metadata/relation-metadata/relation-metadata.entity'; import { FieldMetadata } from 'src/workspace/workspace-sync-metadata/decorators/field-metadata.decorator'; +import { Gate } from 'src/workspace/workspace-sync-metadata/decorators/gate.decorator'; import { IsNullable } from 'src/workspace/workspace-sync-metadata/decorators/is-nullable.decorator'; import { IsSystem } from 'src/workspace/workspace-sync-metadata/decorators/is-system.decorator'; import { ObjectMetadata } from 'src/workspace/workspace-sync-metadata/decorators/object-metadata.decorator'; @@ -13,6 +14,7 @@ import { ActivityObjectMetadata } from 'src/workspace/workspace-sync-metadata/st import { AttachmentObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/attachment.object-metadata'; import { BaseObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/base.object-metadata'; import { BlocklistObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/blocklist.object-metadata'; +import { CalendarEventAttendeeObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/calendar-event-attendee.object-metadata'; import { CommentObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/comment.object-metadata'; import { CompanyObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/company.object-metadata'; import { ConnectedAccountObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/connected-account.object-metadata'; @@ -90,7 +92,6 @@ export class WorkspaceMemberObjectMetadata extends BaseObjectMetadata { objectName: 'activity', inverseSideFieldName: 'author', }) - @IsNullable() authoredActivities: ActivityObjectMetadata[]; @FieldMetadata({ @@ -105,8 +106,6 @@ export class WorkspaceMemberObjectMetadata extends BaseObjectMetadata { inverseSideFieldName: 'assignee', }) @IsNullable() - assignedActivities: ActivityObjectMetadata[]; - @FieldMetadata({ type: FieldMetadataType.RELATION, label: 'Favorites', @@ -118,7 +117,6 @@ export class WorkspaceMemberObjectMetadata extends BaseObjectMetadata { objectName: 'favorite', onDelete: RelationOnDeleteAction.CASCADE, }) - @IsNullable() favorites: FavoriteObjectMetadata[]; @FieldMetadata({ @@ -132,7 +130,6 @@ export class WorkspaceMemberObjectMetadata extends BaseObjectMetadata { objectName: 'company', inverseSideFieldName: 'accountOwner', }) - @IsNullable() accountOwnerForCompanies: CompanyObjectMetadata[]; @FieldMetadata({ @@ -146,7 +143,6 @@ export class WorkspaceMemberObjectMetadata extends BaseObjectMetadata { objectName: 'attachment', inverseSideFieldName: 'author', }) - @IsNullable() authoredAttachments: AttachmentObjectMetadata[]; @FieldMetadata({ @@ -160,7 +156,6 @@ export class WorkspaceMemberObjectMetadata extends BaseObjectMetadata { objectName: 'comment', inverseSideFieldName: 'author', }) - @IsNullable() authoredComments: CommentObjectMetadata[]; @FieldMetadata({ @@ -174,7 +169,6 @@ export class WorkspaceMemberObjectMetadata extends BaseObjectMetadata { objectName: 'connectedAccount', inverseSideFieldName: 'accountOwner', }) - @IsNullable() connectedAccounts: ConnectedAccountObjectMetadata[]; @FieldMetadata({ @@ -188,7 +182,6 @@ export class WorkspaceMemberObjectMetadata extends BaseObjectMetadata { objectName: 'messageParticipant', inverseSideFieldName: 'workspaceMember', }) - @IsNullable() messageParticipants: MessageParticipantObjectMetadata[]; @FieldMetadata({ @@ -202,6 +195,21 @@ export class WorkspaceMemberObjectMetadata extends BaseObjectMetadata { objectName: 'blocklist', inverseSideFieldName: 'workspaceMember', }) - @IsNullable() blocklist: BlocklistObjectMetadata[]; + + @FieldMetadata({ + type: FieldMetadataType.RELATION, + label: 'Calendar Event Attendees', + description: 'Calendar Event Attendees', + icon: 'IconCalendar', + }) + @RelationMetadata({ + type: RelationMetadataType.ONE_TO_MANY, + objectName: 'calendarEventAttendee', + inverseSideFieldName: 'workspaceMember', + }) + @Gate({ + featureFlag: 'IS_CALENDAR_ENABLED', + }) + calendarEventAttendees: CalendarEventAttendeeObjectMetadata[]; }