New Timeline (#4936)
Refactored the code to introduce two different concepts: - AuditLogs (immutable, raw data) - TimelineActivities (user-friendly, transformed data) Still some work needed: - Add message, files, calendar events to timeline (~2 hours if done naively) - Refactor repository to try to abstract concept when we can (tbd, wait for Twenty ORM) - Introduce ability to display child timelines on parent timeline with filtering (~2 days) - Improve UI: add links to open note/task, improve diff display, etc (half a day) - Decide the path forward for Task vs Notes: either introduce a new field type "Record Type" and start going into that direction ; or split in two objects? - Trigger updates when a field is changed (will be solved by real-time / websockets: 2 weeks) - Integrate behavioral events (1 day for POC, 1 week for clean/documented) <img width="1248" alt="Screenshot 2024-04-12 at 09 24 49" src="https://github.com/twentyhq/twenty/assets/6399865/9428db1a-ab2b-492c-8b0b-d4d9a36e81fa">
This commit is contained in:
@ -27,7 +27,7 @@ export class ParticipantPersonListener {
|
||||
async handleCreatedEvent(
|
||||
payload: ObjectRecordCreateEvent<PersonObjectMetadata>,
|
||||
) {
|
||||
if (payload.details.after.email === null) {
|
||||
if (payload.properties.after.email === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -35,7 +35,7 @@ export class ParticipantPersonListener {
|
||||
MatchParticipantJob.name,
|
||||
{
|
||||
workspaceId: payload.workspaceId,
|
||||
email: payload.details.after.email,
|
||||
email: payload.properties.after.email,
|
||||
personId: payload.recordId,
|
||||
},
|
||||
);
|
||||
@ -47,15 +47,15 @@ export class ParticipantPersonListener {
|
||||
) {
|
||||
if (
|
||||
objectRecordUpdateEventChangedProperties(
|
||||
payload.details.before,
|
||||
payload.details.after,
|
||||
payload.properties.before,
|
||||
payload.properties.after,
|
||||
).includes('email')
|
||||
) {
|
||||
await this.messageQueueService.add<UnmatchParticipantJobData>(
|
||||
UnmatchParticipantJob.name,
|
||||
{
|
||||
workspaceId: payload.workspaceId,
|
||||
email: payload.details.before.email,
|
||||
email: payload.properties.before.email,
|
||||
personId: payload.recordId,
|
||||
},
|
||||
);
|
||||
@ -64,7 +64,7 @@ export class ParticipantPersonListener {
|
||||
MatchParticipantJob.name,
|
||||
{
|
||||
workspaceId: payload.workspaceId,
|
||||
email: payload.details.after.email,
|
||||
email: payload.properties.after.email,
|
||||
personId: payload.recordId,
|
||||
},
|
||||
);
|
||||
|
||||
@ -27,7 +27,7 @@ export class ParticipantWorkspaceMemberListener {
|
||||
async handleCreatedEvent(
|
||||
payload: ObjectRecordCreateEvent<WorkspaceMemberObjectMetadata>,
|
||||
) {
|
||||
if (payload.details.after.userEmail === null) {
|
||||
if (payload.properties.after.userEmail === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -35,8 +35,8 @@ export class ParticipantWorkspaceMemberListener {
|
||||
MatchParticipantJob.name,
|
||||
{
|
||||
workspaceId: payload.workspaceId,
|
||||
email: payload.details.after.userEmail,
|
||||
workspaceMemberId: payload.details.after.id,
|
||||
email: payload.properties.after.userEmail,
|
||||
workspaceMemberId: payload.properties.after.id,
|
||||
},
|
||||
);
|
||||
}
|
||||
@ -47,15 +47,15 @@ export class ParticipantWorkspaceMemberListener {
|
||||
) {
|
||||
if (
|
||||
objectRecordUpdateEventChangedProperties(
|
||||
payload.details.before,
|
||||
payload.details.after,
|
||||
payload.properties.before,
|
||||
payload.properties.after,
|
||||
).includes('userEmail')
|
||||
) {
|
||||
await this.messageQueueService.add<UnmatchParticipantJobData>(
|
||||
UnmatchParticipantJob.name,
|
||||
{
|
||||
workspaceId: payload.workspaceId,
|
||||
email: payload.details.before.userEmail,
|
||||
email: payload.properties.before.userEmail,
|
||||
personId: payload.recordId,
|
||||
},
|
||||
);
|
||||
@ -64,7 +64,7 @@ export class ParticipantWorkspaceMemberListener {
|
||||
MatchParticipantJob.name,
|
||||
{
|
||||
workspaceId: payload.workspaceId,
|
||||
email: payload.details.after.userEmail,
|
||||
email: payload.properties.after.userEmail,
|
||||
workspaceMemberId: payload.recordId,
|
||||
},
|
||||
);
|
||||
|
||||
@ -24,10 +24,10 @@ export class CalendarChannelListener {
|
||||
) {
|
||||
if (
|
||||
objectRecordChangedProperties(
|
||||
payload.details.before,
|
||||
payload.details.after,
|
||||
payload.properties.before,
|
||||
payload.properties.after,
|
||||
).includes('isContactAutoCreationEnabled') &&
|
||||
payload.details.after.isContactAutoCreationEnabled
|
||||
payload.properties.after.isContactAutoCreationEnabled
|
||||
) {
|
||||
await this.messageQueueService.add<CalendarCreateCompanyAndContactAfterSyncJobData>(
|
||||
CalendarCreateCompanyAndContactAfterSyncJob.name,
|
||||
|
||||
@ -21,7 +21,7 @@ import { FavoriteObjectMetadata } from 'src/modules/favorite/standard-objects/fa
|
||||
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 { EventObjectMetadata } from 'src/modules/event/standard-objects/event.object-metadata';
|
||||
import { TimelineActivityObjectMetadata } from 'src/modules/timeline/standard-objects/timeline-activity.object-metadata';
|
||||
|
||||
@ObjectMetadata({
|
||||
standardId: standardObjectIds.company,
|
||||
@ -213,18 +213,18 @@ export class CompanyObjectMetadata extends BaseObjectMetadata {
|
||||
attachments: Relation<AttachmentObjectMetadata[]>;
|
||||
|
||||
@FieldMetadata({
|
||||
standardId: companyStandardFieldIds.events,
|
||||
standardId: companyStandardFieldIds.timelineActivities,
|
||||
type: FieldMetadataType.RELATION,
|
||||
label: 'Events',
|
||||
description: 'Events linked to the company',
|
||||
label: 'Timeline Activities',
|
||||
description: 'Timeline Activities linked to the company',
|
||||
icon: 'IconIconTimelineEvent',
|
||||
})
|
||||
@RelationMetadata({
|
||||
type: RelationMetadataType.ONE_TO_MANY,
|
||||
inverseSideTarget: () => EventObjectMetadata,
|
||||
inverseSideTarget: () => TimelineActivityObjectMetadata,
|
||||
onDelete: RelationOnDeleteAction.CASCADE,
|
||||
})
|
||||
@IsNullable()
|
||||
@IsSystem()
|
||||
events: Relation<EventObjectMetadata[]>;
|
||||
timelineActivities: Relation<TimelineActivityObjectMetadata[]>;
|
||||
}
|
||||
|
||||
@ -16,6 +16,9 @@ import { OpportunityObjectMetadata } from 'src/modules/opportunity/standard-obje
|
||||
import { PersonObjectMetadata } from 'src/modules/person/standard-objects/person.object-metadata';
|
||||
import { WorkspaceMemberObjectMetadata } from 'src/modules/workspace-member/standard-objects/workspace-member.object-metadata';
|
||||
|
||||
// TODO: Depricate
|
||||
// This should be removed in the next release
|
||||
// We use AuditLog and ActivityTimeline instead
|
||||
@ObjectMetadata({
|
||||
standardId: standardObjectIds.event,
|
||||
namePlural: 'events',
|
||||
|
||||
@ -24,10 +24,10 @@ export class MessagingMessageChannelListener {
|
||||
) {
|
||||
if (
|
||||
objectRecordChangedProperties(
|
||||
payload.details.before,
|
||||
payload.details.after,
|
||||
payload.properties.before,
|
||||
payload.properties.after,
|
||||
).includes('isContactAutoCreationEnabled') &&
|
||||
payload.details.after.isContactAutoCreationEnabled
|
||||
payload.properties.after.isContactAutoCreationEnabled
|
||||
) {
|
||||
await this.messageQueueService.add<MessagingCreateCompanyAndContactAfterSyncJobData>(
|
||||
MessagingCreateCompanyAndContactAfterSyncJob.name,
|
||||
|
||||
@ -19,7 +19,7 @@ import { BaseObjectMetadata } from 'src/engine/workspace-manager/workspace-sync-
|
||||
import { CompanyObjectMetadata } from 'src/modules/company/standard-objects/company.object-metadata';
|
||||
import { FavoriteObjectMetadata } from 'src/modules/favorite/standard-objects/favorite.object-metadata';
|
||||
import { PersonObjectMetadata } from 'src/modules/person/standard-objects/person.object-metadata';
|
||||
import { EventObjectMetadata } from 'src/modules/event/standard-objects/event.object-metadata';
|
||||
import { TimelineActivityObjectMetadata } from 'src/modules/timeline/standard-objects/timeline-activity.object-metadata';
|
||||
import { IsNotAuditLogged } from 'src/engine/workspace-manager/workspace-sync-metadata/decorators/is-not-audit-logged.decorator';
|
||||
|
||||
@ObjectMetadata({
|
||||
@ -173,17 +173,17 @@ export class OpportunityObjectMetadata extends BaseObjectMetadata {
|
||||
attachments: Relation<AttachmentObjectMetadata[]>;
|
||||
|
||||
@FieldMetadata({
|
||||
standardId: opportunityStandardFieldIds.events,
|
||||
standardId: opportunityStandardFieldIds.timelineActivities,
|
||||
type: FieldMetadataType.RELATION,
|
||||
label: 'Events',
|
||||
description: 'Events linked to the opportunity.',
|
||||
label: 'Timeline Activities',
|
||||
description: 'Timeline Activities linked to the opportunity.',
|
||||
icon: 'IconTimelineEvent',
|
||||
})
|
||||
@RelationMetadata({
|
||||
type: RelationMetadataType.ONE_TO_MANY,
|
||||
inverseSideTarget: () => EventObjectMetadata,
|
||||
inverseSideTarget: () => TimelineActivityObjectMetadata,
|
||||
onDelete: RelationOnDeleteAction.SET_NULL,
|
||||
})
|
||||
@IsNullable()
|
||||
events: Relation<EventObjectMetadata[]>;
|
||||
timelineActivities: Relation<TimelineActivityObjectMetadata[]>;
|
||||
}
|
||||
|
||||
@ -23,7 +23,7 @@ import { CompanyObjectMetadata } from 'src/modules/company/standard-objects/comp
|
||||
import { FavoriteObjectMetadata } from 'src/modules/favorite/standard-objects/favorite.object-metadata';
|
||||
import { MessageParticipantObjectMetadata } from 'src/modules/messaging/standard-objects/message-participant.object-metadata';
|
||||
import { OpportunityObjectMetadata } from 'src/modules/opportunity/standard-objects/opportunity.object-metadata';
|
||||
import { EventObjectMetadata } from 'src/modules/event/standard-objects/event.object-metadata';
|
||||
import { TimelineActivityObjectMetadata } from 'src/modules/timeline/standard-objects/timeline-activity.object-metadata';
|
||||
|
||||
@ObjectMetadata({
|
||||
standardId: standardObjectIds.person,
|
||||
@ -226,7 +226,7 @@ export class PersonObjectMetadata extends BaseObjectMetadata {
|
||||
calendarEventParticipants: Relation<CalendarEventParticipantObjectMetadata[]>;
|
||||
|
||||
@FieldMetadata({
|
||||
standardId: personStandardFieldIds.events,
|
||||
standardId: personStandardFieldIds.timelineActivities,
|
||||
type: FieldMetadataType.RELATION,
|
||||
label: 'Events',
|
||||
description: 'Events linked to the company',
|
||||
@ -234,10 +234,10 @@ export class PersonObjectMetadata extends BaseObjectMetadata {
|
||||
})
|
||||
@RelationMetadata({
|
||||
type: RelationMetadataType.ONE_TO_MANY,
|
||||
inverseSideTarget: () => EventObjectMetadata,
|
||||
inverseSideTarget: () => TimelineActivityObjectMetadata,
|
||||
onDelete: RelationOnDeleteAction.CASCADE,
|
||||
})
|
||||
@IsNullable()
|
||||
@IsSystem()
|
||||
events: Relation<EventObjectMetadata[]>;
|
||||
timelineActivities: Relation<TimelineActivityObjectMetadata[]>;
|
||||
}
|
||||
|
||||
@ -0,0 +1,52 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
import { MessageQueueJob } from 'src/engine/integrations/message-queue/interfaces/message-queue-job.interface';
|
||||
|
||||
import { ObjectRecordBaseEvent } from 'src/engine/integrations/event-emitter/types/object-record.base.event';
|
||||
import { InjectObjectMetadataRepository } from 'src/engine/object-metadata-repository/object-metadata-repository.decorator';
|
||||
import { AuditLogRepository } from 'src/modules/timeline/repositiories/audit-log.repository';
|
||||
import { AuditLogObjectMetadata } from 'src/modules/timeline/standard-objects/audit-log.object-metadata';
|
||||
import { WorkspaceMemberRepository } from 'src/modules/workspace-member/repositories/workspace-member.repository';
|
||||
import { WorkspaceMemberObjectMetadata } from 'src/modules/workspace-member/standard-objects/workspace-member.object-metadata';
|
||||
|
||||
@Injectable()
|
||||
export class CreateAuditLogFromInternalEvent
|
||||
implements MessageQueueJob<ObjectRecordBaseEvent>
|
||||
{
|
||||
constructor(
|
||||
@InjectObjectMetadataRepository(WorkspaceMemberObjectMetadata)
|
||||
private readonly workspaceMemberService: WorkspaceMemberRepository,
|
||||
@InjectObjectMetadataRepository(AuditLogObjectMetadata)
|
||||
private readonly auditLogRepository: AuditLogRepository,
|
||||
) {}
|
||||
|
||||
async handle(data: ObjectRecordBaseEvent): Promise<void> {
|
||||
let workspaceMemberId: string | null = null;
|
||||
|
||||
if (data.userId) {
|
||||
const workspaceMember = await this.workspaceMemberService.getByIdOrFail(
|
||||
data.userId,
|
||||
data.workspaceId,
|
||||
);
|
||||
|
||||
workspaceMemberId = workspaceMember.id;
|
||||
}
|
||||
|
||||
if (data.properties.diff) {
|
||||
// we remove "before" and "after" property for a cleaner/slimmer event payload
|
||||
data.properties = {
|
||||
diff: data.properties.diff,
|
||||
};
|
||||
}
|
||||
|
||||
await this.auditLogRepository.insert(
|
||||
data.name,
|
||||
data.properties,
|
||||
workspaceMemberId,
|
||||
data.name.split('.')[0],
|
||||
data.objectMetadata.id,
|
||||
data.recordId,
|
||||
data.workspaceId,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1 @@
|
||||
// TODO
|
||||
@ -0,0 +1,50 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
import { MessageQueueJob } from 'src/engine/integrations/message-queue/interfaces/message-queue-job.interface';
|
||||
|
||||
import { ObjectRecordBaseEvent } from 'src/engine/integrations/event-emitter/types/object-record.base.event';
|
||||
import { InjectObjectMetadataRepository } from 'src/engine/object-metadata-repository/object-metadata-repository.decorator';
|
||||
import { WorkspaceMemberRepository } from 'src/modules/workspace-member/repositories/workspace-member.repository';
|
||||
import { WorkspaceMemberObjectMetadata } from 'src/modules/workspace-member/standard-objects/workspace-member.object-metadata';
|
||||
import { TimelineActivityService } from 'src/modules/timeline/services/timeline-activity.service';
|
||||
|
||||
@Injectable()
|
||||
export class UpsertTimelineActivityFromInternalEvent
|
||||
implements MessageQueueJob<ObjectRecordBaseEvent>
|
||||
{
|
||||
constructor(
|
||||
@InjectObjectMetadataRepository(WorkspaceMemberObjectMetadata)
|
||||
private readonly workspaceMemberService: WorkspaceMemberRepository,
|
||||
private readonly timelineActivityService: TimelineActivityService,
|
||||
) {}
|
||||
|
||||
async handle(data: ObjectRecordBaseEvent): Promise<void> {
|
||||
if (data.userId) {
|
||||
const workspaceMember = await this.workspaceMemberService.getByIdOrFail(
|
||||
data.userId,
|
||||
data.workspaceId,
|
||||
);
|
||||
|
||||
data.workspaceMemberId = workspaceMember.id;
|
||||
}
|
||||
|
||||
if (data.properties.diff) {
|
||||
// we remove "before" and "after" property for a cleaner/slimmer event payload
|
||||
data.properties = {
|
||||
diff: data.properties.diff,
|
||||
};
|
||||
}
|
||||
|
||||
// Temporary
|
||||
// We ignore every that is not a LinkedObject or a Business Object
|
||||
if (
|
||||
data.objectMetadata.isSystem &&
|
||||
data.objectMetadata.nameSingular !== 'activityTarget' &&
|
||||
data.objectMetadata.nameSingular !== 'activity'
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
await this.timelineActivityService.upsertEvent(data);
|
||||
}
|
||||
}
|
||||
@ -3,7 +3,7 @@ import { Injectable } from '@nestjs/common';
|
||||
import { WorkspaceDataSourceService } from 'src/engine/workspace-datasource/workspace-datasource.service';
|
||||
|
||||
@Injectable()
|
||||
export class EventRepository {
|
||||
export class AuditLogRepository {
|
||||
constructor(
|
||||
private readonly workspaceDataSourceService: WorkspaceDataSourceService,
|
||||
) {}
|
||||
@ -13,17 +13,25 @@ export class EventRepository {
|
||||
properties: string,
|
||||
workspaceMemberId: string | null,
|
||||
objectName: string,
|
||||
objectId: string,
|
||||
objectMetadataId: string,
|
||||
recordId: string,
|
||||
workspaceId: string,
|
||||
): Promise<void> {
|
||||
const dataSourceSchema =
|
||||
this.workspaceDataSourceService.getSchemaName(workspaceId);
|
||||
|
||||
await this.workspaceDataSourceService.executeRawQuery(
|
||||
`INSERT INTO ${dataSourceSchema}."event"
|
||||
("name", "properties", "workspaceMemberId", "${objectName}Id")
|
||||
VALUES ($1, $2, $3, $4)`,
|
||||
[name, properties, workspaceMemberId, objectId],
|
||||
`INSERT INTO ${dataSourceSchema}."auditLog"
|
||||
("name", "properties", "workspaceMemberId", "objectName", "objectMetadataId", "recordId")
|
||||
VALUES ($1, $2, $3, $4, $5, $6)`,
|
||||
[
|
||||
name,
|
||||
properties,
|
||||
workspaceMemberId,
|
||||
objectName,
|
||||
objectMetadataId,
|
||||
recordId,
|
||||
],
|
||||
workspaceId,
|
||||
);
|
||||
}
|
||||
@ -0,0 +1,136 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
import { WorkspaceDataSourceService } from 'src/engine/workspace-datasource/workspace-datasource.service';
|
||||
import { objectRecordDiffMerge } from 'src/engine/integrations/event-emitter/utils/object-record-diff-merge';
|
||||
|
||||
@Injectable()
|
||||
export class TimelineActivityRepository {
|
||||
constructor(
|
||||
private readonly workspaceDataSourceService: WorkspaceDataSourceService,
|
||||
) {}
|
||||
|
||||
async upsertOne(
|
||||
name: string,
|
||||
properties: Record<string, any>,
|
||||
objectName: string,
|
||||
recordId: string,
|
||||
workspaceId: string,
|
||||
workspaceMemberId?: string,
|
||||
linkedRecordCachedName?: string,
|
||||
linkedRecordId?: string,
|
||||
linkedObjectMetadataId?: string,
|
||||
) {
|
||||
const dataSourceSchema =
|
||||
this.workspaceDataSourceService.getSchemaName(workspaceId);
|
||||
|
||||
const recentTimelineActivity = await this.findRecentTimelineActivity(
|
||||
dataSourceSchema,
|
||||
name,
|
||||
objectName,
|
||||
recordId,
|
||||
workspaceMemberId,
|
||||
linkedRecordId,
|
||||
workspaceId,
|
||||
);
|
||||
|
||||
if (recentTimelineActivity.length !== 0) {
|
||||
const newProps = objectRecordDiffMerge(
|
||||
recentTimelineActivity[0].properties,
|
||||
properties,
|
||||
);
|
||||
|
||||
return this.updateTimelineActivity(
|
||||
dataSourceSchema,
|
||||
recentTimelineActivity[0].id,
|
||||
newProps,
|
||||
workspaceMemberId,
|
||||
workspaceId,
|
||||
);
|
||||
}
|
||||
|
||||
return this.insertTimelineActivity(
|
||||
dataSourceSchema,
|
||||
name,
|
||||
properties,
|
||||
objectName,
|
||||
recordId,
|
||||
workspaceMemberId,
|
||||
linkedRecordCachedName ?? '',
|
||||
linkedRecordId,
|
||||
linkedObjectMetadataId,
|
||||
workspaceId,
|
||||
);
|
||||
}
|
||||
|
||||
private async findRecentTimelineActivity(
|
||||
dataSourceSchema: string,
|
||||
name: string,
|
||||
objectName: string,
|
||||
recordId: string,
|
||||
workspaceMemberId: string | undefined,
|
||||
linkedRecordId: string | undefined,
|
||||
workspaceId: string,
|
||||
) {
|
||||
return this.workspaceDataSourceService.executeRawQuery(
|
||||
`SELECT * FROM ${dataSourceSchema}."timelineActivity"
|
||||
WHERE "${objectName}Id" = $1
|
||||
AND ("name" = $2 OR "name" = $3)
|
||||
AND "workspaceMemberId" = $4
|
||||
AND "linkedRecordId" = $5
|
||||
AND "createdAt" >= NOW() - interval '10 minutes'`,
|
||||
[
|
||||
recordId,
|
||||
name,
|
||||
name.replace(/\.updated$/, '.created'),
|
||||
workspaceMemberId,
|
||||
linkedRecordId,
|
||||
],
|
||||
workspaceId,
|
||||
);
|
||||
}
|
||||
|
||||
private async updateTimelineActivity(
|
||||
dataSourceSchema: string,
|
||||
id: string,
|
||||
properties: Record<string, any>,
|
||||
workspaceMemberId: string | undefined,
|
||||
workspaceId: string,
|
||||
) {
|
||||
return this.workspaceDataSourceService.executeRawQuery(
|
||||
`UPDATE ${dataSourceSchema}."timelineActivity"
|
||||
SET "properties" = $2, "workspaceMemberId" = $3
|
||||
WHERE "id" = $1`,
|
||||
[id, properties, workspaceMemberId],
|
||||
workspaceId,
|
||||
);
|
||||
}
|
||||
|
||||
private async insertTimelineActivity(
|
||||
dataSourceSchema: string,
|
||||
name: string,
|
||||
properties: Record<string, any>,
|
||||
objectName: string,
|
||||
recordId: string,
|
||||
workspaceMemberId: string | undefined,
|
||||
linkedRecordCachedName: string,
|
||||
linkedRecordId: string | undefined,
|
||||
linkedObjectMetadataId: string | undefined,
|
||||
workspaceId: string,
|
||||
) {
|
||||
return this.workspaceDataSourceService.executeRawQuery(
|
||||
`INSERT INTO ${dataSourceSchema}."timelineActivity"
|
||||
("name", "properties", "workspaceMemberId", "${objectName}Id", "linkedRecordCachedName", "linkedRecordId", "linkedObjectMetadataId")
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7)`,
|
||||
[
|
||||
name,
|
||||
properties,
|
||||
workspaceMemberId,
|
||||
recordId,
|
||||
linkedRecordCachedName ?? '',
|
||||
linkedRecordId,
|
||||
linkedObjectMetadataId,
|
||||
],
|
||||
workspaceId,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,173 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
import { ObjectRecordBaseEvent } from 'src/engine/integrations/event-emitter/types/object-record.base.event';
|
||||
import { InjectObjectMetadataRepository } from 'src/engine/object-metadata-repository/object-metadata-repository.decorator';
|
||||
import { WorkspaceDataSourceService } from 'src/engine/workspace-datasource/workspace-datasource.service';
|
||||
import { TimelineActivityRepository } from 'src/modules/timeline/repositiories/timeline-activity.repository';
|
||||
import { TimelineActivityObjectMetadata } from 'src/modules/timeline/standard-objects/timeline-activity.object-metadata';
|
||||
|
||||
type TransformedEvent = ObjectRecordBaseEvent & {
|
||||
objectName?: string;
|
||||
linkedRecordCachedName?: string;
|
||||
linkedRecordId?: string;
|
||||
linkedObjectMetadataId?: string;
|
||||
};
|
||||
|
||||
@Injectable()
|
||||
export class TimelineActivityService {
|
||||
constructor(
|
||||
@InjectObjectMetadataRepository(TimelineActivityObjectMetadata)
|
||||
private readonly timelineActivityRepository: TimelineActivityRepository,
|
||||
private readonly workspaceDataSourceService: WorkspaceDataSourceService,
|
||||
) {}
|
||||
|
||||
async upsertEvent(event: ObjectRecordBaseEvent) {
|
||||
const events = await this.transformEvent(event);
|
||||
|
||||
if (!events || events.length === 0) return;
|
||||
|
||||
for (const event of events) {
|
||||
return await this.timelineActivityRepository.upsertOne(
|
||||
event.name,
|
||||
event.properties,
|
||||
event.objectName ?? event.objectMetadata.nameSingular,
|
||||
event.recordId,
|
||||
event.workspaceId,
|
||||
event.workspaceMemberId,
|
||||
event.linkedRecordCachedName,
|
||||
event.linkedRecordId,
|
||||
event.linkedObjectMetadataId,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private async transformEvent(
|
||||
event: ObjectRecordBaseEvent,
|
||||
): Promise<TransformedEvent[]> {
|
||||
if (
|
||||
['activity', 'messageParticipant', 'activityTarget'].includes(
|
||||
event.objectMetadata.nameSingular,
|
||||
)
|
||||
) {
|
||||
return await this.handleLinkedObjects(event);
|
||||
}
|
||||
|
||||
return [event];
|
||||
}
|
||||
|
||||
private async handleLinkedObjects(event: ObjectRecordBaseEvent) {
|
||||
const dataSourceSchema = this.workspaceDataSourceService.getSchemaName(
|
||||
event.workspaceId,
|
||||
);
|
||||
|
||||
switch (event.objectMetadata.nameSingular) {
|
||||
case 'activityTarget':
|
||||
return this.processActivityTarget(event, dataSourceSchema);
|
||||
case 'activity':
|
||||
return this.processActivity(event, dataSourceSchema);
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
private async processActivity(
|
||||
event: ObjectRecordBaseEvent,
|
||||
dataSourceSchema: string,
|
||||
) {
|
||||
const activityTargets =
|
||||
await this.workspaceDataSourceService.executeRawQuery(
|
||||
`SELECT * FROM ${dataSourceSchema}."activityTarget"
|
||||
WHERE "activityId" = $1`,
|
||||
[event.recordId],
|
||||
event.workspaceId,
|
||||
);
|
||||
|
||||
const activity = await this.workspaceDataSourceService.executeRawQuery(
|
||||
`SELECT * FROM ${dataSourceSchema}."activity"
|
||||
WHERE "id" = $1`,
|
||||
[event.recordId],
|
||||
event.workspaceId,
|
||||
);
|
||||
|
||||
if (activityTargets.length === 0) return;
|
||||
if (activity.length === 0) return;
|
||||
|
||||
return activityTargets
|
||||
.map((activityTarget) => {
|
||||
const targetColumn: string[] = Object.entries(activityTarget)
|
||||
.map(([columnName, columnValue]: [string, string]) => {
|
||||
if (columnName === 'activityId' || !columnName.endsWith('Id'))
|
||||
return;
|
||||
if (columnValue === null) return;
|
||||
|
||||
return columnName;
|
||||
})
|
||||
.filter((column): column is string => column !== undefined);
|
||||
|
||||
if (targetColumn.length === 0) return;
|
||||
|
||||
return {
|
||||
...event,
|
||||
name: activity[0].type.toLowerCase() + '.' + event.name.split('.')[1],
|
||||
objectName: targetColumn[0].replace(/Id$/, ''),
|
||||
recordId: activityTarget[targetColumn[0]],
|
||||
linkedRecordCachedName: activity[0].title,
|
||||
linkedRecordId: activity[0].id,
|
||||
linkedObjectMetadataId: event.objectMetadata.id,
|
||||
} as TransformedEvent;
|
||||
})
|
||||
.filter((event): event is TransformedEvent => event !== undefined);
|
||||
}
|
||||
|
||||
private async processActivityTarget(
|
||||
event: ObjectRecordBaseEvent,
|
||||
dataSourceSchema: string,
|
||||
) {
|
||||
const activityTarget =
|
||||
await this.workspaceDataSourceService.executeRawQuery(
|
||||
`SELECT * FROM ${dataSourceSchema}."activityTarget"
|
||||
WHERE "id" = $1`,
|
||||
[event.recordId],
|
||||
event.workspaceId,
|
||||
);
|
||||
|
||||
if (activityTarget.length === 0) return;
|
||||
|
||||
const activity = await this.workspaceDataSourceService.executeRawQuery(
|
||||
`SELECT * FROM ${dataSourceSchema}."activity"
|
||||
WHERE "id" = $1`,
|
||||
[activityTarget[0].activityId],
|
||||
event.workspaceId,
|
||||
);
|
||||
|
||||
if (activity.length === 0) return;
|
||||
|
||||
const activityObjectMetadataId = event.objectMetadata.fields.find(
|
||||
(field) => field.name === 'activity',
|
||||
)?.toRelationMetadata?.fromObjectMetadataId;
|
||||
|
||||
const targetColumn: string[] = Object.entries(activityTarget[0])
|
||||
.map(([columnName, columnValue]: [string, string]) => {
|
||||
if (columnName === 'activityId' || !columnName.endsWith('Id')) return;
|
||||
if (columnValue === null) return;
|
||||
|
||||
return columnName;
|
||||
})
|
||||
.filter((column): column is string => column !== undefined);
|
||||
|
||||
if (targetColumn.length === 0) return;
|
||||
|
||||
return [
|
||||
{
|
||||
...event,
|
||||
name: activity[0].type.toLowerCase() + '.' + event.name.split('.')[1],
|
||||
properties: {},
|
||||
objectName: targetColumn[0].replace(/Id$/, ''),
|
||||
recordId: activityTarget[0][targetColumn[0]],
|
||||
linkedRecordCachedName: activity[0].title,
|
||||
linkedRecordId: activity[0].id,
|
||||
linkedObjectMetadataId: activityObjectMetadataId,
|
||||
},
|
||||
] as TransformedEvent[];
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,96 @@
|
||||
import { Relation } from 'src/engine/workspace-manager/workspace-sync-metadata/interfaces/relation.interface';
|
||||
|
||||
import { FeatureFlagKeys } from 'src/engine/core-modules/feature-flag/feature-flag.entity';
|
||||
import { FieldMetadataType } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
|
||||
import { auditLogStandardFieldIds } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids';
|
||||
import { standardObjectIds } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-ids';
|
||||
import { FieldMetadata } from 'src/engine/workspace-manager/workspace-sync-metadata/decorators/field-metadata.decorator';
|
||||
import { Gate } from 'src/engine/workspace-manager/workspace-sync-metadata/decorators/gate.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 { BaseObjectMetadata } from 'src/engine/workspace-manager/workspace-sync-metadata/standard-objects/base.object-metadata';
|
||||
import { WorkspaceMemberObjectMetadata } from 'src/modules/workspace-member/standard-objects/workspace-member.object-metadata';
|
||||
|
||||
@ObjectMetadata({
|
||||
standardId: standardObjectIds.auditLog,
|
||||
namePlural: 'auditLogs',
|
||||
labelSingular: 'Audit Log',
|
||||
labelPlural: 'Audit Logs',
|
||||
description: 'An audit log of actions performed in the system',
|
||||
icon: 'IconIconTimelineEvent',
|
||||
})
|
||||
@IsSystem()
|
||||
@Gate({
|
||||
featureFlag: FeatureFlagKeys.IsEventObjectEnabled,
|
||||
})
|
||||
export class AuditLogObjectMetadata extends BaseObjectMetadata {
|
||||
@FieldMetadata({
|
||||
standardId: auditLogStandardFieldIds.name,
|
||||
type: FieldMetadataType.TEXT,
|
||||
label: 'Event name',
|
||||
description: 'Event name/type',
|
||||
icon: 'IconAbc',
|
||||
})
|
||||
name: string;
|
||||
|
||||
@FieldMetadata({
|
||||
standardId: auditLogStandardFieldIds.properties,
|
||||
type: FieldMetadataType.RAW_JSON,
|
||||
label: 'Event details',
|
||||
description: 'Json value for event details',
|
||||
icon: 'IconListDetails',
|
||||
})
|
||||
@IsNullable()
|
||||
properties: JSON;
|
||||
|
||||
@FieldMetadata({
|
||||
standardId: auditLogStandardFieldIds.context,
|
||||
type: FieldMetadataType.RAW_JSON,
|
||||
label: 'Event context',
|
||||
description:
|
||||
'Json object to provide context (user, device, workspace, etc.)',
|
||||
icon: 'IconListDetails',
|
||||
})
|
||||
@IsNullable()
|
||||
context: JSON;
|
||||
|
||||
@FieldMetadata({
|
||||
standardId: auditLogStandardFieldIds.objectName,
|
||||
type: FieldMetadataType.TEXT,
|
||||
label: 'Object name',
|
||||
description: 'If the event is related to a particular object',
|
||||
icon: 'IconAbc',
|
||||
})
|
||||
objectName: string;
|
||||
|
||||
@FieldMetadata({
|
||||
standardId: auditLogStandardFieldIds.objectName,
|
||||
type: FieldMetadataType.TEXT,
|
||||
label: 'Object name',
|
||||
description: 'If the event is related to a particular object',
|
||||
icon: 'IconAbc',
|
||||
})
|
||||
objectMetadataId: string;
|
||||
|
||||
@FieldMetadata({
|
||||
standardId: auditLogStandardFieldIds.recordId,
|
||||
type: FieldMetadataType.UUID,
|
||||
label: 'Object id',
|
||||
description: 'Event name/type',
|
||||
icon: 'IconAbc',
|
||||
})
|
||||
@IsNullable()
|
||||
recordId: string;
|
||||
|
||||
@FieldMetadata({
|
||||
standardId: auditLogStandardFieldIds.workspaceMember,
|
||||
type: FieldMetadataType.RELATION,
|
||||
label: 'Workspace Member',
|
||||
description: 'Event workspace member',
|
||||
icon: 'IconCircleUser',
|
||||
joinColumn: 'workspaceMemberId',
|
||||
})
|
||||
@IsNullable()
|
||||
workspaceMember: Relation<WorkspaceMemberObjectMetadata>;
|
||||
}
|
||||
@ -0,0 +1,90 @@
|
||||
import { FeatureFlagKeys } from 'src/engine/core-modules/feature-flag/feature-flag.entity';
|
||||
import { FieldMetadataType } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
|
||||
import { behavioralEventStandardFieldIds } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids';
|
||||
import { standardObjectIds } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-ids';
|
||||
import { FieldMetadata } from 'src/engine/workspace-manager/workspace-sync-metadata/decorators/field-metadata.decorator';
|
||||
import { Gate } from 'src/engine/workspace-manager/workspace-sync-metadata/decorators/gate.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 { BaseObjectMetadata } from 'src/engine/workspace-manager/workspace-sync-metadata/standard-objects/base.object-metadata';
|
||||
|
||||
@ObjectMetadata({
|
||||
standardId: standardObjectIds.behavioralEvent,
|
||||
namePlural: 'behavioralEvents',
|
||||
labelSingular: 'Behavioral Event',
|
||||
labelPlural: 'Behavioral Events',
|
||||
description: 'An event related to user behavior',
|
||||
icon: 'IconIconTimelineEvent',
|
||||
})
|
||||
@IsSystem()
|
||||
@Gate({
|
||||
featureFlag: FeatureFlagKeys.IsEventObjectEnabled,
|
||||
})
|
||||
export class BehavioralEventObjectMetadata extends BaseObjectMetadata {
|
||||
/**
|
||||
*
|
||||
* Common in Segment, Rudderstack, etc.
|
||||
* = Track, Screen, Page...
|
||||
* But doesn't feel that useful.
|
||||
* Let's try living without it.
|
||||
*
|
||||
@FieldMetadata({
|
||||
standardId: behavioralEventStandardFieldIds.type,
|
||||
type: FieldMetadataType.TEXT,
|
||||
label: 'Event type',
|
||||
description: 'Event type',
|
||||
icon: 'IconAbc',
|
||||
})
|
||||
type: string;
|
||||
*/
|
||||
|
||||
@FieldMetadata({
|
||||
standardId: behavioralEventStandardFieldIds.name,
|
||||
type: FieldMetadataType.TEXT,
|
||||
label: 'Event name',
|
||||
description: 'Event name',
|
||||
icon: 'IconAbc',
|
||||
})
|
||||
name: string;
|
||||
|
||||
@FieldMetadata({
|
||||
standardId: behavioralEventStandardFieldIds.properties,
|
||||
type: FieldMetadataType.RAW_JSON,
|
||||
label: 'Event details',
|
||||
description: 'Json value for event details',
|
||||
icon: 'IconListDetails',
|
||||
})
|
||||
@IsNullable()
|
||||
properties: JSON;
|
||||
|
||||
@FieldMetadata({
|
||||
standardId: behavioralEventStandardFieldIds.context,
|
||||
type: FieldMetadataType.RAW_JSON,
|
||||
label: 'Event context',
|
||||
description:
|
||||
'Json object to provide context (user, device, workspace, etc.)',
|
||||
icon: 'IconListDetails',
|
||||
})
|
||||
@IsNullable()
|
||||
context: JSON;
|
||||
|
||||
@FieldMetadata({
|
||||
standardId: behavioralEventStandardFieldIds.objectName,
|
||||
type: FieldMetadataType.TEXT,
|
||||
label: 'Object name',
|
||||
description: 'If the event is related to a particular object',
|
||||
icon: 'IconAbc',
|
||||
})
|
||||
objectName: string;
|
||||
|
||||
@FieldMetadata({
|
||||
standardId: behavioralEventStandardFieldIds.recordId,
|
||||
type: FieldMetadataType.UUID,
|
||||
label: 'Object id',
|
||||
description: 'Event name/type',
|
||||
icon: 'IconAbc',
|
||||
})
|
||||
@IsNullable()
|
||||
recordId: string;
|
||||
}
|
||||
@ -0,0 +1,148 @@
|
||||
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 { timelineActivityStandardFieldIds } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids';
|
||||
import { standardObjectIds } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-ids';
|
||||
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 { IsNotAuditLogged } from 'src/engine/workspace-manager/workspace-sync-metadata/decorators/is-not-audit-logged.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 { 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 { FeatureFlagKeys } from 'src/engine/core-modules/feature-flag/feature-flag.entity';
|
||||
import { Gate } from 'src/engine/workspace-manager/workspace-sync-metadata/decorators/gate.decorator';
|
||||
import { CustomObjectMetadata } from 'src/engine/workspace-manager/workspace-sync-metadata/custom-objects/custom.object-metadata';
|
||||
|
||||
@ObjectMetadata({
|
||||
standardId: standardObjectIds.timelineActivity,
|
||||
namePlural: 'timelineActivities',
|
||||
labelSingular: 'Timeline Activity',
|
||||
labelPlural: 'Timeline Activities',
|
||||
description: 'Aggregated / filtered event to be displayed on the timeline',
|
||||
icon: 'IconIconTimelineEvent',
|
||||
})
|
||||
@IsSystem()
|
||||
@IsNotAuditLogged()
|
||||
@Gate({
|
||||
featureFlag: FeatureFlagKeys.IsEventObjectEnabled,
|
||||
})
|
||||
export class TimelineActivityObjectMetadata extends BaseObjectMetadata {
|
||||
@FieldMetadata({
|
||||
standardId: timelineActivityStandardFieldIds.happensAt,
|
||||
type: FieldMetadataType.DATE_TIME,
|
||||
label: 'Creation date',
|
||||
description: 'Creation date',
|
||||
icon: 'IconCalendar',
|
||||
defaultValue: 'now',
|
||||
})
|
||||
happensAt: Date;
|
||||
|
||||
@FieldMetadata({
|
||||
standardId: timelineActivityStandardFieldIds.name,
|
||||
type: FieldMetadataType.TEXT,
|
||||
label: 'Event name',
|
||||
description: 'Event name',
|
||||
icon: 'IconAbc',
|
||||
})
|
||||
name: string;
|
||||
|
||||
@FieldMetadata({
|
||||
standardId: timelineActivityStandardFieldIds.properties,
|
||||
type: FieldMetadataType.RAW_JSON,
|
||||
label: 'Event details',
|
||||
description: 'Json value for event details',
|
||||
icon: 'IconListDetails',
|
||||
})
|
||||
@IsNullable()
|
||||
properties: JSON;
|
||||
|
||||
// Who made the action
|
||||
@FieldMetadata({
|
||||
standardId: timelineActivityStandardFieldIds.workspaceMember,
|
||||
type: FieldMetadataType.RELATION,
|
||||
label: 'Workspace Member',
|
||||
description: 'Event workspace member',
|
||||
icon: 'IconCircleUser',
|
||||
joinColumn: 'workspaceMemberId',
|
||||
})
|
||||
@IsNullable()
|
||||
workspaceMember: Relation<WorkspaceMemberObjectMetadata>;
|
||||
|
||||
@FieldMetadata({
|
||||
standardId: timelineActivityStandardFieldIds.person,
|
||||
type: FieldMetadataType.RELATION,
|
||||
label: 'Person',
|
||||
description: 'Event person',
|
||||
icon: 'IconUser',
|
||||
joinColumn: 'personId',
|
||||
})
|
||||
@IsNullable()
|
||||
person: Relation<PersonObjectMetadata>;
|
||||
|
||||
@FieldMetadata({
|
||||
standardId: timelineActivityStandardFieldIds.company,
|
||||
type: FieldMetadataType.RELATION,
|
||||
label: 'Company',
|
||||
description: 'Event company',
|
||||
icon: 'IconBuildingSkyscraper',
|
||||
joinColumn: 'companyId',
|
||||
})
|
||||
@IsNullable()
|
||||
company: Relation<CompanyObjectMetadata>;
|
||||
|
||||
@FieldMetadata({
|
||||
standardId: timelineActivityStandardFieldIds.opportunity,
|
||||
type: FieldMetadataType.RELATION,
|
||||
label: 'Opportunity',
|
||||
description: 'Events opportunity',
|
||||
icon: 'IconTargetArrow',
|
||||
joinColumn: 'opportunityId',
|
||||
})
|
||||
@IsNullable()
|
||||
opportunity: Relation<OpportunityObjectMetadata>;
|
||||
|
||||
@DynamicRelationFieldMetadata((oppositeObjectMetadata) => ({
|
||||
standardId: timelineActivityStandardFieldIds.custom,
|
||||
name: oppositeObjectMetadata.nameSingular,
|
||||
label: oppositeObjectMetadata.labelSingular,
|
||||
description: `Event ${oppositeObjectMetadata.labelSingular}`,
|
||||
joinColumn: `${oppositeObjectMetadata.nameSingular}Id`,
|
||||
icon: 'IconTimeline',
|
||||
}))
|
||||
custom: Relation<CustomObjectMetadata>;
|
||||
|
||||
// Special objects that don't have their own timeline and are 'link' to the main object
|
||||
@FieldMetadata({
|
||||
standardId: timelineActivityStandardFieldIds.linkedRecordCachedName,
|
||||
type: FieldMetadataType.TEXT,
|
||||
label: 'Linked Record cached name',
|
||||
description: 'Cached record name',
|
||||
icon: 'IconAbc',
|
||||
})
|
||||
linkedRecordCachedName: string;
|
||||
|
||||
@FieldMetadata({
|
||||
standardId: timelineActivityStandardFieldIds.linkedRecordId,
|
||||
type: FieldMetadataType.UUID,
|
||||
label: 'Linked Record id',
|
||||
description: 'Linked Record id',
|
||||
icon: 'IconAbc',
|
||||
})
|
||||
@IsNullable()
|
||||
linkedRecordId: string;
|
||||
|
||||
@FieldMetadata({
|
||||
standardId: timelineActivityStandardFieldIds.linkedObjectMetadataId,
|
||||
type: FieldMetadataType.UUID,
|
||||
label: 'Linked Object Metadata Id',
|
||||
description: 'inked Object Metadata Id',
|
||||
icon: 'IconAbc',
|
||||
})
|
||||
@IsNullable()
|
||||
linkedObjectMetadataId: string;
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
|
||||
import { ObjectMetadataRepositoryModule } from 'src/engine/object-metadata-repository/object-metadata-repository.module';
|
||||
import { WorkspaceDataSourceModule } from 'src/engine/workspace-datasource/workspace-datasource.module';
|
||||
import { TimelineActivityService } from 'src/modules/timeline/services/timeline-activity.service';
|
||||
import { TimelineActivityObjectMetadata } from 'src/modules/timeline/standard-objects/timeline-activity.object-metadata';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
WorkspaceDataSourceModule,
|
||||
ObjectMetadataRepositoryModule.forFeature([TimelineActivityObjectMetadata]),
|
||||
],
|
||||
providers: [TimelineActivityService],
|
||||
exports: [TimelineActivityService],
|
||||
})
|
||||
export class TimelineActivityModule {}
|
||||
@ -24,7 +24,8 @@ import { ConnectedAccountObjectMetadata } from 'src/modules/connected-account/st
|
||||
import { FavoriteObjectMetadata } from 'src/modules/favorite/standard-objects/favorite.object-metadata';
|
||||
import { MessageParticipantObjectMetadata } from 'src/modules/messaging/standard-objects/message-participant.object-metadata';
|
||||
import { IsNullable } from 'src/engine/workspace-manager/workspace-sync-metadata/decorators/is-nullable.decorator';
|
||||
import { EventObjectMetadata } from 'src/modules/event/standard-objects/event.object-metadata';
|
||||
import { TimelineActivityObjectMetadata } from 'src/modules/timeline/standard-objects/timeline-activity.object-metadata';
|
||||
import { AuditLogObjectMetadata } from 'src/modules/timeline/standard-objects/audit-log.object-metadata';
|
||||
import { IsNotAuditLogged } from 'src/engine/workspace-manager/workspace-sync-metadata/decorators/is-not-audit-logged.decorator';
|
||||
|
||||
@ObjectMetadata({
|
||||
@ -248,7 +249,7 @@ export class WorkspaceMemberObjectMetadata extends BaseObjectMetadata {
|
||||
calendarEventParticipants: Relation<CalendarEventParticipantObjectMetadata[]>;
|
||||
|
||||
@FieldMetadata({
|
||||
standardId: workspaceMemberStandardFieldIds.events,
|
||||
standardId: workspaceMemberStandardFieldIds.timelineActivities,
|
||||
type: FieldMetadataType.RELATION,
|
||||
label: 'Events',
|
||||
description: 'Events linked to the workspace member',
|
||||
@ -256,10 +257,26 @@ export class WorkspaceMemberObjectMetadata extends BaseObjectMetadata {
|
||||
})
|
||||
@RelationMetadata({
|
||||
type: RelationMetadataType.ONE_TO_MANY,
|
||||
inverseSideTarget: () => EventObjectMetadata,
|
||||
inverseSideTarget: () => TimelineActivityObjectMetadata,
|
||||
onDelete: RelationOnDeleteAction.CASCADE,
|
||||
})
|
||||
@IsNullable()
|
||||
@IsSystem()
|
||||
events: Relation<EventObjectMetadata[]>;
|
||||
timelineActivities: Relation<TimelineActivityObjectMetadata[]>;
|
||||
|
||||
@FieldMetadata({
|
||||
standardId: workspaceMemberStandardFieldIds.auditLogs,
|
||||
type: FieldMetadataType.RELATION,
|
||||
label: 'Aud tLogs',
|
||||
description: 'Audit Logs linked to the workspace member',
|
||||
icon: 'IconTimelineEvent',
|
||||
})
|
||||
@RelationMetadata({
|
||||
type: RelationMetadataType.ONE_TO_MANY,
|
||||
inverseSideTarget: () => AuditLogObjectMetadata,
|
||||
onDelete: RelationOnDeleteAction.SET_NULL,
|
||||
})
|
||||
@IsNullable()
|
||||
@IsSystem()
|
||||
auditLogs: Relation<AuditLogObjectMetadata[]>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user