mirror of
https://github.com/twentyhq/twenty.git
synced 2024-09-11 15:35:36 +03:00
feat: manually implement joinColumn (#6022)
This PR introduce a new decorator named `@WorkspaceJoinColumn`, the goal of this one is to manually declare the join columns inside the workspace entities, so we don't have to rely on `ObjectRecord` type. This decorator can be used that way: ```typescript @WorkspaceRelation({ standardId: ACTIVITY_TARGET_STANDARD_FIELD_IDS.company, type: RelationMetadataType.MANY_TO_ONE, label: 'Company', description: 'ActivityTarget company', icon: 'IconBuildingSkyscraper', inverseSideTarget: () => CompanyWorkspaceEntity, inverseSideFieldKey: 'activityTargets', }) @WorkspaceIsNullable() company: Relation<CompanyWorkspaceEntity> | null; // The argument is the name of the relation above @WorkspaceJoinColumn('company') companyId: string | null; ```
This commit is contained in:
parent
7eb69a78ef
commit
95c5602a4e
@ -31,9 +31,7 @@ export class TimelineCalendarEventService {
|
||||
const calendarEventIds = await this.calendarEventRepository.find({
|
||||
where: {
|
||||
calendarEventParticipants: {
|
||||
person: {
|
||||
id: Any(personIds),
|
||||
},
|
||||
personId: Any(personIds),
|
||||
},
|
||||
},
|
||||
select: {
|
||||
@ -81,8 +79,8 @@ export class TimelineCalendarEventService {
|
||||
const participants = event.calendarEventParticipants.map(
|
||||
(participant) => ({
|
||||
calendarEventId: event.id,
|
||||
personId: participant.person?.id ?? null,
|
||||
workspaceMemberId: participant.workspaceMember?.id ?? null,
|
||||
personId: participant.personId ?? null,
|
||||
workspaceMemberId: participant.workspaceMemberId ?? null,
|
||||
firstName:
|
||||
participant.person?.name?.firstName ||
|
||||
participant.workspaceMember?.name.firstName ||
|
||||
@ -135,9 +133,7 @@ export class TimelineCalendarEventService {
|
||||
): Promise<TimelineCalendarEventsWithTotal> {
|
||||
const personIds = await this.personRepository.find({
|
||||
where: {
|
||||
company: {
|
||||
id: companyId,
|
||||
},
|
||||
companyId,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
|
@ -12,7 +12,6 @@ import { TypeORMService } from 'src/database/typeorm/typeorm.service';
|
||||
import { DataSourceEntity } from 'src/engine/metadata-modules/data-source/data-source.entity';
|
||||
import { WorkspaceMemberWorkspaceEntity } from 'src/modules/workspace-member/standard-objects/workspace-member.workspace-entity';
|
||||
import { ObjectRecordDeleteEvent } from 'src/engine/integrations/event-emitter/types/object-record-delete.event';
|
||||
import { ObjectRecord } from 'src/engine/workspace-manager/workspace-sync-metadata/types/object-record';
|
||||
import { WorkspaceService } from 'src/engine/core-modules/workspace/services/workspace.service';
|
||||
|
||||
export class UserService extends TypeOrmQueryService<User> {
|
||||
@ -113,8 +112,7 @@ export class UserService extends TypeOrmQueryService<User> {
|
||||
`SELECT * FROM ${dataSourceMetadata.schema}."workspaceMember"`,
|
||||
);
|
||||
const workspaceMember = workspaceMembers.filter(
|
||||
(member: ObjectRecord<WorkspaceMemberWorkspaceEntity>) =>
|
||||
member.userId === userId,
|
||||
(member: WorkspaceMemberWorkspaceEntity) => member.userId === userId,
|
||||
)?.[0];
|
||||
|
||||
assert(workspaceMember, 'WorkspaceMember not found');
|
||||
|
@ -0,0 +1,13 @@
|
||||
import { metadataArgsStorage } from 'src/engine/twenty-orm/storage/metadata-args.storage';
|
||||
|
||||
export function WorkspaceJoinColumn(
|
||||
relationPropertyKey: string,
|
||||
): PropertyDecorator {
|
||||
return (object, propertyKey) => {
|
||||
metadataArgsStorage.addJoinColumns({
|
||||
target: object.constructor,
|
||||
relationName: relationPropertyKey,
|
||||
joinColumn: propertyKey.toString(),
|
||||
});
|
||||
};
|
||||
}
|
@ -8,35 +8,19 @@ import { metadataArgsStorage } from 'src/engine/twenty-orm/storage/metadata-args
|
||||
import { TypedReflect } from 'src/utils/typed-reflect';
|
||||
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
|
||||
|
||||
interface WorkspaceBaseRelationOptions<TType, TClass> {
|
||||
interface WorkspaceRelationOptions<TClass> {
|
||||
standardId: string;
|
||||
label: string | ((objectMetadata: ObjectMetadataEntity) => string);
|
||||
description?: string | ((objectMetadata: ObjectMetadataEntity) => string);
|
||||
icon?: string;
|
||||
type: TType;
|
||||
type: RelationMetadataType;
|
||||
inverseSideTarget: () => ObjectType<TClass>;
|
||||
inverseSideFieldKey?: keyof TClass;
|
||||
onDelete?: RelationOnDeleteAction;
|
||||
}
|
||||
|
||||
export interface WorkspaceManyToOneRelationOptions<TClass>
|
||||
extends WorkspaceBaseRelationOptions<
|
||||
RelationMetadataType.MANY_TO_ONE | RelationMetadataType.ONE_TO_ONE,
|
||||
TClass
|
||||
> {
|
||||
joinColumn?: string;
|
||||
}
|
||||
|
||||
export interface WorkspaceOtherRelationOptions<TClass>
|
||||
extends WorkspaceBaseRelationOptions<
|
||||
RelationMetadataType.ONE_TO_MANY | RelationMetadataType.MANY_TO_MANY,
|
||||
TClass
|
||||
> {}
|
||||
|
||||
export function WorkspaceRelation<TClass extends object>(
|
||||
options:
|
||||
| WorkspaceManyToOneRelationOptions<TClass>
|
||||
| WorkspaceOtherRelationOptions<TClass>,
|
||||
options: WorkspaceRelationOptions<TClass>,
|
||||
): PropertyDecorator {
|
||||
return (object, propertyKey) => {
|
||||
const isPrimary =
|
||||
@ -63,14 +47,6 @@ export function WorkspaceRelation<TClass extends object>(
|
||||
propertyKey.toString(),
|
||||
);
|
||||
|
||||
let joinColumn: string | undefined;
|
||||
|
||||
if ('joinColumn' in options) {
|
||||
joinColumn = options.joinColumn
|
||||
? options.joinColumn
|
||||
: `${propertyKey.toString()}Id`;
|
||||
}
|
||||
|
||||
metadataArgsStorage.addRelations({
|
||||
target: object.constructor,
|
||||
standardId: options.standardId,
|
||||
@ -82,7 +58,6 @@ export function WorkspaceRelation<TClass extends object>(
|
||||
inverseSideTarget: options.inverseSideTarget,
|
||||
inverseSideFieldKey: options.inverseSideFieldKey as string | undefined,
|
||||
onDelete: options.onDelete,
|
||||
joinColumn,
|
||||
isPrimary,
|
||||
isNullable,
|
||||
isSystem,
|
||||
|
@ -4,6 +4,7 @@ import { ColumnType, EntitySchemaColumnOptions } from 'typeorm';
|
||||
|
||||
import { WorkspaceFieldMetadataArgs } from 'src/engine/twenty-orm/interfaces/workspace-field-metadata-args.interface';
|
||||
import { WorkspaceRelationMetadataArgs } from 'src/engine/twenty-orm/interfaces/workspace-relation-metadata-args.interface';
|
||||
import { WorkspaceJoinColumnsMetadataArgs } from 'src/engine/twenty-orm/interfaces/workspace-join-columns-metadata-args.interface';
|
||||
|
||||
import { fieldMetadataTypeToColumnType } from 'src/engine/metadata-modules/workspace-migration/utils/field-metadata-type-to-column-type.util';
|
||||
import { isEnumFieldMetadataType } from 'src/engine/metadata-modules/field-metadata/utils/is-enum-field-metadata-type.util';
|
||||
@ -12,6 +13,7 @@ import { computeCompositeColumnName } from 'src/engine/metadata-modules/field-me
|
||||
import { isCompositeFieldMetadataType } from 'src/engine/metadata-modules/field-metadata/utils/is-composite-field-metadata-type.util';
|
||||
import { compositeTypeDefintions } from 'src/engine/metadata-modules/field-metadata/composite-types';
|
||||
import { FieldMetadataType } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
|
||||
import { getJoinColumn } from 'src/engine/twenty-orm/utils/get-join-column.util';
|
||||
|
||||
type EntitySchemaColumnMap = {
|
||||
[key: string]: EntitySchemaColumnOptions;
|
||||
@ -22,6 +24,7 @@ export class EntitySchemaColumnFactory {
|
||||
create(
|
||||
fieldMetadataArgsCollection: WorkspaceFieldMetadataArgs[],
|
||||
relationMetadataArgsCollection: WorkspaceRelationMetadataArgs[],
|
||||
joinColumnsMetadataArgsCollection: WorkspaceJoinColumnsMetadataArgs[],
|
||||
): EntitySchemaColumnMap {
|
||||
let entitySchemaColumnMap: EntitySchemaColumnMap = {};
|
||||
|
||||
@ -56,9 +59,14 @@ export class EntitySchemaColumnFactory {
|
||||
};
|
||||
|
||||
for (const relationMetadataArgs of relationMetadataArgsCollection) {
|
||||
if (relationMetadataArgs.joinColumn) {
|
||||
entitySchemaColumnMap[relationMetadataArgs.joinColumn] = {
|
||||
name: relationMetadataArgs.joinColumn,
|
||||
const joinColumn = getJoinColumn(
|
||||
joinColumnsMetadataArgsCollection,
|
||||
relationMetadataArgs,
|
||||
);
|
||||
|
||||
if (joinColumn) {
|
||||
entitySchemaColumnMap[joinColumn] = {
|
||||
name: joinColumn,
|
||||
type: 'uuid',
|
||||
nullable: relationMetadataArgs.isNullable,
|
||||
};
|
||||
|
@ -4,9 +4,11 @@ import { EntitySchemaRelationOptions } from 'typeorm';
|
||||
import { RelationType } from 'typeorm/metadata/types/RelationTypes';
|
||||
|
||||
import { WorkspaceRelationMetadataArgs } from 'src/engine/twenty-orm/interfaces/workspace-relation-metadata-args.interface';
|
||||
import { WorkspaceJoinColumnsMetadataArgs } from 'src/engine/twenty-orm/interfaces/workspace-join-columns-metadata-args.interface';
|
||||
|
||||
import { convertClassNameToObjectMetadataName } from 'src/engine/workspace-manager/workspace-sync-metadata/utils/convert-class-to-object-metadata-name.util';
|
||||
import { RelationMetadataType } from 'src/engine/metadata-modules/relation-metadata/relation-metadata.entity';
|
||||
import { getJoinColumn } from 'src/engine/twenty-orm/utils/get-join-column.util';
|
||||
|
||||
type EntitySchemaRelationMap = {
|
||||
[key: string]: EntitySchemaRelationOptions;
|
||||
@ -18,6 +20,7 @@ export class EntitySchemaRelationFactory {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
target: Function,
|
||||
relationMetadataArgsCollection: WorkspaceRelationMetadataArgs[],
|
||||
joinColumnsMetadataArgsCollection: WorkspaceJoinColumnsMetadataArgs[],
|
||||
): EntitySchemaRelationMap {
|
||||
const entitySchemaRelationMap: EntitySchemaRelationMap = {};
|
||||
|
||||
@ -27,16 +30,19 @@ export class EntitySchemaRelationFactory {
|
||||
const oppositeObjectName = convertClassNameToObjectMetadataName(
|
||||
oppositeTarget.name,
|
||||
);
|
||||
|
||||
const relationType = this.getRelationType(relationMetadataArgs);
|
||||
const joinColumn = getJoinColumn(
|
||||
joinColumnsMetadataArgsCollection,
|
||||
relationMetadataArgs,
|
||||
);
|
||||
|
||||
entitySchemaRelationMap[relationMetadataArgs.name] = {
|
||||
type: relationType,
|
||||
target: oppositeObjectName,
|
||||
inverseSide: relationMetadataArgs.inverseSideFieldKey ?? objectName,
|
||||
joinColumn: relationMetadataArgs.joinColumn
|
||||
joinColumn: joinColumn
|
||||
? {
|
||||
name: relationMetadataArgs.joinColumn,
|
||||
name: joinColumn,
|
||||
}
|
||||
: undefined,
|
||||
};
|
||||
|
@ -23,17 +23,21 @@ export class EntitySchemaFactory {
|
||||
|
||||
const fieldMetadataArgsCollection =
|
||||
metadataArgsStorage.filterFields(target);
|
||||
const joinColumnsMetadataArgsCollection =
|
||||
metadataArgsStorage.filterJoinColumns(target);
|
||||
const relationMetadataArgsCollection =
|
||||
metadataArgsStorage.filterRelations(target);
|
||||
|
||||
const columns = this.entitySchemaColumnFactory.create(
|
||||
fieldMetadataArgsCollection,
|
||||
relationMetadataArgsCollection,
|
||||
joinColumnsMetadataArgsCollection,
|
||||
);
|
||||
|
||||
const relations = this.entitySchemaRelationFactory.create(
|
||||
target,
|
||||
relationMetadataArgsCollection,
|
||||
joinColumnsMetadataArgsCollection,
|
||||
);
|
||||
|
||||
const entitySchema = new EntitySchema({
|
||||
|
@ -0,0 +1,17 @@
|
||||
export interface WorkspaceJoinColumnsMetadataArgs {
|
||||
/**
|
||||
* Class to which relation is applied.
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
readonly target: Function;
|
||||
|
||||
/**
|
||||
* Relation name.
|
||||
*/
|
||||
readonly relationName: string;
|
||||
|
||||
/**
|
||||
* Relation label.
|
||||
*/
|
||||
readonly joinColumn: string;
|
||||
}
|
@ -62,11 +62,6 @@ export interface WorkspaceRelationMetadataArgs {
|
||||
*/
|
||||
readonly onDelete?: RelationOnDeleteAction;
|
||||
|
||||
/**
|
||||
* Relation join column.
|
||||
*/
|
||||
readonly joinColumn?: string;
|
||||
|
||||
/**
|
||||
* Is primary field.
|
||||
*/
|
||||
|
@ -6,6 +6,7 @@ import { WorkspaceEntityMetadataArgs } from 'src/engine/twenty-orm/interfaces/wo
|
||||
import { WorkspaceRelationMetadataArgs } from 'src/engine/twenty-orm/interfaces/workspace-relation-metadata-args.interface';
|
||||
import { WorkspaceExtendedEntityMetadataArgs } from 'src/engine/twenty-orm/interfaces/workspace-extended-entity-metadata-args.interface';
|
||||
import { WorkspaceIndexMetadataArgs } from 'src/engine/twenty-orm/interfaces/workspace-index-metadata-args.interface';
|
||||
import { WorkspaceJoinColumnsMetadataArgs } from 'src/engine/twenty-orm/interfaces/workspace-join-columns-metadata-args.interface';
|
||||
|
||||
export class MetadataArgsStorage {
|
||||
private readonly entities: WorkspaceEntityMetadataArgs[] = [];
|
||||
@ -15,6 +16,7 @@ export class MetadataArgsStorage {
|
||||
private readonly dynamicRelations: WorkspaceDynamicRelationMetadataArgs[] =
|
||||
[];
|
||||
private readonly indexes: WorkspaceIndexMetadataArgs[] = [];
|
||||
private readonly joinColumns: WorkspaceJoinColumnsMetadataArgs[] = [];
|
||||
|
||||
addEntities(...entities: WorkspaceEntityMetadataArgs[]): void {
|
||||
this.entities.push(...entities);
|
||||
@ -44,6 +46,10 @@ export class MetadataArgsStorage {
|
||||
this.dynamicRelations.push(...dynamicRelations);
|
||||
}
|
||||
|
||||
addJoinColumns(...joinColumns: WorkspaceJoinColumnsMetadataArgs[]): void {
|
||||
this.joinColumns.push(...joinColumns);
|
||||
}
|
||||
|
||||
filterEntities(
|
||||
target: Function | string,
|
||||
): WorkspaceEntityMetadataArgs | undefined;
|
||||
@ -123,6 +129,20 @@ export class MetadataArgsStorage {
|
||||
return this.filterByTarget(this.dynamicRelations, target);
|
||||
}
|
||||
|
||||
filterJoinColumns(
|
||||
target: Function | string,
|
||||
): WorkspaceJoinColumnsMetadataArgs[];
|
||||
|
||||
filterJoinColumns(
|
||||
target: (Function | string)[],
|
||||
): WorkspaceJoinColumnsMetadataArgs[];
|
||||
|
||||
filterJoinColumns(
|
||||
target: (Function | string) | (Function | string)[],
|
||||
): WorkspaceJoinColumnsMetadataArgs[] {
|
||||
return this.filterByTarget(this.joinColumns, target);
|
||||
}
|
||||
|
||||
protected filterByTarget<T extends { target: Function | string }>(
|
||||
array: T[],
|
||||
target: (Function | string) | (Function | string)[],
|
||||
|
@ -0,0 +1,87 @@
|
||||
import { WorkspaceJoinColumnsMetadataArgs } from 'src/engine/twenty-orm/interfaces/workspace-join-columns-metadata-args.interface';
|
||||
import { WorkspaceRelationMetadataArgs } from 'src/engine/twenty-orm/interfaces/workspace-relation-metadata-args.interface';
|
||||
|
||||
import { RelationMetadataType } from 'src/engine/metadata-modules/relation-metadata/relation-metadata.entity';
|
||||
import { metadataArgsStorage } from 'src/engine/twenty-orm/storage/metadata-args.storage';
|
||||
|
||||
export const getJoinColumn = (
|
||||
joinColumnsMetadataArgsCollection: WorkspaceJoinColumnsMetadataArgs[],
|
||||
relationMetadataArgs: WorkspaceRelationMetadataArgs,
|
||||
opposite = false,
|
||||
): string | null => {
|
||||
if (
|
||||
relationMetadataArgs.type === RelationMetadataType.ONE_TO_MANY ||
|
||||
relationMetadataArgs.type === RelationMetadataType.MANY_TO_MANY
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const inverseSideTarget = relationMetadataArgs.inverseSideTarget();
|
||||
const inverseSideJoinColumnsMetadataArgsCollection =
|
||||
metadataArgsStorage.filterJoinColumns(inverseSideTarget);
|
||||
const filteredJoinColumnsMetadataArgsCollection =
|
||||
joinColumnsMetadataArgsCollection.filter(
|
||||
(joinColumnsMetadataArgs) =>
|
||||
joinColumnsMetadataArgs.relationName === relationMetadataArgs.name,
|
||||
);
|
||||
const oppositeFilteredJoinColumnsMetadataArgsCollection =
|
||||
inverseSideJoinColumnsMetadataArgsCollection.filter(
|
||||
(joinColumnsMetadataArgs) =>
|
||||
joinColumnsMetadataArgs.relationName === relationMetadataArgs.name,
|
||||
);
|
||||
|
||||
if (
|
||||
filteredJoinColumnsMetadataArgsCollection.length > 0 &&
|
||||
oppositeFilteredJoinColumnsMetadataArgsCollection.length > 0
|
||||
) {
|
||||
throw new Error(
|
||||
`Join column for ${relationMetadataArgs.name} relation is present on both sides`,
|
||||
);
|
||||
}
|
||||
|
||||
// If we're in a ONE_TO_ONE relation and there are no join columns, we need to find the join column on the inverse side
|
||||
if (
|
||||
relationMetadataArgs.type === RelationMetadataType.ONE_TO_ONE &&
|
||||
filteredJoinColumnsMetadataArgsCollection.length === 0 &&
|
||||
!opposite
|
||||
) {
|
||||
const inverseSideRelationMetadataArgsCollection =
|
||||
metadataArgsStorage.filterRelations(inverseSideTarget);
|
||||
const inverseSideRelationMetadataArgs =
|
||||
inverseSideRelationMetadataArgsCollection.find(
|
||||
(inverseSideRelationMetadataArgs) =>
|
||||
inverseSideRelationMetadataArgs.inverseSideFieldKey ===
|
||||
relationMetadataArgs.name,
|
||||
);
|
||||
|
||||
if (!inverseSideRelationMetadataArgs) {
|
||||
throw new Error(
|
||||
`Inverse side join column of relation ${relationMetadataArgs.name} is missing`,
|
||||
);
|
||||
}
|
||||
|
||||
return getJoinColumn(
|
||||
inverseSideJoinColumnsMetadataArgsCollection,
|
||||
inverseSideRelationMetadataArgs,
|
||||
// Avoid infinite recursion
|
||||
true,
|
||||
);
|
||||
}
|
||||
|
||||
// Check if there are multiple join columns for the relation
|
||||
if (filteredJoinColumnsMetadataArgsCollection.length > 1) {
|
||||
throw new Error(
|
||||
`Multiple join columns found for relation ${relationMetadataArgs.name}`,
|
||||
);
|
||||
}
|
||||
|
||||
const joinColumnsMetadataArgs = filteredJoinColumnsMetadataArgsCollection[0];
|
||||
|
||||
if (!joinColumnsMetadataArgs) {
|
||||
throw new Error(
|
||||
`Join column is missing for relation ${relationMetadataArgs.name}`,
|
||||
);
|
||||
}
|
||||
|
||||
return joinColumnsMetadataArgs.joinColumn;
|
||||
};
|
@ -16,6 +16,7 @@ import { metadataArgsStorage } from 'src/engine/twenty-orm/storage/metadata-args
|
||||
import { BaseWorkspaceEntity } from 'src/engine/twenty-orm/base.workspace-entity';
|
||||
import { FieldMetadataType } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
|
||||
import { createDeterministicUuid } from 'src/engine/workspace-manager/workspace-sync-metadata/utils/create-deterministic-uuid.util';
|
||||
import { getJoinColumn } from 'src/engine/twenty-orm/utils/get-join-column.util';
|
||||
|
||||
@Injectable()
|
||||
export class StandardFieldFactory {
|
||||
@ -139,6 +140,14 @@ export class StandardFieldFactory {
|
||||
const foreignKeyStandardId = createDeterministicUuid(
|
||||
workspaceRelationMetadataArgs.standardId,
|
||||
);
|
||||
const joinColumnMetadataArgsCollection =
|
||||
metadataArgsStorage.filterJoinColumns(
|
||||
workspaceRelationMetadataArgs.target,
|
||||
);
|
||||
const joinColumn = getJoinColumn(
|
||||
joinColumnMetadataArgsCollection,
|
||||
workspaceRelationMetadataArgs,
|
||||
);
|
||||
|
||||
if (
|
||||
isGatedAndNotEnabled(
|
||||
@ -149,11 +158,11 @@ export class StandardFieldFactory {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (workspaceRelationMetadataArgs.joinColumn) {
|
||||
if (joinColumn) {
|
||||
fieldMetadataCollection.push({
|
||||
type: FieldMetadataType.UUID,
|
||||
standardId: foreignKeyStandardId,
|
||||
name: workspaceRelationMetadataArgs.joinColumn,
|
||||
name: joinColumn,
|
||||
label: `${workspaceRelationMetadataArgs.label} id (foreign key)`,
|
||||
description: `${workspaceRelationMetadataArgs.description} id foreign key`,
|
||||
icon: workspaceRelationMetadataArgs.icon,
|
||||
|
@ -1,20 +0,0 @@
|
||||
import { BaseWorkspaceEntity } from 'src/engine/twenty-orm/base.workspace-entity';
|
||||
|
||||
type RelationKeys<T> = {
|
||||
[K in keyof T]: NonNullable<T[K]> extends BaseWorkspaceEntity ? K : never;
|
||||
}[keyof T];
|
||||
|
||||
type ForeignKeyMap<T> = {
|
||||
[K in RelationKeys<T> as `${K & string}Id`]: string;
|
||||
};
|
||||
|
||||
type RecursiveObjectRecord<T> = {
|
||||
[P in keyof T]: NonNullable<T[P]> extends BaseWorkspaceEntity
|
||||
? ObjectRecord<NonNullable<T[P]>> & ForeignKeyMap<NonNullable<T[P]>>
|
||||
: T[P];
|
||||
};
|
||||
|
||||
// TODO: We should get rid of that it's causing too much issues
|
||||
// Some relations can be null or undefined because they're not mendatory and other cannot
|
||||
// This utility type put as defined all the joinColumn, so it's not well typed
|
||||
export type ObjectRecord<T> = RecursiveObjectRecord<T> & ForeignKeyMap<T>;
|
@ -14,6 +14,7 @@ import { WorkspaceDynamicRelation } from 'src/engine/twenty-orm/decorators/works
|
||||
import { RelationMetadataType } from 'src/engine/metadata-modules/relation-metadata/relation-metadata.entity';
|
||||
import { WorkspaceRelation } from 'src/engine/twenty-orm/decorators/workspace-relation.decorator';
|
||||
import { BaseWorkspaceEntity } from 'src/engine/twenty-orm/base.workspace-entity';
|
||||
import { WorkspaceJoinColumn } from 'src/engine/twenty-orm/decorators/workspace-join-column.decorator';
|
||||
|
||||
@WorkspaceEntity({
|
||||
standardId: STANDARD_OBJECT_IDS.activityTarget,
|
||||
@ -31,52 +32,60 @@ export class ActivityTargetWorkspaceEntity extends BaseWorkspaceEntity {
|
||||
label: 'Activity',
|
||||
description: 'ActivityTarget activity',
|
||||
icon: 'IconNotes',
|
||||
joinColumn: 'activityId',
|
||||
inverseSideTarget: () => ActivityWorkspaceEntity,
|
||||
inverseSideFieldKey: 'activityTargets',
|
||||
})
|
||||
@WorkspaceIsNullable()
|
||||
activity: Relation<ActivityWorkspaceEntity> | null;
|
||||
|
||||
@WorkspaceJoinColumn('activity')
|
||||
activityId: string | null;
|
||||
|
||||
@WorkspaceRelation({
|
||||
standardId: ACTIVITY_TARGET_STANDARD_FIELD_IDS.person,
|
||||
type: RelationMetadataType.MANY_TO_ONE,
|
||||
label: 'Person',
|
||||
description: 'ActivityTarget person',
|
||||
icon: 'IconUser',
|
||||
joinColumn: 'personId',
|
||||
inverseSideTarget: () => PersonWorkspaceEntity,
|
||||
inverseSideFieldKey: 'activityTargets',
|
||||
})
|
||||
@WorkspaceIsNullable()
|
||||
person: Relation<PersonWorkspaceEntity> | null;
|
||||
|
||||
@WorkspaceJoinColumn('person')
|
||||
personId: string | null;
|
||||
|
||||
@WorkspaceRelation({
|
||||
standardId: ACTIVITY_TARGET_STANDARD_FIELD_IDS.company,
|
||||
type: RelationMetadataType.MANY_TO_ONE,
|
||||
label: 'Company',
|
||||
description: 'ActivityTarget company',
|
||||
icon: 'IconBuildingSkyscraper',
|
||||
joinColumn: 'companyId',
|
||||
inverseSideTarget: () => CompanyWorkspaceEntity,
|
||||
inverseSideFieldKey: 'activityTargets',
|
||||
})
|
||||
@WorkspaceIsNullable()
|
||||
company: Relation<CompanyWorkspaceEntity> | null;
|
||||
|
||||
@WorkspaceJoinColumn('company')
|
||||
companyId: string | null;
|
||||
|
||||
@WorkspaceRelation({
|
||||
standardId: ACTIVITY_TARGET_STANDARD_FIELD_IDS.opportunity,
|
||||
type: RelationMetadataType.MANY_TO_ONE,
|
||||
label: 'Opportunity',
|
||||
description: 'ActivityTarget opportunity',
|
||||
icon: 'IconTargetArrow',
|
||||
joinColumn: 'opportunityId',
|
||||
inverseSideTarget: () => OpportunityWorkspaceEntity,
|
||||
inverseSideFieldKey: 'activityTargets',
|
||||
})
|
||||
@WorkspaceIsNullable()
|
||||
opportunity: Relation<OpportunityWorkspaceEntity> | null;
|
||||
|
||||
@WorkspaceJoinColumn('opportunity')
|
||||
opportunityId: string | null;
|
||||
|
||||
@WorkspaceDynamicRelation({
|
||||
type: RelationMetadataType.MANY_TO_ONE,
|
||||
argsFactory: (oppositeObjectMetadata) => ({
|
||||
|
@ -17,6 +17,7 @@ import { WorkspaceField } from 'src/engine/twenty-orm/decorators/workspace-field
|
||||
import { WorkspaceRelation } from 'src/engine/twenty-orm/decorators/workspace-relation.decorator';
|
||||
import { WorkspaceIsNullable } from 'src/engine/twenty-orm/decorators/workspace-is-nullable.decorator';
|
||||
import { BaseWorkspaceEntity } from 'src/engine/twenty-orm/base.workspace-entity';
|
||||
import { WorkspaceJoinColumn } from 'src/engine/twenty-orm/decorators/workspace-join-column.decorator';
|
||||
|
||||
@WorkspaceEntity({
|
||||
standardId: STANDARD_OBJECT_IDS.activity,
|
||||
@ -131,11 +132,13 @@ export class ActivityWorkspaceEntity extends BaseWorkspaceEntity {
|
||||
inverseSideTarget: () => WorkspaceMemberWorkspaceEntity,
|
||||
inverseSideFieldKey: 'authoredActivities',
|
||||
onDelete: RelationOnDeleteAction.SET_NULL,
|
||||
joinColumn: 'authorId',
|
||||
})
|
||||
@WorkspaceIsNullable()
|
||||
author: Relation<WorkspaceMemberWorkspaceEntity> | null;
|
||||
|
||||
@WorkspaceJoinColumn('author')
|
||||
authorId: string | null;
|
||||
|
||||
@WorkspaceRelation({
|
||||
standardId: ACTIVITY_STANDARD_FIELD_IDS.assignee,
|
||||
label: 'Assignee',
|
||||
@ -145,8 +148,10 @@ export class ActivityWorkspaceEntity extends BaseWorkspaceEntity {
|
||||
inverseSideTarget: () => WorkspaceMemberWorkspaceEntity,
|
||||
inverseSideFieldKey: 'assignedActivities',
|
||||
onDelete: RelationOnDeleteAction.SET_NULL,
|
||||
joinColumn: 'assigneeId',
|
||||
})
|
||||
@WorkspaceIsNullable()
|
||||
assignee: Relation<WorkspaceMemberWorkspaceEntity> | null;
|
||||
|
||||
@WorkspaceJoinColumn('assignee')
|
||||
assigneeId: string | null;
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import { WorkspaceField } from 'src/engine/twenty-orm/decorators/workspace-field
|
||||
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';
|
||||
import { WorkspaceJoinColumn } from 'src/engine/twenty-orm/decorators/workspace-join-column.decorator';
|
||||
|
||||
@WorkspaceEntity({
|
||||
standardId: STANDARD_OBJECT_IDS.comment,
|
||||
@ -37,21 +38,25 @@ export class CommentWorkspaceEntity extends BaseWorkspaceEntity {
|
||||
label: 'Author',
|
||||
description: 'Comment author',
|
||||
icon: 'IconCircleUser',
|
||||
joinColumn: 'authorId',
|
||||
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',
|
||||
joinColumn: 'activityId',
|
||||
inverseSideTarget: () => ActivityWorkspaceEntity,
|
||||
inverseSideFieldKey: 'comments',
|
||||
})
|
||||
activity: Relation<ActivityWorkspaceEntity>;
|
||||
|
||||
@WorkspaceJoinColumn('activity')
|
||||
activityId: string;
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ import { RelationMetadataType } from 'src/engine/metadata-modules/relation-metad
|
||||
import { WorkspaceIsNullable } from 'src/engine/twenty-orm/decorators/workspace-is-nullable.decorator';
|
||||
import { WorkspaceDynamicRelation } from 'src/engine/twenty-orm/decorators/workspace-dynamic-relation.decorator';
|
||||
import { BaseWorkspaceEntity } from 'src/engine/twenty-orm/base.workspace-entity';
|
||||
import { WorkspaceJoinColumn } from 'src/engine/twenty-orm/decorators/workspace-join-column.decorator';
|
||||
|
||||
@WorkspaceEntity({
|
||||
standardId: STANDARD_OBJECT_IDS.attachment,
|
||||
@ -63,64 +64,74 @@ export class AttachmentWorkspaceEntity extends BaseWorkspaceEntity {
|
||||
label: 'Author',
|
||||
description: 'Attachment author',
|
||||
icon: 'IconCircleUser',
|
||||
joinColumn: 'authorId',
|
||||
inverseSideTarget: () => WorkspaceMemberWorkspaceEntity,
|
||||
inverseSideFieldKey: 'authoredAttachments',
|
||||
})
|
||||
author: Relation<WorkspaceMemberWorkspaceEntity>;
|
||||
|
||||
@WorkspaceJoinColumn('author')
|
||||
authorId: string;
|
||||
|
||||
@WorkspaceRelation({
|
||||
standardId: ATTACHMENT_STANDARD_FIELD_IDS.activity,
|
||||
type: RelationMetadataType.MANY_TO_ONE,
|
||||
label: 'Activity',
|
||||
description: 'Attachment activity',
|
||||
icon: 'IconNotes',
|
||||
joinColumn: 'activityId',
|
||||
inverseSideTarget: () => ActivityWorkspaceEntity,
|
||||
inverseSideFieldKey: 'attachments',
|
||||
})
|
||||
@WorkspaceIsNullable()
|
||||
activity: Relation<ActivityWorkspaceEntity> | null;
|
||||
|
||||
@WorkspaceJoinColumn('activity')
|
||||
activityId: string | null;
|
||||
|
||||
@WorkspaceRelation({
|
||||
standardId: ATTACHMENT_STANDARD_FIELD_IDS.person,
|
||||
type: RelationMetadataType.MANY_TO_ONE,
|
||||
label: 'Person',
|
||||
description: 'Attachment person',
|
||||
icon: 'IconUser',
|
||||
joinColumn: 'personId',
|
||||
inverseSideTarget: () => PersonWorkspaceEntity,
|
||||
inverseSideFieldKey: 'attachments',
|
||||
})
|
||||
@WorkspaceIsNullable()
|
||||
person: Relation<PersonWorkspaceEntity> | null;
|
||||
|
||||
@WorkspaceJoinColumn('person')
|
||||
personId: string | null;
|
||||
|
||||
@WorkspaceRelation({
|
||||
standardId: ATTACHMENT_STANDARD_FIELD_IDS.company,
|
||||
type: RelationMetadataType.MANY_TO_ONE,
|
||||
label: 'Company',
|
||||
description: 'Attachment company',
|
||||
icon: 'IconBuildingSkyscraper',
|
||||
joinColumn: 'companyId',
|
||||
inverseSideTarget: () => CompanyWorkspaceEntity,
|
||||
inverseSideFieldKey: 'attachments',
|
||||
})
|
||||
@WorkspaceIsNullable()
|
||||
company: Relation<CompanyWorkspaceEntity> | null;
|
||||
|
||||
@WorkspaceJoinColumn('company')
|
||||
companyId: string | null;
|
||||
|
||||
@WorkspaceRelation({
|
||||
standardId: ATTACHMENT_STANDARD_FIELD_IDS.opportunity,
|
||||
type: RelationMetadataType.MANY_TO_ONE,
|
||||
label: 'Opportunity',
|
||||
description: 'Attachment opportunity',
|
||||
icon: 'IconBuildingSkyscraper',
|
||||
joinColumn: 'opportunityId',
|
||||
inverseSideTarget: () => OpportunityWorkspaceEntity,
|
||||
inverseSideFieldKey: 'attachments',
|
||||
})
|
||||
@WorkspaceIsNullable()
|
||||
opportunity: Relation<OpportunityWorkspaceEntity> | null;
|
||||
|
||||
@WorkspaceJoinColumn('opportunity')
|
||||
opportunityId: string | null;
|
||||
|
||||
@WorkspaceDynamicRelation({
|
||||
type: RelationMetadataType.MANY_TO_ONE,
|
||||
argsFactory: (oppositeObjectMetadata) => ({
|
||||
|
@ -70,12 +70,9 @@ export class BlocklistItemDeleteCalendarEventsJob {
|
||||
const calendarChannels = await this.calendarChannelRepository.find({
|
||||
where: {
|
||||
connectedAccount: {
|
||||
accountOwner: {
|
||||
id: workspaceMemberId,
|
||||
},
|
||||
accountOwnerId: workspaceMemberId,
|
||||
},
|
||||
},
|
||||
relations: ['connectedAccount.accountOwner'],
|
||||
});
|
||||
|
||||
const calendarChannelIds = calendarChannels.map(({ id }) => id);
|
||||
@ -88,9 +85,7 @@ export class BlocklistItemDeleteCalendarEventsJob {
|
||||
handle: isHandleDomain ? ILike(`%${handle}`) : handle,
|
||||
},
|
||||
calendarChannelEventAssociations: {
|
||||
calendarChannel: {
|
||||
id: Any(calendarChannelIds),
|
||||
},
|
||||
calendarChannelId: Any(calendarChannelIds),
|
||||
},
|
||||
},
|
||||
});
|
||||
|
@ -72,9 +72,7 @@ export class CalendarCreateCompanyAndContactAfterSyncJob {
|
||||
where: {
|
||||
calendarEvent: {
|
||||
calendarChannelEventAssociations: {
|
||||
calendarChannel: {
|
||||
id: calendarChannelId,
|
||||
},
|
||||
calendarChannelId,
|
||||
},
|
||||
calendarEventParticipants: {
|
||||
person: IsNull(),
|
||||
|
@ -10,7 +10,6 @@ import { WorkspaceDataSourceService } from 'src/engine/workspace-datasource/work
|
||||
import { CalendarEventParticipantWorkspaceEntity } from 'src/modules/calendar/standard-objects/calendar-event-participant.workspace-entity';
|
||||
import { TimelineActivityRepository } from 'src/modules/timeline/repositiories/timeline-activity.repository';
|
||||
import { TimelineActivityWorkspaceEntity } from 'src/modules/timeline/standard-objects/timeline-activity.workspace-entity';
|
||||
import { ObjectRecord } from 'src/engine/workspace-manager/workspace-sync-metadata/types/object-record';
|
||||
|
||||
@Injectable()
|
||||
export class CalendarEventParticipantListener {
|
||||
@ -26,7 +25,7 @@ export class CalendarEventParticipantListener {
|
||||
public async handleCalendarEventParticipantMatchedEvent(payload: {
|
||||
workspaceId: string;
|
||||
workspaceMemberId: string;
|
||||
calendarEventParticipants: ObjectRecord<CalendarEventParticipantWorkspaceEntity>[];
|
||||
calendarEventParticipants: CalendarEventParticipantWorkspaceEntity[];
|
||||
}): Promise<void> {
|
||||
const calendarEventParticipants = payload.calendarEventParticipants ?? [];
|
||||
|
||||
|
@ -34,9 +34,7 @@ export class CalendarEventFindManyPreQueryHook
|
||||
const calendarChannelCalendarEventAssociations =
|
||||
await this.calendarChannelEventAssociationRepository.find({
|
||||
where: {
|
||||
calendarEvent: {
|
||||
id: payload?.filter?.id?.eq,
|
||||
},
|
||||
calendarEventId: payload?.filter?.id?.eq,
|
||||
},
|
||||
relations: ['calendarChannel.connectedAccount'],
|
||||
});
|
||||
|
@ -35,9 +35,7 @@ export class CalendarEventFindOnePreQueryHook
|
||||
const calendarChannelCalendarEventAssociations =
|
||||
await this.calendarChannelEventAssociationRepository.find({
|
||||
where: {
|
||||
calendarEvent: {
|
||||
id: payload?.filter?.id?.eq,
|
||||
},
|
||||
calendarEventId: payload?.filter?.id?.eq,
|
||||
},
|
||||
relations: ['calendarChannel.connectedAccount'],
|
||||
});
|
||||
|
@ -11,7 +11,6 @@ import { getFlattenedValuesAndValuesStringForBatchRawQuery } from 'src/modules/c
|
||||
import { CalendarEventParticipant } from 'src/modules/calendar/types/calendar-event';
|
||||
import { CalendarEventParticipantWorkspaceEntity } from 'src/modules/calendar/standard-objects/calendar-event-participant.workspace-entity';
|
||||
import { AddPersonIdAndWorkspaceMemberIdService } from 'src/modules/calendar-messaging-participant/services/add-person-id-and-workspace-member-id/add-person-id-and-workspace-member-id.service';
|
||||
import { ObjectRecord } from 'src/engine/workspace-manager/workspace-sync-metadata/types/object-record';
|
||||
import { InjectWorkspaceRepository } from 'src/engine/twenty-orm/decorators/inject-workspace-repository.decorator';
|
||||
import { WorkspaceRepository } from 'src/engine/twenty-orm/repository/workspace.repository';
|
||||
|
||||
@ -28,10 +27,10 @@ export class CalendarEventParticipantService {
|
||||
) {}
|
||||
|
||||
public async updateCalendarEventParticipantsAfterPeopleCreation(
|
||||
createdPeople: ObjectRecord<PersonWorkspaceEntity>[],
|
||||
createdPeople: PersonWorkspaceEntity[],
|
||||
workspaceId: string,
|
||||
transactionManager?: EntityManager,
|
||||
): Promise<ObjectRecord<CalendarEventParticipantWorkspaceEntity>[]> {
|
||||
): Promise<CalendarEventParticipantWorkspaceEntity[]> {
|
||||
const participants = await this.calendarEventParticipantRepository.find({
|
||||
where: {
|
||||
handle: Any(createdPeople.map((person) => person.email)),
|
||||
@ -88,7 +87,7 @@ export class CalendarEventParticipantService {
|
||||
calendarEventParticipants: CalendarEventParticipant[],
|
||||
workspaceId: string,
|
||||
transactionManager?: EntityManager,
|
||||
): Promise<ObjectRecord<CalendarEventParticipantWorkspaceEntity>[]> {
|
||||
): Promise<CalendarEventParticipantWorkspaceEntity[]> {
|
||||
if (calendarEventParticipants.length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
@ -37,7 +37,6 @@ import {
|
||||
} from 'src/modules/connected-account/auto-companies-and-contacts-creation/jobs/create-company-and-contact.job';
|
||||
import { InjectWorkspaceRepository } from 'src/engine/twenty-orm/decorators/inject-workspace-repository.decorator';
|
||||
import { WorkspaceRepository } from 'src/engine/twenty-orm/repository/workspace.repository';
|
||||
import { ObjectRecord } from 'src/engine/workspace-manager/workspace-sync-metadata/types/object-record';
|
||||
import { isDefined } from 'src/utils/is-defined';
|
||||
import { WorkspaceDataSource } from 'src/engine/twenty-orm/datasource/workspace.datasource';
|
||||
import { InjectWorkspaceDatasource } from 'src/engine/twenty-orm/decorators/inject-workspace-datasource.decorator';
|
||||
@ -416,7 +415,7 @@ export class GoogleCalendarSyncService {
|
||||
eventExternalId: string;
|
||||
calendarChannelId: string;
|
||||
}[],
|
||||
connectedAccount: ObjectRecord<ConnectedAccountWorkspaceEntity>,
|
||||
connectedAccount: ConnectedAccountWorkspaceEntity,
|
||||
calendarChannel: CalendarChannelWorkspaceEntity,
|
||||
workspaceId: string,
|
||||
): Promise<void> {
|
||||
@ -431,7 +430,7 @@ export class GoogleCalendarSyncService {
|
||||
let startTime: number;
|
||||
let endTime: number;
|
||||
|
||||
const savedCalendarEventParticipantsToEmit: ObjectRecord<CalendarEventParticipantWorkspaceEntity>[] =
|
||||
const savedCalendarEventParticipantsToEmit: CalendarEventParticipantWorkspaceEntity[] =
|
||||
[];
|
||||
|
||||
try {
|
||||
@ -496,13 +495,11 @@ export class GoogleCalendarSyncService {
|
||||
const existingCalendarEventParticipants =
|
||||
await this.calendarEventParticipantsRepository.find({
|
||||
where: {
|
||||
calendarEvent: {
|
||||
id: Any(
|
||||
participantsToUpdate
|
||||
.map((participant) => participant.calendarEventId)
|
||||
.filter(isDefined),
|
||||
),
|
||||
},
|
||||
calendarEventId: Any(
|
||||
participantsToUpdate
|
||||
.map((participant) => participant.calendarEventId)
|
||||
.filter(isDefined),
|
||||
),
|
||||
},
|
||||
});
|
||||
|
||||
|
@ -12,6 +12,7 @@ import { RelationMetadataType } from 'src/engine/metadata-modules/relation-metad
|
||||
import { WorkspaceField } from 'src/engine/twenty-orm/decorators/workspace-field.decorator';
|
||||
import { BaseWorkspaceEntity } from 'src/engine/twenty-orm/base.workspace-entity';
|
||||
import { CalendarChannelWorkspaceEntity } from 'src/modules/calendar/standard-objects/calendar-channel.workspace-entity';
|
||||
import { WorkspaceJoinColumn } from 'src/engine/twenty-orm/decorators/workspace-join-column.decorator';
|
||||
|
||||
@WorkspaceEntity({
|
||||
standardId: STANDARD_OBJECT_IDS.calendarChannelEventAssociation,
|
||||
@ -41,12 +42,14 @@ export class CalendarChannelEventAssociationWorkspaceEntity extends BaseWorkspac
|
||||
label: 'Channel ID',
|
||||
description: 'Channel ID',
|
||||
icon: 'IconCalendar',
|
||||
joinColumn: 'calendarChannelId',
|
||||
inverseSideTarget: () => CalendarChannelWorkspaceEntity,
|
||||
inverseSideFieldKey: 'calendarChannelEventAssociations',
|
||||
})
|
||||
calendarChannel: Relation<CalendarChannelWorkspaceEntity>;
|
||||
|
||||
@WorkspaceJoinColumn('calendarChannel')
|
||||
calendarChannelId: string;
|
||||
|
||||
@WorkspaceRelation({
|
||||
standardId:
|
||||
CALENDAR_CHANNEL_EVENT_ASSOCIATION_STANDARD_FIELD_IDS.calendarEvent,
|
||||
@ -54,9 +57,11 @@ export class CalendarChannelEventAssociationWorkspaceEntity extends BaseWorkspac
|
||||
label: 'Event ID',
|
||||
description: 'Event ID',
|
||||
icon: 'IconCalendar',
|
||||
joinColumn: 'calendarEventId',
|
||||
inverseSideTarget: () => CalendarEventWorkspaceEntity,
|
||||
inverseSideFieldKey: 'calendarChannelEventAssociations',
|
||||
})
|
||||
calendarEvent: Relation<CalendarEventWorkspaceEntity>;
|
||||
|
||||
@WorkspaceJoinColumn('calendarEvent')
|
||||
calendarEventId: string;
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ import { WorkspaceIsNotAuditLogged } from 'src/engine/twenty-orm/decorators/work
|
||||
import { WorkspaceField } from 'src/engine/twenty-orm/decorators/workspace-field.decorator';
|
||||
import { WorkspaceRelation } from 'src/engine/twenty-orm/decorators/workspace-relation.decorator';
|
||||
import { WorkspaceIsNullable } from 'src/engine/twenty-orm/decorators/workspace-is-nullable.decorator';
|
||||
import { WorkspaceJoinColumn } from 'src/engine/twenty-orm/decorators/workspace-join-column.decorator';
|
||||
|
||||
export enum CalendarChannelVisibility {
|
||||
METADATA = 'METADATA',
|
||||
@ -231,12 +232,12 @@ export class CalendarChannelWorkspaceEntity extends BaseWorkspaceEntity {
|
||||
label: 'Connected Account',
|
||||
description: 'Connected Account',
|
||||
icon: 'IconUserCircle',
|
||||
joinColumn: 'connectedAccountId',
|
||||
inverseSideTarget: () => ConnectedAccountWorkspaceEntity,
|
||||
inverseSideFieldKey: 'calendarChannels',
|
||||
})
|
||||
connectedAccount: Relation<ConnectedAccountWorkspaceEntity>;
|
||||
|
||||
@WorkspaceJoinColumn('connectedAccount')
|
||||
connectedAccountId: string;
|
||||
|
||||
@WorkspaceRelation({
|
||||
|
@ -14,6 +14,7 @@ import { WorkspaceField } from 'src/engine/twenty-orm/decorators/workspace-field
|
||||
import { WorkspaceRelation } from 'src/engine/twenty-orm/decorators/workspace-relation.decorator';
|
||||
import { RelationMetadataType } from 'src/engine/metadata-modules/relation-metadata/relation-metadata.entity';
|
||||
import { WorkspaceIsNullable } from 'src/engine/twenty-orm/decorators/workspace-is-nullable.decorator';
|
||||
import { WorkspaceJoinColumn } from 'src/engine/twenty-orm/decorators/workspace-join-column.decorator';
|
||||
|
||||
export enum CalendarEventParticipantResponseStatus {
|
||||
NEEDS_ACTION = 'NEEDS_ACTION',
|
||||
@ -103,35 +104,41 @@ export class CalendarEventParticipantWorkspaceEntity extends BaseWorkspaceEntity
|
||||
label: 'Event ID',
|
||||
description: 'Event ID',
|
||||
icon: 'IconCalendar',
|
||||
joinColumn: 'calendarEventId',
|
||||
inverseSideTarget: () => CalendarEventWorkspaceEntity,
|
||||
inverseSideFieldKey: 'calendarEventParticipants',
|
||||
})
|
||||
calendarEvent: Relation<CalendarEventWorkspaceEntity>;
|
||||
|
||||
@WorkspaceJoinColumn('calendarEvent')
|
||||
calendarEventId: string;
|
||||
|
||||
@WorkspaceRelation({
|
||||
standardId: CALENDAR_EVENT_PARTICIPANT_STANDARD_FIELD_IDS.person,
|
||||
type: RelationMetadataType.MANY_TO_ONE,
|
||||
label: 'Person',
|
||||
description: 'Person',
|
||||
icon: 'IconUser',
|
||||
joinColumn: 'personId',
|
||||
inverseSideTarget: () => PersonWorkspaceEntity,
|
||||
inverseSideFieldKey: 'calendarEventParticipants',
|
||||
})
|
||||
@WorkspaceIsNullable()
|
||||
person: Relation<PersonWorkspaceEntity> | null;
|
||||
|
||||
@WorkspaceJoinColumn('person')
|
||||
personId: string | null;
|
||||
|
||||
@WorkspaceRelation({
|
||||
standardId: CALENDAR_EVENT_PARTICIPANT_STANDARD_FIELD_IDS.workspaceMember,
|
||||
type: RelationMetadataType.MANY_TO_ONE,
|
||||
label: 'Workspace Member',
|
||||
description: 'Workspace Member',
|
||||
icon: 'IconUser',
|
||||
joinColumn: 'workspaceMemberId',
|
||||
inverseSideTarget: () => WorkspaceMemberWorkspaceEntity,
|
||||
inverseSideFieldKey: 'calendarEventParticipants',
|
||||
})
|
||||
@WorkspaceIsNullable()
|
||||
workspaceMember: Relation<WorkspaceMemberWorkspaceEntity> | null;
|
||||
|
||||
@WorkspaceJoinColumn('workspaceMember')
|
||||
workspaceMemberId: string | null;
|
||||
}
|
||||
|
@ -1,9 +1,8 @@
|
||||
import { CalendarEventParticipantWorkspaceEntity } from 'src/modules/calendar/standard-objects/calendar-event-participant.workspace-entity';
|
||||
import { CalendarEventWorkspaceEntity } from 'src/modules/calendar/standard-objects/calendar-event.workspace-entity';
|
||||
import { ObjectRecord } from 'src/engine/workspace-manager/workspace-sync-metadata/types/object-record';
|
||||
|
||||
export type CalendarEvent = Omit<
|
||||
ObjectRecord<CalendarEventWorkspaceEntity>,
|
||||
CalendarEventWorkspaceEntity,
|
||||
| 'createdAt'
|
||||
| 'updatedAt'
|
||||
| 'calendarChannelEventAssociations'
|
||||
@ -15,7 +14,7 @@ export type CalendarEvent = Omit<
|
||||
};
|
||||
|
||||
export type CalendarEventParticipant = Omit<
|
||||
ObjectRecord<CalendarEventParticipantWorkspaceEntity>,
|
||||
CalendarEventParticipantWorkspaceEntity,
|
||||
| 'id'
|
||||
| 'createdAt'
|
||||
| 'updatedAt'
|
||||
|
@ -22,6 +22,7 @@ import { WorkspaceField } from 'src/engine/twenty-orm/decorators/workspace-field
|
||||
import { WorkspaceIsNullable } from 'src/engine/twenty-orm/decorators/workspace-is-nullable.decorator';
|
||||
import { WorkspaceIsSystem } from 'src/engine/twenty-orm/decorators/workspace-is-system.decorator';
|
||||
import { WorkspaceRelation } from 'src/engine/twenty-orm/decorators/workspace-relation.decorator';
|
||||
import { WorkspaceJoinColumn } from 'src/engine/twenty-orm/decorators/workspace-join-column.decorator';
|
||||
|
||||
@WorkspaceEntity({
|
||||
standardId: STANDARD_OBJECT_IDS.company,
|
||||
@ -143,7 +144,6 @@ export class CompanyWorkspaceEntity extends BaseWorkspaceEntity {
|
||||
description:
|
||||
'Your team member responsible for managing the company account',
|
||||
icon: 'IconUserCircle',
|
||||
joinColumn: 'accountOwnerId',
|
||||
inverseSideTarget: () => WorkspaceMemberWorkspaceEntity,
|
||||
inverseSideFieldKey: 'accountOwnerForCompanies',
|
||||
onDelete: RelationOnDeleteAction.SET_NULL,
|
||||
@ -151,6 +151,9 @@ export class CompanyWorkspaceEntity extends BaseWorkspaceEntity {
|
||||
@WorkspaceIsNullable()
|
||||
accountOwner: Relation<WorkspaceMemberWorkspaceEntity> | null;
|
||||
|
||||
@WorkspaceJoinColumn('accountOwner')
|
||||
accountOwnerId: string | null;
|
||||
|
||||
@WorkspaceRelation({
|
||||
standardId: COMPANY_STANDARD_FIELD_IDS.activityTargets,
|
||||
type: RelationMetadataType.ONE_TO_MANY,
|
||||
|
@ -7,7 +7,6 @@ import { PersonRepository } from 'src/modules/person/repositories/person.reposit
|
||||
import { getFirstNameAndLastNameFromHandleAndDisplayName } from 'src/modules/calendar-messaging-participant/utils/get-first-name-and-last-name-from-handle-and-display-name.util';
|
||||
import { InjectObjectMetadataRepository } from 'src/engine/object-metadata-repository/object-metadata-repository.decorator';
|
||||
import { PersonWorkspaceEntity } from 'src/modules/person/standard-objects/person.workspace-entity';
|
||||
import { ObjectRecord } from 'src/engine/workspace-manager/workspace-sync-metadata/types/object-record';
|
||||
|
||||
type ContactToCreate = {
|
||||
handle: string;
|
||||
@ -55,7 +54,7 @@ export class CreateContactService {
|
||||
contactsToCreate: ContactToCreate[],
|
||||
workspaceId: string,
|
||||
transactionManager?: EntityManager,
|
||||
): Promise<ObjectRecord<PersonWorkspaceEntity>[]> {
|
||||
): Promise<PersonWorkspaceEntity[]> {
|
||||
if (contactsToCreate.length === 0) return [];
|
||||
|
||||
const formattedContacts = this.formatContacts(contactsToCreate);
|
||||
|
@ -17,7 +17,6 @@ import { getUniqueContactsAndHandles } from 'src/modules/connected-account/auto-
|
||||
import { Contacts } from 'src/modules/connected-account/auto-companies-and-contacts-creation/types/contact.type';
|
||||
import { CalendarEventParticipantService } from 'src/modules/calendar/services/calendar-event-participant/calendar-event-participant.service';
|
||||
import { filterOutContactsFromCompanyOrWorkspace } from 'src/modules/connected-account/auto-companies-and-contacts-creation/utils/filter-out-contacts-from-company-or-workspace.util';
|
||||
import { ObjectRecord } from 'src/engine/workspace-manager/workspace-sync-metadata/types/object-record';
|
||||
import { MessagingMessageParticipantService } from 'src/modules/messaging/common/services/messaging-message-participant.service';
|
||||
import { MessageParticipantWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-participant.workspace-entity';
|
||||
import { CalendarEventParticipantWorkspaceEntity } from 'src/modules/calendar/standard-objects/calendar-event-participant.workspace-entity';
|
||||
@ -46,7 +45,7 @@ export class CreateCompanyAndContactService {
|
||||
contactsToCreate: Contacts,
|
||||
workspaceId: string,
|
||||
transactionManager?: EntityManager,
|
||||
): Promise<ObjectRecord<PersonWorkspaceEntity>[]> {
|
||||
): Promise<PersonWorkspaceEntity[]> {
|
||||
if (!contactsToCreate || contactsToCreate.length === 0) {
|
||||
return [];
|
||||
}
|
||||
@ -136,9 +135,8 @@ export class CreateCompanyAndContactService {
|
||||
contactsToCreate: Contacts,
|
||||
workspaceId: string,
|
||||
) {
|
||||
let updatedMessageParticipants: ObjectRecord<MessageParticipantWorkspaceEntity>[] =
|
||||
[];
|
||||
let updatedCalendarEventParticipants: ObjectRecord<CalendarEventParticipantWorkspaceEntity>[] =
|
||||
let updatedMessageParticipants: MessageParticipantWorkspaceEntity[] = [];
|
||||
let updatedCalendarEventParticipants: CalendarEventParticipantWorkspaceEntity[] =
|
||||
[];
|
||||
|
||||
await this.workspaceDataSource?.transaction(
|
||||
|
@ -1,12 +1,11 @@
|
||||
import { getDomainNameFromHandle } from 'src/modules/calendar-messaging-participant/utils/get-domain-name-from-handle.util';
|
||||
import { WorkspaceMemberWorkspaceEntity } from 'src/modules/workspace-member/standard-objects/workspace-member.workspace-entity';
|
||||
import { ObjectRecord } from 'src/engine/workspace-manager/workspace-sync-metadata/types/object-record';
|
||||
import { Contacts } from 'src/modules/connected-account/auto-companies-and-contacts-creation/types/contact.type';
|
||||
|
||||
export function filterOutContactsFromCompanyOrWorkspace(
|
||||
contacts: Contacts,
|
||||
selfHandle: string,
|
||||
workspaceMembers: ObjectRecord<WorkspaceMemberWorkspaceEntity>[],
|
||||
workspaceMembers: WorkspaceMemberWorkspaceEntity[],
|
||||
): Contacts {
|
||||
const selfDomainName = getDomainNameFromHandle(selfHandle);
|
||||
|
||||
|
@ -3,7 +3,6 @@ import { Injectable } from '@nestjs/common';
|
||||
import { EntityManager } from 'typeorm';
|
||||
|
||||
import { WorkspaceDataSourceService } from 'src/engine/workspace-datasource/workspace-datasource.service';
|
||||
import { ObjectRecord } from 'src/engine/workspace-manager/workspace-sync-metadata/types/object-record';
|
||||
import { BlocklistWorkspaceEntity } from 'src/modules/connected-account/standard-objects/blocklist.workspace-entity';
|
||||
|
||||
@Injectable()
|
||||
@ -16,7 +15,7 @@ export class BlocklistRepository {
|
||||
id: string,
|
||||
workspaceId: string,
|
||||
transactionManager?: EntityManager,
|
||||
): Promise<ObjectRecord<BlocklistWorkspaceEntity> | null> {
|
||||
): Promise<BlocklistWorkspaceEntity | null> {
|
||||
const dataSourceSchema =
|
||||
this.workspaceDataSourceService.getSchemaName(workspaceId);
|
||||
|
||||
@ -39,7 +38,7 @@ export class BlocklistRepository {
|
||||
workspaceMemberId: string,
|
||||
workspaceId: string,
|
||||
transactionManager?: EntityManager,
|
||||
): Promise<ObjectRecord<BlocklistWorkspaceEntity>[]> {
|
||||
): Promise<BlocklistWorkspaceEntity[]> {
|
||||
const dataSourceSchema =
|
||||
this.workspaceDataSourceService.getSchemaName(workspaceId);
|
||||
|
||||
@ -56,7 +55,7 @@ export class BlocklistRepository {
|
||||
handle: string,
|
||||
workspaceId: string,
|
||||
transactionManager?: EntityManager,
|
||||
): Promise<ObjectRecord<BlocklistWorkspaceEntity>[]> {
|
||||
): Promise<BlocklistWorkspaceEntity[]> {
|
||||
const dataSourceSchema =
|
||||
this.workspaceDataSourceService.getSchemaName(workspaceId);
|
||||
|
||||
|
@ -4,7 +4,6 @@ import { EntityManager } from 'typeorm';
|
||||
|
||||
import { WorkspaceDataSourceService } from 'src/engine/workspace-datasource/workspace-datasource.service';
|
||||
import { ConnectedAccountWorkspaceEntity } from 'src/modules/connected-account/standard-objects/connected-account.workspace-entity';
|
||||
import { ObjectRecord } from 'src/engine/workspace-manager/workspace-sync-metadata/types/object-record';
|
||||
|
||||
@Injectable()
|
||||
export class ConnectedAccountRepository {
|
||||
@ -15,7 +14,7 @@ export class ConnectedAccountRepository {
|
||||
public async getAll(
|
||||
workspaceId: string,
|
||||
transactionManager?: EntityManager,
|
||||
): Promise<ObjectRecord<ConnectedAccountWorkspaceEntity>[]> {
|
||||
): Promise<ConnectedAccountWorkspaceEntity[]> {
|
||||
const dataSourceSchema =
|
||||
this.workspaceDataSourceService.getSchemaName(workspaceId);
|
||||
|
||||
@ -31,7 +30,7 @@ export class ConnectedAccountRepository {
|
||||
connectedAccountIds: string[],
|
||||
workspaceId: string,
|
||||
transactionManager?: EntityManager,
|
||||
): Promise<ObjectRecord<ConnectedAccountWorkspaceEntity>[]> {
|
||||
): Promise<ConnectedAccountWorkspaceEntity[]> {
|
||||
const dataSourceSchema =
|
||||
this.workspaceDataSourceService.getSchemaName(workspaceId);
|
||||
|
||||
@ -47,7 +46,7 @@ export class ConnectedAccountRepository {
|
||||
workspaceMemberId: string,
|
||||
workspaceId: string,
|
||||
transactionManager?: EntityManager,
|
||||
): Promise<ObjectRecord<ConnectedAccountWorkspaceEntity>[] | undefined> {
|
||||
): Promise<ConnectedAccountWorkspaceEntity[] | undefined> {
|
||||
const dataSourceSchema =
|
||||
this.workspaceDataSourceService.getSchemaName(workspaceId);
|
||||
|
||||
@ -66,7 +65,7 @@ export class ConnectedAccountRepository {
|
||||
userId: string,
|
||||
workspaceId: string,
|
||||
transactionManager?: EntityManager,
|
||||
): Promise<ObjectRecord<ConnectedAccountWorkspaceEntity>[] | undefined> {
|
||||
): Promise<ConnectedAccountWorkspaceEntity[] | undefined> {
|
||||
const schemaExists =
|
||||
await this.workspaceDataSourceService.checkSchemaExists(workspaceId);
|
||||
|
||||
@ -102,7 +101,7 @@ export class ConnectedAccountRepository {
|
||||
workspaceMemberId: string,
|
||||
workspaceId: string,
|
||||
transactionManager?: EntityManager,
|
||||
): Promise<ObjectRecord<ConnectedAccountWorkspaceEntity>[] | undefined> {
|
||||
): Promise<ConnectedAccountWorkspaceEntity[] | undefined> {
|
||||
const dataSourceSchema =
|
||||
this.workspaceDataSourceService.getSchemaName(workspaceId);
|
||||
|
||||
@ -119,7 +118,7 @@ export class ConnectedAccountRepository {
|
||||
|
||||
public async create(
|
||||
connectedAccount: Pick<
|
||||
ObjectRecord<ConnectedAccountWorkspaceEntity>,
|
||||
ConnectedAccountWorkspaceEntity,
|
||||
| 'id'
|
||||
| 'handle'
|
||||
| 'provider'
|
||||
@ -129,7 +128,7 @@ export class ConnectedAccountRepository {
|
||||
>,
|
||||
workspaceId: string,
|
||||
transactionManager?: EntityManager,
|
||||
): Promise<ObjectRecord<ConnectedAccountWorkspaceEntity>> {
|
||||
): Promise<ConnectedAccountWorkspaceEntity> {
|
||||
const dataSourceSchema =
|
||||
this.workspaceDataSourceService.getSchemaName(workspaceId);
|
||||
|
||||
@ -170,7 +169,7 @@ export class ConnectedAccountRepository {
|
||||
connectedAccountId: string,
|
||||
workspaceId: string,
|
||||
transactionManager?: EntityManager,
|
||||
): Promise<ObjectRecord<ConnectedAccountWorkspaceEntity> | undefined> {
|
||||
): Promise<ConnectedAccountWorkspaceEntity | undefined> {
|
||||
const dataSourceSchema =
|
||||
this.workspaceDataSourceService.getSchemaName(workspaceId);
|
||||
|
||||
@ -189,7 +188,7 @@ export class ConnectedAccountRepository {
|
||||
connectedAccountId: string,
|
||||
workspaceId: string,
|
||||
transactionManager?: EntityManager,
|
||||
): Promise<ObjectRecord<ConnectedAccountWorkspaceEntity>> {
|
||||
): Promise<ConnectedAccountWorkspaceEntity> {
|
||||
const connectedAccount = await this.getById(
|
||||
connectedAccountId,
|
||||
workspaceId,
|
||||
@ -293,7 +292,7 @@ export class ConnectedAccountRepository {
|
||||
public async getConnectedAccountOrThrow(
|
||||
workspaceId: string,
|
||||
connectedAccountId: string,
|
||||
): Promise<ObjectRecord<ConnectedAccountWorkspaceEntity>> {
|
||||
): Promise<ConnectedAccountWorkspaceEntity> {
|
||||
const connectedAccount = await this.getById(
|
||||
connectedAccountId,
|
||||
workspaceId,
|
||||
|
@ -11,6 +11,7 @@ import { WorkspaceIsNotAuditLogged } from 'src/engine/twenty-orm/decorators/work
|
||||
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 { WorkspaceJoinColumn } from 'src/engine/twenty-orm/decorators/workspace-join-column.decorator';
|
||||
|
||||
@WorkspaceEntity({
|
||||
standardId: STANDARD_OBJECT_IDS.blocklist,
|
||||
@ -38,9 +39,11 @@ export class BlocklistWorkspaceEntity extends BaseWorkspaceEntity {
|
||||
label: 'WorkspaceMember',
|
||||
description: 'WorkspaceMember',
|
||||
icon: 'IconCircleUser',
|
||||
joinColumn: 'workspaceMemberId',
|
||||
inverseSideTarget: () => WorkspaceMemberWorkspaceEntity,
|
||||
inverseSideFieldKey: 'blocklist',
|
||||
})
|
||||
workspaceMember: Relation<WorkspaceMemberWorkspaceEntity>;
|
||||
|
||||
@WorkspaceJoinColumn('workspaceMember')
|
||||
workspaceMemberId: string;
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ import { WorkspaceField } from 'src/engine/twenty-orm/decorators/workspace-field
|
||||
import { WorkspaceRelation } from 'src/engine/twenty-orm/decorators/workspace-relation.decorator';
|
||||
import { WorkspaceIsNullable } from 'src/engine/twenty-orm/decorators/workspace-is-nullable.decorator';
|
||||
import { MessageChannelWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-channel.workspace-entity';
|
||||
import { WorkspaceJoinColumn } from 'src/engine/twenty-orm/decorators/workspace-join-column.decorator';
|
||||
|
||||
export enum ConnectedAccountProvider {
|
||||
GOOGLE = 'google',
|
||||
@ -94,12 +95,12 @@ export class ConnectedAccountWorkspaceEntity extends BaseWorkspaceEntity {
|
||||
label: 'Account Owner',
|
||||
description: 'Account Owner',
|
||||
icon: 'IconUserCircle',
|
||||
joinColumn: 'accountOwnerId',
|
||||
inverseSideTarget: () => WorkspaceMemberWorkspaceEntity,
|
||||
inverseSideFieldKey: 'connectedAccounts',
|
||||
})
|
||||
accountOwner: Relation<WorkspaceMemberWorkspaceEntity>;
|
||||
|
||||
@WorkspaceJoinColumn('accountOwner')
|
||||
accountOwnerId: string;
|
||||
|
||||
@WorkspaceRelation({
|
||||
|
@ -17,6 +17,7 @@ import { WorkspaceRelation } from 'src/engine/twenty-orm/decorators/workspace-re
|
||||
import { RelationMetadataType } from 'src/engine/metadata-modules/relation-metadata/relation-metadata.entity';
|
||||
import { WorkspaceIsNullable } from 'src/engine/twenty-orm/decorators/workspace-is-nullable.decorator';
|
||||
import { WorkspaceDynamicRelation } from 'src/engine/twenty-orm/decorators/workspace-dynamic-relation.decorator';
|
||||
import { WorkspaceJoinColumn } from 'src/engine/twenty-orm/decorators/workspace-join-column.decorator';
|
||||
|
||||
@WorkspaceEntity({
|
||||
standardId: STANDARD_OBJECT_IDS.favorite,
|
||||
@ -46,51 +47,59 @@ export class FavoriteWorkspaceEntity extends BaseWorkspaceEntity {
|
||||
label: 'Workspace Member',
|
||||
description: 'Favorite workspace member',
|
||||
icon: 'IconCircleUser',
|
||||
joinColumn: 'workspaceMemberId',
|
||||
inverseSideFieldKey: 'favorites',
|
||||
inverseSideTarget: () => WorkspaceMemberWorkspaceEntity,
|
||||
})
|
||||
workspaceMember: Relation<WorkspaceMemberWorkspaceEntity>;
|
||||
|
||||
@WorkspaceJoinColumn('workspaceMember')
|
||||
workspaceMemberId: string;
|
||||
|
||||
@WorkspaceRelation({
|
||||
standardId: FAVORITE_STANDARD_FIELD_IDS.person,
|
||||
type: RelationMetadataType.MANY_TO_ONE,
|
||||
label: 'Person',
|
||||
description: 'Favorite person',
|
||||
icon: 'IconUser',
|
||||
joinColumn: 'personId',
|
||||
inverseSideTarget: () => PersonWorkspaceEntity,
|
||||
inverseSideFieldKey: 'favorites',
|
||||
})
|
||||
@WorkspaceIsNullable()
|
||||
person: Relation<PersonWorkspaceEntity> | null;
|
||||
|
||||
@WorkspaceJoinColumn('person')
|
||||
personId: string;
|
||||
|
||||
@WorkspaceRelation({
|
||||
standardId: FAVORITE_STANDARD_FIELD_IDS.company,
|
||||
type: RelationMetadataType.MANY_TO_ONE,
|
||||
label: 'Company',
|
||||
description: 'Favorite company',
|
||||
icon: 'IconBuildingSkyscraper',
|
||||
joinColumn: 'companyId',
|
||||
inverseSideTarget: () => CompanyWorkspaceEntity,
|
||||
inverseSideFieldKey: 'favorites',
|
||||
})
|
||||
@WorkspaceIsNullable()
|
||||
company: Relation<CompanyWorkspaceEntity> | null;
|
||||
|
||||
@WorkspaceJoinColumn('company')
|
||||
companyId: string;
|
||||
|
||||
@WorkspaceRelation({
|
||||
standardId: FAVORITE_STANDARD_FIELD_IDS.opportunity,
|
||||
type: RelationMetadataType.MANY_TO_ONE,
|
||||
label: 'Opportunity',
|
||||
description: 'Favorite opportunity',
|
||||
icon: 'IconTargetArrow',
|
||||
joinColumn: 'opportunityId',
|
||||
inverseSideTarget: () => OpportunityWorkspaceEntity,
|
||||
inverseSideFieldKey: 'favorites',
|
||||
})
|
||||
@WorkspaceIsNullable()
|
||||
opportunity: Relation<OpportunityWorkspaceEntity> | null;
|
||||
|
||||
@WorkspaceJoinColumn('opportunity')
|
||||
opportunityId: string;
|
||||
|
||||
@WorkspaceDynamicRelation({
|
||||
type: RelationMetadataType.MANY_TO_ONE,
|
||||
argsFactory: (oppositeObjectMetadata) => ({
|
||||
|
@ -3,7 +3,6 @@ import { Injectable } from '@nestjs/common';
|
||||
import { EntityManager } from 'typeorm';
|
||||
|
||||
import { WorkspaceDataSourceService } from 'src/engine/workspace-datasource/workspace-datasource.service';
|
||||
import { ObjectRecord } from 'src/engine/workspace-manager/workspace-sync-metadata/types/object-record';
|
||||
import { MessageChannelMessageAssociationWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-channel-message-association.workspace-entity';
|
||||
|
||||
@Injectable()
|
||||
@ -17,7 +16,7 @@ export class MessageChannelMessageAssociationRepository {
|
||||
messageChannelId: string,
|
||||
workspaceId: string,
|
||||
transactionManager?: EntityManager,
|
||||
): Promise<ObjectRecord<MessageChannelMessageAssociationWorkspaceEntity>[]> {
|
||||
): Promise<MessageChannelMessageAssociationWorkspaceEntity[]> {
|
||||
const dataSourceSchema =
|
||||
this.workspaceDataSourceService.getSchemaName(workspaceId);
|
||||
|
||||
@ -130,7 +129,7 @@ export class MessageChannelMessageAssociationRepository {
|
||||
messageChannelIds: string[],
|
||||
workspaceId: string,
|
||||
transactionManager?: EntityManager,
|
||||
): Promise<ObjectRecord<MessageChannelMessageAssociationWorkspaceEntity>[]> {
|
||||
): Promise<MessageChannelMessageAssociationWorkspaceEntity[]> {
|
||||
const dataSourceSchema =
|
||||
this.workspaceDataSourceService.getSchemaName(workspaceId);
|
||||
|
||||
@ -183,7 +182,7 @@ export class MessageChannelMessageAssociationRepository {
|
||||
messageThreadExternalIds: string[],
|
||||
workspaceId: string,
|
||||
transactionManager?: EntityManager,
|
||||
): Promise<ObjectRecord<MessageChannelMessageAssociationWorkspaceEntity>[]> {
|
||||
): Promise<MessageChannelMessageAssociationWorkspaceEntity[]> {
|
||||
const dataSourceSchema =
|
||||
this.workspaceDataSourceService.getSchemaName(workspaceId);
|
||||
|
||||
@ -200,7 +199,7 @@ export class MessageChannelMessageAssociationRepository {
|
||||
messageThreadExternalId: string,
|
||||
workspaceId: string,
|
||||
transactionManager?: EntityManager,
|
||||
): Promise<ObjectRecord<MessageChannelMessageAssociationWorkspaceEntity> | null> {
|
||||
): Promise<MessageChannelMessageAssociationWorkspaceEntity | null> {
|
||||
const existingMessageChannelMessageAssociations =
|
||||
await this.getByMessageThreadExternalIds(
|
||||
[messageThreadExternalId],
|
||||
@ -222,7 +221,7 @@ export class MessageChannelMessageAssociationRepository {
|
||||
messageIds: string[],
|
||||
workspaceId: string,
|
||||
transactionManager?: EntityManager,
|
||||
): Promise<ObjectRecord<MessageChannelMessageAssociationWorkspaceEntity>[]> {
|
||||
): Promise<MessageChannelMessageAssociationWorkspaceEntity[]> {
|
||||
const dataSourceSchema =
|
||||
this.workspaceDataSourceService.getSchemaName(workspaceId);
|
||||
|
||||
@ -239,7 +238,7 @@ export class MessageChannelMessageAssociationRepository {
|
||||
messageThreadId: string,
|
||||
workspaceId: string,
|
||||
transactionManager?: EntityManager,
|
||||
): Promise<ObjectRecord<MessageChannelMessageAssociationWorkspaceEntity>[]> {
|
||||
): Promise<MessageChannelMessageAssociationWorkspaceEntity[]> {
|
||||
const dataSourceSchema =
|
||||
this.workspaceDataSourceService.getSchemaName(workspaceId);
|
||||
|
||||
|
@ -3,7 +3,6 @@ import { Injectable } from '@nestjs/common';
|
||||
import { EntityManager } from 'typeorm';
|
||||
|
||||
import { WorkspaceDataSourceService } from 'src/engine/workspace-datasource/workspace-datasource.service';
|
||||
import { ObjectRecord } from 'src/engine/workspace-manager/workspace-sync-metadata/types/object-record';
|
||||
import {
|
||||
MessageChannelWorkspaceEntity,
|
||||
MessageChannelSyncStatus,
|
||||
@ -18,7 +17,7 @@ export class MessageChannelRepository {
|
||||
|
||||
public async create(
|
||||
messageChannel: Pick<
|
||||
ObjectRecord<MessageChannelWorkspaceEntity>,
|
||||
MessageChannelWorkspaceEntity,
|
||||
| 'id'
|
||||
| 'connectedAccountId'
|
||||
| 'type'
|
||||
@ -72,7 +71,7 @@ export class MessageChannelRepository {
|
||||
public async getAll(
|
||||
workspaceId: string,
|
||||
transactionManager?: EntityManager,
|
||||
): Promise<ObjectRecord<MessageChannelWorkspaceEntity>[]> {
|
||||
): Promise<MessageChannelWorkspaceEntity[]> {
|
||||
const dataSourceSchema =
|
||||
this.workspaceDataSourceService.getSchemaName(workspaceId);
|
||||
|
||||
@ -88,7 +87,7 @@ export class MessageChannelRepository {
|
||||
connectedAccountId: string,
|
||||
workspaceId: string,
|
||||
transactionManager?: EntityManager,
|
||||
): Promise<ObjectRecord<MessageChannelWorkspaceEntity>[]> {
|
||||
): Promise<MessageChannelWorkspaceEntity[]> {
|
||||
const dataSourceSchema =
|
||||
this.workspaceDataSourceService.getSchemaName(workspaceId);
|
||||
|
||||
@ -103,7 +102,7 @@ export class MessageChannelRepository {
|
||||
public async getFirstByConnectedAccountIdOrFail(
|
||||
connectedAccountId: string,
|
||||
workspaceId: string,
|
||||
): Promise<ObjectRecord<MessageChannelWorkspaceEntity>> {
|
||||
): Promise<MessageChannelWorkspaceEntity> {
|
||||
const messageChannel = await this.getFirstByConnectedAccountId(
|
||||
connectedAccountId,
|
||||
workspaceId,
|
||||
@ -122,7 +121,7 @@ export class MessageChannelRepository {
|
||||
connectedAccountId: string,
|
||||
workspaceId: string,
|
||||
transactionManager?: EntityManager,
|
||||
): Promise<ObjectRecord<MessageChannelWorkspaceEntity> | undefined> {
|
||||
): Promise<MessageChannelWorkspaceEntity | undefined> {
|
||||
const messageChannels = await this.getByConnectedAccountId(
|
||||
connectedAccountId,
|
||||
workspaceId,
|
||||
@ -136,7 +135,7 @@ export class MessageChannelRepository {
|
||||
ids: string[],
|
||||
workspaceId: string,
|
||||
transactionManager?: EntityManager,
|
||||
): Promise<ObjectRecord<MessageChannelWorkspaceEntity>[]> {
|
||||
): Promise<MessageChannelWorkspaceEntity[]> {
|
||||
const dataSourceSchema =
|
||||
this.workspaceDataSourceService.getSchemaName(workspaceId);
|
||||
|
||||
@ -152,7 +151,7 @@ export class MessageChannelRepository {
|
||||
id: string,
|
||||
workspaceId: string,
|
||||
transactionManager?: EntityManager,
|
||||
): Promise<ObjectRecord<MessageChannelWorkspaceEntity>> {
|
||||
): Promise<MessageChannelWorkspaceEntity> {
|
||||
const dataSourceSchema =
|
||||
this.workspaceDataSourceService.getSchemaName(workspaceId);
|
||||
|
||||
@ -171,7 +170,7 @@ export class MessageChannelRepository {
|
||||
workspaceMemberId: string,
|
||||
workspaceId: string,
|
||||
transactionManager?: EntityManager,
|
||||
): Promise<ObjectRecord<MessageChannelWorkspaceEntity>[]> {
|
||||
): Promise<MessageChannelWorkspaceEntity[]> {
|
||||
const dataSourceSchema =
|
||||
this.workspaceDataSourceService.getSchemaName(workspaceId);
|
||||
|
||||
|
@ -3,7 +3,6 @@ import { Injectable } from '@nestjs/common';
|
||||
import { EntityManager } from 'typeorm';
|
||||
|
||||
import { WorkspaceDataSourceService } from 'src/engine/workspace-datasource/workspace-datasource.service';
|
||||
import { ObjectRecord } from 'src/engine/workspace-manager/workspace-sync-metadata/types/object-record';
|
||||
import { MessageParticipantWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-participant.workspace-entity';
|
||||
import { ParticipantWithId } from 'src/modules/messaging/message-import-manager/drivers/gmail/types/gmail-message';
|
||||
|
||||
@ -17,7 +16,7 @@ export class MessageParticipantRepository {
|
||||
handles: string[],
|
||||
workspaceId: string,
|
||||
transactionManager?: EntityManager,
|
||||
): Promise<ObjectRecord<MessageParticipantWorkspaceEntity>[]> {
|
||||
): Promise<MessageParticipantWorkspaceEntity[]> {
|
||||
const dataSourceSchema =
|
||||
this.workspaceDataSourceService.getSchemaName(workspaceId);
|
||||
|
||||
|
@ -3,7 +3,6 @@ import { Injectable } from '@nestjs/common';
|
||||
import { EntityManager } from 'typeorm';
|
||||
|
||||
import { WorkspaceDataSourceService } from 'src/engine/workspace-datasource/workspace-datasource.service';
|
||||
import { ObjectRecord } from 'src/engine/workspace-manager/workspace-sync-metadata/types/object-record';
|
||||
import { MessageWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message.workspace-entity';
|
||||
|
||||
@Injectable()
|
||||
@ -40,7 +39,7 @@ export class MessageRepository {
|
||||
headerMessageId: string,
|
||||
workspaceId: string,
|
||||
transactionManager?: EntityManager,
|
||||
): Promise<ObjectRecord<MessageWorkspaceEntity> | null> {
|
||||
): Promise<MessageWorkspaceEntity | null> {
|
||||
const dataSourceSchema =
|
||||
this.workspaceDataSourceService.getSchemaName(workspaceId);
|
||||
|
||||
@ -62,7 +61,7 @@ export class MessageRepository {
|
||||
messageIds: string[],
|
||||
workspaceId: string,
|
||||
transactionManager?: EntityManager,
|
||||
): Promise<ObjectRecord<MessageWorkspaceEntity>[]> {
|
||||
): Promise<MessageWorkspaceEntity[]> {
|
||||
const dataSourceSchema =
|
||||
this.workspaceDataSourceService.getSchemaName(workspaceId);
|
||||
|
||||
@ -94,7 +93,7 @@ export class MessageRepository {
|
||||
messageThreadIds: string[],
|
||||
workspaceId: string,
|
||||
transactionManager?: EntityManager,
|
||||
): Promise<ObjectRecord<MessageWorkspaceEntity>[]> {
|
||||
): Promise<MessageWorkspaceEntity[]> {
|
||||
const dataSourceSchema =
|
||||
this.workspaceDataSourceService.getSchemaName(workspaceId);
|
||||
|
||||
|
@ -3,7 +3,6 @@ import { Injectable } from '@nestjs/common';
|
||||
import snakeCase from 'lodash.snakecase';
|
||||
|
||||
import { InjectObjectMetadataRepository } from 'src/engine/object-metadata-repository/object-metadata-repository.decorator';
|
||||
import { ObjectRecord } from 'src/engine/workspace-manager/workspace-sync-metadata/types/object-record';
|
||||
import { ConnectedAccountRepository } from 'src/modules/connected-account/repositories/connected-account.repository';
|
||||
import { ConnectedAccountWorkspaceEntity } from 'src/modules/connected-account/standard-objects/connected-account.workspace-entity';
|
||||
import { MessagingTelemetryService } from 'src/modules/messaging/common/services/messaging-telemetry.service';
|
||||
@ -36,7 +35,7 @@ export class MessagingErrorHandlingService {
|
||||
public async handleGmailError(
|
||||
error: GmailError,
|
||||
syncStep: SyncStep,
|
||||
messageChannel: ObjectRecord<MessageChannelWorkspaceEntity>,
|
||||
messageChannel: MessageChannelWorkspaceEntity,
|
||||
workspaceId: string,
|
||||
): Promise<void> {
|
||||
const { code, reason } = error;
|
||||
@ -156,7 +155,7 @@ export class MessagingErrorHandlingService {
|
||||
private async handleRateLimitExceeded(
|
||||
error: GmailError,
|
||||
syncStep: SyncStep,
|
||||
messageChannel: ObjectRecord<MessageChannelWorkspaceEntity>,
|
||||
messageChannel: MessageChannelWorkspaceEntity,
|
||||
workspaceId: string,
|
||||
): Promise<void> {
|
||||
await this.messagingTelemetryService.track({
|
||||
@ -190,7 +189,7 @@ export class MessagingErrorHandlingService {
|
||||
private async handleInsufficientPermissions(
|
||||
error: GmailError,
|
||||
syncStep: SyncStep,
|
||||
messageChannel: ObjectRecord<MessageChannelWorkspaceEntity>,
|
||||
messageChannel: MessageChannelWorkspaceEntity,
|
||||
workspaceId: string,
|
||||
): Promise<void> {
|
||||
await this.messagingTelemetryService.track({
|
||||
@ -221,7 +220,7 @@ export class MessagingErrorHandlingService {
|
||||
private async handleNotFound(
|
||||
error: GmailError,
|
||||
syncStep: SyncStep,
|
||||
messageChannel: ObjectRecord<MessageChannelWorkspaceEntity>,
|
||||
messageChannel: MessageChannelWorkspaceEntity,
|
||||
workspaceId: string,
|
||||
): Promise<void> {
|
||||
if (syncStep === 'messages-import') {
|
||||
@ -288,7 +287,7 @@ export class MessagingErrorHandlingService {
|
||||
}
|
||||
|
||||
private async throttle(
|
||||
messageChannel: ObjectRecord<MessageChannelWorkspaceEntity>,
|
||||
messageChannel: MessageChannelWorkspaceEntity,
|
||||
workspaceId: string,
|
||||
): Promise<void> {
|
||||
await this.messageChannelRepository.incrementThrottleFailureCount(
|
||||
|
@ -9,7 +9,6 @@ import { PersonWorkspaceEntity } from 'src/modules/person/standard-objects/perso
|
||||
import { WorkspaceDataSourceService } from 'src/engine/workspace-datasource/workspace-datasource.service';
|
||||
import { getFlattenedValuesAndValuesStringForBatchRawQuery } from 'src/modules/calendar/utils/get-flattened-values-and-values-string-for-batch-raw-query.util';
|
||||
import { AddPersonIdAndWorkspaceMemberIdService } from 'src/modules/calendar-messaging-participant/services/add-person-id-and-workspace-member-id/add-person-id-and-workspace-member-id.service';
|
||||
import { ObjectRecord } from 'src/engine/workspace-manager/workspace-sync-metadata/types/object-record';
|
||||
import { MessageParticipantRepository } from 'src/modules/messaging/common/repositories/message-participant.repository';
|
||||
import { MessageParticipantWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-participant.workspace-entity';
|
||||
import { ParticipantWithMessageId } from 'src/modules/messaging/message-import-manager/drivers/gmail/types/gmail-message';
|
||||
@ -29,10 +28,10 @@ export class MessagingMessageParticipantService {
|
||||
) {}
|
||||
|
||||
public async updateMessageParticipantsAfterPeopleCreation(
|
||||
createdPeople: ObjectRecord<PersonWorkspaceEntity>[],
|
||||
createdPeople: PersonWorkspaceEntity[],
|
||||
workspaceId: string,
|
||||
transactionManager?: EntityManager,
|
||||
): Promise<ObjectRecord<MessageParticipantWorkspaceEntity>[]> {
|
||||
): Promise<MessageParticipantWorkspaceEntity[]> {
|
||||
const participants = await this.messageParticipantRepository.getByHandles(
|
||||
createdPeople.map((person) => person.email),
|
||||
workspaceId,
|
||||
@ -87,7 +86,7 @@ export class MessagingMessageParticipantService {
|
||||
participants: ParticipantWithMessageId[],
|
||||
workspaceId: string,
|
||||
transactionManager?: EntityManager,
|
||||
): Promise<ObjectRecord<MessageParticipantWorkspaceEntity>[]> {
|
||||
): Promise<MessageParticipantWorkspaceEntity[]> {
|
||||
if (!participants) return [];
|
||||
|
||||
const dataSourceSchema =
|
||||
|
@ -4,7 +4,6 @@ import { DataSource, EntityManager } from 'typeorm';
|
||||
import { v4 } from 'uuid';
|
||||
|
||||
import { WorkspaceDataSourceService } from 'src/engine/workspace-datasource/workspace-datasource.service';
|
||||
import { ObjectRecord } from 'src/engine/workspace-manager/workspace-sync-metadata/types/object-record';
|
||||
import { InjectObjectMetadataRepository } from 'src/engine/object-metadata-repository/object-metadata-repository.decorator';
|
||||
import { ConnectedAccountWorkspaceEntity } from 'src/modules/connected-account/standard-objects/connected-account.workspace-entity';
|
||||
import { MessageChannelMessageAssociationRepository } from 'src/modules/messaging/common/repositories/message-channel-message-association.repository';
|
||||
@ -39,7 +38,7 @@ export class MessagingMessageService {
|
||||
|
||||
public async saveMessagesWithinTransaction(
|
||||
messages: GmailMessage[],
|
||||
connectedAccount: ObjectRecord<ConnectedAccountWorkspaceEntity>,
|
||||
connectedAccount: ConnectedAccountWorkspaceEntity,
|
||||
gmailMessageChannelId: string,
|
||||
workspaceId: string,
|
||||
transactionManager: EntityManager,
|
||||
@ -68,6 +67,12 @@ export class MessagingMessageService {
|
||||
transactionManager,
|
||||
);
|
||||
|
||||
if (!savedOrExistingMessageThreadId) {
|
||||
throw new Error(
|
||||
`No message thread found for message ${message.headerMessageId} in workspace ${workspaceId} in saveMessages`,
|
||||
);
|
||||
}
|
||||
|
||||
const savedOrExistingMessageId =
|
||||
await this.saveMessageOrReturnExistingMessage(
|
||||
message,
|
||||
@ -99,7 +104,7 @@ export class MessagingMessageService {
|
||||
public async saveMessages(
|
||||
messages: GmailMessage[],
|
||||
workspaceDataSource: DataSource,
|
||||
connectedAccount: ObjectRecord<ConnectedAccountWorkspaceEntity>,
|
||||
connectedAccount: ConnectedAccountWorkspaceEntity,
|
||||
gmailMessageChannelId: string,
|
||||
workspaceId: string,
|
||||
): Promise<Map<string, string>> {
|
||||
@ -153,6 +158,12 @@ export class MessagingMessageService {
|
||||
manager,
|
||||
);
|
||||
|
||||
if (!savedOrExistingMessageThreadId) {
|
||||
throw new Error(
|
||||
`No message thread found for message ${message.headerMessageId} in workspace ${workspaceId} in saveMessages`,
|
||||
);
|
||||
}
|
||||
|
||||
const savedOrExistingMessageId =
|
||||
await this.saveMessageOrReturnExistingMessage(
|
||||
message,
|
||||
@ -191,7 +202,7 @@ export class MessagingMessageService {
|
||||
private async saveMessageOrReturnExistingMessage(
|
||||
message: GmailMessage,
|
||||
messageThreadId: string,
|
||||
connectedAccount: ObjectRecord<ConnectedAccountWorkspaceEntity>,
|
||||
connectedAccount: ConnectedAccountWorkspaceEntity,
|
||||
workspaceId: string,
|
||||
manager: EntityManager,
|
||||
): Promise<string> {
|
||||
|
@ -7,7 +7,6 @@ import { EntityManager, Repository } from 'typeorm';
|
||||
import { MessageQueue } from 'src/engine/integrations/message-queue/message-queue.constants';
|
||||
import { MessageQueueService } from 'src/engine/integrations/message-queue/services/message-queue.service';
|
||||
import { WorkspaceDataSourceService } from 'src/engine/workspace-datasource/workspace-datasource.service';
|
||||
import { ObjectRecord } from 'src/engine/workspace-manager/workspace-sync-metadata/types/object-record';
|
||||
import { ConnectedAccountWorkspaceEntity } from 'src/modules/connected-account/standard-objects/connected-account.workspace-entity';
|
||||
import {
|
||||
CreateCompanyAndContactJobData,
|
||||
@ -43,8 +42,8 @@ export class MessagingSaveMessagesAndEnqueueContactCreationService {
|
||||
|
||||
async saveMessagesAndEnqueueContactCreationJob(
|
||||
messagesToSave: GmailMessage[],
|
||||
messageChannel: ObjectRecord<MessageChannelWorkspaceEntity>,
|
||||
connectedAccount: ObjectRecord<ConnectedAccountWorkspaceEntity>,
|
||||
messageChannel: MessageChannelWorkspaceEntity,
|
||||
connectedAccount: ConnectedAccountWorkspaceEntity,
|
||||
workspaceId: string,
|
||||
) {
|
||||
const workspaceDataSource =
|
||||
@ -62,8 +61,7 @@ export class MessagingSaveMessagesAndEnqueueContactCreationService {
|
||||
const isContactCreationForSentAndReceivedEmailsEnabled =
|
||||
isContactCreationForSentAndReceivedEmailsEnabledFeatureFlag?.value;
|
||||
|
||||
let savedMessageParticipants: ObjectRecord<MessageParticipantWorkspaceEntity>[] =
|
||||
[];
|
||||
let savedMessageParticipants: MessageParticipantWorkspaceEntity[] = [];
|
||||
|
||||
const participantsWithMessageId = await workspaceDataSource?.transaction(
|
||||
async (transactionManager: EntityManager) => {
|
||||
|
@ -14,6 +14,7 @@ import { RelationMetadataType } from 'src/engine/metadata-modules/relation-metad
|
||||
import { MessageChannelWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-channel.workspace-entity';
|
||||
import { MessageThreadWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-thread.workspace-entity';
|
||||
import { MessageWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message.workspace-entity';
|
||||
import { WorkspaceJoinColumn } from 'src/engine/twenty-orm/decorators/workspace-join-column.decorator';
|
||||
|
||||
@WorkspaceEntity({
|
||||
standardId: STANDARD_OBJECT_IDS.messageChannelMessageAssociation,
|
||||
@ -55,26 +56,30 @@ export class MessageChannelMessageAssociationWorkspaceEntity extends BaseWorkspa
|
||||
label: 'Message Channel Id',
|
||||
description: 'Message Channel Id',
|
||||
icon: 'IconHash',
|
||||
joinColumn: 'messageChannelId',
|
||||
inverseSideTarget: () => MessageChannelWorkspaceEntity,
|
||||
inverseSideFieldKey: 'messageChannelMessageAssociations',
|
||||
})
|
||||
@WorkspaceIsNullable()
|
||||
messageChannel: Relation<MessageChannelWorkspaceEntity> | null;
|
||||
|
||||
@WorkspaceJoinColumn('messageChannel')
|
||||
messageChannelId: string;
|
||||
|
||||
@WorkspaceRelation({
|
||||
standardId: MESSAGE_CHANNEL_MESSAGE_ASSOCIATION_STANDARD_FIELD_IDS.message,
|
||||
type: RelationMetadataType.MANY_TO_ONE,
|
||||
label: 'Message Id',
|
||||
description: 'Message Id',
|
||||
icon: 'IconHash',
|
||||
joinColumn: 'messageId',
|
||||
inverseSideTarget: () => MessageWorkspaceEntity,
|
||||
inverseSideFieldKey: 'messageChannelMessageAssociations',
|
||||
})
|
||||
@WorkspaceIsNullable()
|
||||
message: Relation<MessageWorkspaceEntity> | null;
|
||||
|
||||
@WorkspaceJoinColumn('message')
|
||||
messageId: string;
|
||||
|
||||
@WorkspaceRelation({
|
||||
standardId:
|
||||
MESSAGE_CHANNEL_MESSAGE_ASSOCIATION_STANDARD_FIELD_IDS.messageThread,
|
||||
@ -82,10 +87,12 @@ export class MessageChannelMessageAssociationWorkspaceEntity extends BaseWorkspa
|
||||
label: 'Message Thread Id',
|
||||
description: 'Message Thread Id',
|
||||
icon: 'IconHash',
|
||||
joinColumn: 'messageThreadId',
|
||||
inverseSideTarget: () => MessageThreadWorkspaceEntity,
|
||||
inverseSideFieldKey: 'messageChannelMessageAssociations',
|
||||
})
|
||||
@WorkspaceIsNullable()
|
||||
messageThread: Relation<MessageThreadWorkspaceEntity> | null;
|
||||
|
||||
@WorkspaceJoinColumn('messageThread')
|
||||
messageThreadId: string;
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ import { WorkspaceField } from 'src/engine/twenty-orm/decorators/workspace-field
|
||||
import { WorkspaceIsNullable } from 'src/engine/twenty-orm/decorators/workspace-is-nullable.decorator';
|
||||
import { WorkspaceRelation } from 'src/engine/twenty-orm/decorators/workspace-relation.decorator';
|
||||
import { MessageChannelMessageAssociationWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-channel-message-association.workspace-entity';
|
||||
import { WorkspaceJoinColumn } from 'src/engine/twenty-orm/decorators/workspace-join-column.decorator';
|
||||
|
||||
export enum MessageChannelSyncStatus {
|
||||
// TO BE DEPRECATED
|
||||
@ -300,11 +301,12 @@ export class MessageChannelWorkspaceEntity extends BaseWorkspaceEntity {
|
||||
label: 'Connected Account',
|
||||
description: 'Connected Account',
|
||||
icon: 'IconUserCircle',
|
||||
joinColumn: 'connectedAccountId',
|
||||
inverseSideTarget: () => ConnectedAccountWorkspaceEntity,
|
||||
inverseSideFieldKey: 'messageChannels',
|
||||
})
|
||||
connectedAccount: Relation<ConnectedAccountWorkspaceEntity>;
|
||||
|
||||
@WorkspaceJoinColumn('connectedAccount')
|
||||
connectedAccountId: string;
|
||||
|
||||
@WorkspaceRelation({
|
||||
|
@ -14,6 +14,7 @@ import { WorkspaceRelation } from 'src/engine/twenty-orm/decorators/workspace-re
|
||||
import { RelationMetadataType } from 'src/engine/metadata-modules/relation-metadata/relation-metadata.entity';
|
||||
import { WorkspaceIsNullable } from 'src/engine/twenty-orm/decorators/workspace-is-nullable.decorator';
|
||||
import { MessageWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message.workspace-entity';
|
||||
import { WorkspaceJoinColumn } from 'src/engine/twenty-orm/decorators/workspace-join-column.decorator';
|
||||
|
||||
@WorkspaceEntity({
|
||||
standardId: STANDARD_OBJECT_IDS.messageParticipant,
|
||||
@ -66,35 +67,41 @@ export class MessageParticipantWorkspaceEntity extends BaseWorkspaceEntity {
|
||||
label: 'Message',
|
||||
description: 'Message',
|
||||
icon: 'IconMessage',
|
||||
joinColumn: 'messageId',
|
||||
inverseSideTarget: () => MessageWorkspaceEntity,
|
||||
inverseSideFieldKey: 'messageParticipants',
|
||||
})
|
||||
message: Relation<MessageWorkspaceEntity>;
|
||||
|
||||
@WorkspaceJoinColumn('message')
|
||||
messageId: string;
|
||||
|
||||
@WorkspaceRelation({
|
||||
standardId: MESSAGE_PARTICIPANT_STANDARD_FIELD_IDS.person,
|
||||
type: RelationMetadataType.MANY_TO_ONE,
|
||||
label: 'Person',
|
||||
description: 'Person',
|
||||
icon: 'IconUser',
|
||||
joinColumn: 'personId',
|
||||
inverseSideTarget: () => PersonWorkspaceEntity,
|
||||
inverseSideFieldKey: 'messageParticipants',
|
||||
})
|
||||
@WorkspaceIsNullable()
|
||||
person: Relation<PersonWorkspaceEntity> | null;
|
||||
|
||||
@WorkspaceJoinColumn('person')
|
||||
personId: string | null;
|
||||
|
||||
@WorkspaceRelation({
|
||||
standardId: MESSAGE_PARTICIPANT_STANDARD_FIELD_IDS.workspaceMember,
|
||||
type: RelationMetadataType.MANY_TO_ONE,
|
||||
label: 'Workspace Member',
|
||||
description: 'Workspace member',
|
||||
icon: 'IconCircleUser',
|
||||
joinColumn: 'workspaceMemberId',
|
||||
inverseSideTarget: () => WorkspaceMemberWorkspaceEntity,
|
||||
inverseSideFieldKey: 'messageParticipants',
|
||||
})
|
||||
@WorkspaceIsNullable()
|
||||
workspaceMember: Relation<WorkspaceMemberWorkspaceEntity> | null;
|
||||
|
||||
@WorkspaceJoinColumn('workspaceMember')
|
||||
workspaceMemberId: string | null;
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ import { WorkspaceRelation } from 'src/engine/twenty-orm/decorators/workspace-re
|
||||
import { MessageChannelMessageAssociationWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-channel-message-association.workspace-entity';
|
||||
import { MessageParticipantWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-participant.workspace-entity';
|
||||
import { MessageThreadWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-thread.workspace-entity';
|
||||
import { WorkspaceJoinColumn } from 'src/engine/twenty-orm/decorators/workspace-join-column.decorator';
|
||||
|
||||
@WorkspaceEntity({
|
||||
standardId: STANDARD_OBJECT_IDS.message,
|
||||
@ -86,7 +87,6 @@ export class MessageWorkspaceEntity extends BaseWorkspaceEntity {
|
||||
label: 'Message Thread Id',
|
||||
description: 'Message Thread Id',
|
||||
icon: 'IconHash',
|
||||
joinColumn: 'messageThreadId',
|
||||
inverseSideTarget: () => MessageThreadWorkspaceEntity,
|
||||
inverseSideFieldKey: 'messages',
|
||||
onDelete: RelationOnDeleteAction.CASCADE,
|
||||
@ -94,6 +94,9 @@ export class MessageWorkspaceEntity extends BaseWorkspaceEntity {
|
||||
@WorkspaceIsNullable()
|
||||
messageThread: Relation<MessageThreadWorkspaceEntity> | null;
|
||||
|
||||
@WorkspaceJoinColumn('messageThread')
|
||||
messageThreadId: string | null;
|
||||
|
||||
@WorkspaceRelation({
|
||||
standardId: MESSAGE_STANDARD_FIELD_IDS.messageParticipants,
|
||||
type: RelationMetadataType.ONE_TO_MANY,
|
||||
|
@ -9,7 +9,6 @@ import { InjectCacheStorage } from 'src/engine/integrations/cache-storage/decora
|
||||
import { CacheStorageNamespace } from 'src/engine/integrations/cache-storage/types/cache-storage-namespace.enum';
|
||||
import { InjectObjectMetadataRepository } from 'src/engine/object-metadata-repository/object-metadata-repository.decorator';
|
||||
import { ConnectedAccountWorkspaceEntity } from 'src/modules/connected-account/standard-objects/connected-account.workspace-entity';
|
||||
import { ObjectRecord } from 'src/engine/workspace-manager/workspace-sync-metadata/types/object-record';
|
||||
import { MessageChannelMessageAssociationRepository } from 'src/modules/messaging/common/repositories/message-channel-message-association.repository';
|
||||
import { MessageChannelRepository } from 'src/modules/messaging/common/repositories/message-channel.repository';
|
||||
import { MessageChannelMessageAssociationWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-channel-message-association.workspace-entity';
|
||||
@ -50,8 +49,8 @@ export class MessagingGmailFullMessageListFetchService {
|
||||
) {}
|
||||
|
||||
public async processMessageListFetch(
|
||||
messageChannel: ObjectRecord<MessageChannelWorkspaceEntity>,
|
||||
connectedAccount: ObjectRecord<ConnectedAccountWorkspaceEntity>,
|
||||
messageChannel: MessageChannelWorkspaceEntity,
|
||||
connectedAccount: ConnectedAccountWorkspaceEntity,
|
||||
workspaceId: string,
|
||||
) {
|
||||
await this.messagingChannelSyncStatusService.markAsMessagesListFetchOngoing(
|
||||
|
@ -4,7 +4,6 @@ import { ConnectedAccountWorkspaceEntity } from 'src/modules/connected-account/s
|
||||
import { InjectCacheStorage } from 'src/engine/integrations/cache-storage/decorators/cache-storage.decorator';
|
||||
import { CacheStorageNamespace } from 'src/engine/integrations/cache-storage/types/cache-storage-namespace.enum';
|
||||
import { CacheStorageService } from 'src/engine/integrations/cache-storage/cache-storage.service';
|
||||
import { ObjectRecord } from 'src/engine/workspace-manager/workspace-sync-metadata/types/object-record';
|
||||
import { GoogleAPIRefreshAccessTokenService } from 'src/modules/connected-account/services/google-api-refresh-access-token/google-api-refresh-access-token.service';
|
||||
import { BlocklistWorkspaceEntity } from 'src/modules/connected-account/standard-objects/blocklist.workspace-entity';
|
||||
import { InjectObjectMetadataRepository } from 'src/engine/object-metadata-repository/object-metadata-repository.decorator';
|
||||
@ -44,8 +43,8 @@ export class MessagingGmailMessagesImportService {
|
||||
) {}
|
||||
|
||||
async processMessageBatchImport(
|
||||
messageChannel: ObjectRecord<MessageChannelWorkspaceEntity>,
|
||||
connectedAccount: ObjectRecord<ConnectedAccountWorkspaceEntity>,
|
||||
messageChannel: MessageChannelWorkspaceEntity,
|
||||
connectedAccount: ConnectedAccountWorkspaceEntity,
|
||||
workspaceId: string,
|
||||
) {
|
||||
if (
|
||||
@ -185,7 +184,7 @@ export class MessagingGmailMessagesImportService {
|
||||
}
|
||||
|
||||
private async trackMessageImportCompleted(
|
||||
messageChannel: ObjectRecord<MessageChannelWorkspaceEntity>,
|
||||
messageChannel: MessageChannelWorkspaceEntity,
|
||||
workspaceId: string,
|
||||
) {
|
||||
await this.messagingTelemetryService.track({
|
||||
|
@ -7,7 +7,6 @@ import { ConnectedAccountWorkspaceEntity } from 'src/modules/connected-account/s
|
||||
import { CacheStorageService } from 'src/engine/integrations/cache-storage/cache-storage.service';
|
||||
import { InjectCacheStorage } from 'src/engine/integrations/cache-storage/decorators/cache-storage.decorator';
|
||||
import { CacheStorageNamespace } from 'src/engine/integrations/cache-storage/types/cache-storage-namespace.enum';
|
||||
import { ObjectRecord } from 'src/engine/workspace-manager/workspace-sync-metadata/types/object-record';
|
||||
import { MessageChannelMessageAssociationRepository } from 'src/modules/messaging/common/repositories/message-channel-message-association.repository';
|
||||
import { MessageChannelRepository } from 'src/modules/messaging/common/repositories/message-channel.repository';
|
||||
import { MessageChannelMessageAssociationWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-channel-message-association.workspace-entity';
|
||||
@ -41,8 +40,8 @@ export class MessagingGmailPartialMessageListFetchService {
|
||||
) {}
|
||||
|
||||
public async processMessageListFetch(
|
||||
messageChannel: ObjectRecord<MessageChannelWorkspaceEntity>,
|
||||
connectedAccount: ObjectRecord<ConnectedAccountWorkspaceEntity>,
|
||||
messageChannel: MessageChannelWorkspaceEntity,
|
||||
connectedAccount: ConnectedAccountWorkspaceEntity,
|
||||
workspaceId: string,
|
||||
): Promise<void> {
|
||||
await this.messagingChannelSyncStatusService.markAsMessagesListFetchOngoing(
|
||||
|
@ -9,7 +9,6 @@ import { InjectObjectMetadataRepository } from 'src/engine/object-metadata-repos
|
||||
import { WorkspaceDataSourceService } from 'src/engine/workspace-datasource/workspace-datasource.service';
|
||||
import { TimelineActivityRepository } from 'src/modules/timeline/repositiories/timeline-activity.repository';
|
||||
import { TimelineActivityWorkspaceEntity } from 'src/modules/timeline/standard-objects/timeline-activity.workspace-entity';
|
||||
import { ObjectRecord } from 'src/engine/workspace-manager/workspace-sync-metadata/types/object-record';
|
||||
import { MessageParticipantWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-participant.workspace-entity';
|
||||
|
||||
@Injectable()
|
||||
@ -26,7 +25,7 @@ export class MessageParticipantListener {
|
||||
public async handleMessageParticipantMatched(payload: {
|
||||
workspaceId: string;
|
||||
workspaceMemberId: string;
|
||||
messageParticipants: ObjectRecord<MessageParticipantWorkspaceEntity>[];
|
||||
messageParticipants: MessageParticipantWorkspaceEntity[];
|
||||
}): Promise<void> {
|
||||
const messageParticipants = payload.messageParticipants ?? [];
|
||||
|
||||
|
@ -21,6 +21,7 @@ import { WorkspaceField } from 'src/engine/twenty-orm/decorators/workspace-field
|
||||
import { WorkspaceIsNullable } from 'src/engine/twenty-orm/decorators/workspace-is-nullable.decorator';
|
||||
import { WorkspaceIsSystem } from 'src/engine/twenty-orm/decorators/workspace-is-system.decorator';
|
||||
import { WorkspaceRelation } from 'src/engine/twenty-orm/decorators/workspace-relation.decorator';
|
||||
import { WorkspaceJoinColumn } from 'src/engine/twenty-orm/decorators/workspace-join-column.decorator';
|
||||
|
||||
@WorkspaceEntity({
|
||||
standardId: STANDARD_OBJECT_IDS.opportunity,
|
||||
@ -110,7 +111,6 @@ export class OpportunityWorkspaceEntity extends BaseWorkspaceEntity {
|
||||
label: 'Point of Contact',
|
||||
description: 'Opportunity point of contact',
|
||||
icon: 'IconUser',
|
||||
joinColumn: 'pointOfContactId',
|
||||
inverseSideTarget: () => PersonWorkspaceEntity,
|
||||
inverseSideFieldKey: 'pointOfContactForOpportunities',
|
||||
onDelete: RelationOnDeleteAction.SET_NULL,
|
||||
@ -118,13 +118,15 @@ export class OpportunityWorkspaceEntity extends BaseWorkspaceEntity {
|
||||
@WorkspaceIsNullable()
|
||||
pointOfContact: Relation<PersonWorkspaceEntity> | null;
|
||||
|
||||
@WorkspaceJoinColumn('pointOfContact')
|
||||
pointOfContactId: string | null;
|
||||
|
||||
@WorkspaceRelation({
|
||||
standardId: OPPORTUNITY_STANDARD_FIELD_IDS.company,
|
||||
type: RelationMetadataType.MANY_TO_ONE,
|
||||
label: 'Company',
|
||||
description: 'Opportunity company',
|
||||
icon: 'IconBuildingSkyscraper',
|
||||
joinColumn: 'companyId',
|
||||
inverseSideTarget: () => CompanyWorkspaceEntity,
|
||||
inverseSideFieldKey: 'opportunities',
|
||||
onDelete: RelationOnDeleteAction.SET_NULL,
|
||||
@ -132,6 +134,9 @@ export class OpportunityWorkspaceEntity extends BaseWorkspaceEntity {
|
||||
@WorkspaceIsNullable()
|
||||
company: Relation<CompanyWorkspaceEntity> | null;
|
||||
|
||||
@WorkspaceJoinColumn('company')
|
||||
companyId: string | null;
|
||||
|
||||
@WorkspaceRelation({
|
||||
standardId: OPPORTUNITY_STANDARD_FIELD_IDS.favorites,
|
||||
type: RelationMetadataType.ONE_TO_MANY,
|
||||
|
@ -3,7 +3,6 @@ import { Injectable } from '@nestjs/common';
|
||||
import { EntityManager } from 'typeorm';
|
||||
|
||||
import { WorkspaceDataSourceService } from 'src/engine/workspace-datasource/workspace-datasource.service';
|
||||
import { ObjectRecord } from 'src/engine/workspace-manager/workspace-sync-metadata/types/object-record';
|
||||
import { PersonWorkspaceEntity } from 'src/modules/person/standard-objects/person.workspace-entity';
|
||||
import { getFlattenedValuesAndValuesStringForBatchRawQuery } from 'src/modules/calendar/utils/get-flattened-values-and-values-string-for-batch-raw-query.util';
|
||||
|
||||
@ -17,7 +16,7 @@ export class PersonRepository {
|
||||
emails: string[],
|
||||
workspaceId: string,
|
||||
transactionManager?: EntityManager,
|
||||
): Promise<ObjectRecord<PersonWorkspaceEntity>[]> {
|
||||
): Promise<PersonWorkspaceEntity[]> {
|
||||
const dataSourceSchema =
|
||||
this.workspaceDataSourceService.getSchemaName(workspaceId);
|
||||
|
||||
@ -56,7 +55,7 @@ export class PersonRepository {
|
||||
}[],
|
||||
workspaceId: string,
|
||||
transactionManager?: EntityManager,
|
||||
): Promise<ObjectRecord<PersonWorkspaceEntity>[]> {
|
||||
): Promise<PersonWorkspaceEntity[]> {
|
||||
const dataSourceSchema =
|
||||
this.workspaceDataSourceService.getSchemaName(workspaceId);
|
||||
|
||||
|
@ -23,6 +23,7 @@ import { WorkspaceIsNullable } from 'src/engine/twenty-orm/decorators/workspace-
|
||||
import { WorkspaceIsSystem } from 'src/engine/twenty-orm/decorators/workspace-is-system.decorator';
|
||||
import { WorkspaceRelation } from 'src/engine/twenty-orm/decorators/workspace-relation.decorator';
|
||||
import { MessageParticipantWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-participant.workspace-entity';
|
||||
import { WorkspaceJoinColumn } from 'src/engine/twenty-orm/decorators/workspace-join-column.decorator';
|
||||
|
||||
@WorkspaceEntity({
|
||||
standardId: STANDARD_OBJECT_IDS.person,
|
||||
@ -127,13 +128,15 @@ export class PersonWorkspaceEntity extends BaseWorkspaceEntity {
|
||||
label: 'Company',
|
||||
description: 'Contact’s company',
|
||||
icon: 'IconBuildingSkyscraper',
|
||||
joinColumn: 'companyId',
|
||||
inverseSideTarget: () => CompanyWorkspaceEntity,
|
||||
inverseSideFieldKey: 'people',
|
||||
})
|
||||
@WorkspaceIsNullable()
|
||||
company: Relation<CompanyWorkspaceEntity> | null;
|
||||
|
||||
@WorkspaceJoinColumn('company')
|
||||
companyId: string | null;
|
||||
|
||||
@WorkspaceRelation({
|
||||
standardId: PERSON_STANDARD_FIELD_IDS.pointOfContactForOpportunities,
|
||||
type: RelationMetadataType.ONE_TO_MANY,
|
||||
|
@ -11,6 +11,7 @@ import { WorkspaceField } from 'src/engine/twenty-orm/decorators/workspace-field
|
||||
import { WorkspaceIsNullable } from 'src/engine/twenty-orm/decorators/workspace-is-nullable.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 { WorkspaceJoinColumn } from 'src/engine/twenty-orm/decorators/workspace-join-column.decorator';
|
||||
|
||||
@WorkspaceEntity({
|
||||
standardId: STANDARD_OBJECT_IDS.auditLog,
|
||||
@ -86,10 +87,12 @@ export class AuditLogWorkspaceEntity extends BaseWorkspaceEntity {
|
||||
label: 'Workspace Member',
|
||||
description: 'Event workspace member',
|
||||
icon: 'IconCircleUser',
|
||||
joinColumn: 'workspaceMemberId',
|
||||
inverseSideTarget: () => WorkspaceMemberWorkspaceEntity,
|
||||
inverseSideFieldKey: 'auditLogs',
|
||||
})
|
||||
@WorkspaceIsNullable()
|
||||
workspaceMember: Relation<WorkspaceMemberWorkspaceEntity> | null;
|
||||
|
||||
@WorkspaceJoinColumn('workspaceMember')
|
||||
workspaceMemberId: string | null;
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ import { WorkspaceIsNullable } from 'src/engine/twenty-orm/decorators/workspace-
|
||||
import { WorkspaceRelation } from 'src/engine/twenty-orm/decorators/workspace-relation.decorator';
|
||||
import { RelationMetadataType } from 'src/engine/metadata-modules/relation-metadata/relation-metadata.entity';
|
||||
import { WorkspaceDynamicRelation } from 'src/engine/twenty-orm/decorators/workspace-dynamic-relation.decorator';
|
||||
import { WorkspaceJoinColumn } from 'src/engine/twenty-orm/decorators/workspace-join-column.decorator';
|
||||
|
||||
@WorkspaceEntity({
|
||||
standardId: STANDARD_OBJECT_IDS.timelineActivity,
|
||||
@ -95,52 +96,60 @@ export class TimelineActivityWorkspaceEntity extends BaseWorkspaceEntity {
|
||||
label: 'Workspace Member',
|
||||
description: 'Event workspace member',
|
||||
icon: 'IconCircleUser',
|
||||
joinColumn: 'workspaceMemberId',
|
||||
inverseSideTarget: () => WorkspaceMemberWorkspaceEntity,
|
||||
inverseSideFieldKey: 'timelineActivities',
|
||||
})
|
||||
@WorkspaceIsNullable()
|
||||
workspaceMember: Relation<WorkspaceMemberWorkspaceEntity> | null;
|
||||
|
||||
@WorkspaceJoinColumn('workspaceMember')
|
||||
workspaceMemberId: string | null;
|
||||
|
||||
@WorkspaceRelation({
|
||||
standardId: TIMELINE_ACTIVITY_STANDARD_FIELD_IDS.person,
|
||||
type: RelationMetadataType.MANY_TO_ONE,
|
||||
label: 'Person',
|
||||
description: 'Event person',
|
||||
icon: 'IconUser',
|
||||
joinColumn: 'personId',
|
||||
inverseSideTarget: () => PersonWorkspaceEntity,
|
||||
inverseSideFieldKey: 'timelineActivities',
|
||||
})
|
||||
@WorkspaceIsNullable()
|
||||
person: Relation<PersonWorkspaceEntity> | null;
|
||||
|
||||
@WorkspaceJoinColumn('person')
|
||||
personId: string | null;
|
||||
|
||||
@WorkspaceRelation({
|
||||
standardId: TIMELINE_ACTIVITY_STANDARD_FIELD_IDS.company,
|
||||
type: RelationMetadataType.MANY_TO_ONE,
|
||||
label: 'Company',
|
||||
description: 'Event company',
|
||||
icon: 'IconBuildingSkyscraper',
|
||||
joinColumn: 'companyId',
|
||||
inverseSideTarget: () => CompanyWorkspaceEntity,
|
||||
inverseSideFieldKey: 'timelineActivities',
|
||||
})
|
||||
@WorkspaceIsNullable()
|
||||
company: Relation<CompanyWorkspaceEntity> | null;
|
||||
|
||||
@WorkspaceJoinColumn('company')
|
||||
companyId: string | null;
|
||||
|
||||
@WorkspaceRelation({
|
||||
standardId: TIMELINE_ACTIVITY_STANDARD_FIELD_IDS.opportunity,
|
||||
type: RelationMetadataType.MANY_TO_ONE,
|
||||
label: 'Opportunity',
|
||||
description: 'Event opportunity',
|
||||
icon: 'IconTargetArrow',
|
||||
joinColumn: 'opportunityId',
|
||||
inverseSideTarget: () => OpportunityWorkspaceEntity,
|
||||
inverseSideFieldKey: 'timelineActivities',
|
||||
})
|
||||
@WorkspaceIsNullable()
|
||||
opportunity: Relation<OpportunityWorkspaceEntity> | null;
|
||||
|
||||
@WorkspaceJoinColumn('opportunity')
|
||||
opportunityId: string | null;
|
||||
|
||||
@WorkspaceDynamicRelation({
|
||||
type: RelationMetadataType.MANY_TO_ONE,
|
||||
argsFactory: (oppositeObjectMetadata) => ({
|
||||
|
@ -10,6 +10,7 @@ import { WorkspaceRelation } from 'src/engine/twenty-orm/decorators/workspace-re
|
||||
import { VIEW_FIELD_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 { ViewWorkspaceEntity } from 'src/modules/view/standard-objects/view.workspace-entity';
|
||||
import { WorkspaceJoinColumn } from 'src/engine/twenty-orm/decorators/workspace-join-column.decorator';
|
||||
|
||||
@WorkspaceEntity({
|
||||
standardId: STANDARD_OBJECT_IDS.viewField,
|
||||
@ -69,8 +70,10 @@ export class ViewFieldWorkspaceEntity extends BaseWorkspaceEntity {
|
||||
icon: 'IconLayoutCollage',
|
||||
inverseSideTarget: () => ViewWorkspaceEntity,
|
||||
inverseSideFieldKey: 'viewFields',
|
||||
joinColumn: 'viewId',
|
||||
})
|
||||
@WorkspaceIsNullable()
|
||||
view?: ViewWorkspaceEntity | null;
|
||||
|
||||
@WorkspaceJoinColumn('view')
|
||||
viewId: string | null;
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import { WorkspaceField } from 'src/engine/twenty-orm/decorators/workspace-field
|
||||
import { WorkspaceRelation } from 'src/engine/twenty-orm/decorators/workspace-relation.decorator';
|
||||
import { RelationMetadataType } from 'src/engine/metadata-modules/relation-metadata/relation-metadata.entity';
|
||||
import { WorkspaceIsNullable } from 'src/engine/twenty-orm/decorators/workspace-is-nullable.decorator';
|
||||
import { WorkspaceJoinColumn } from 'src/engine/twenty-orm/decorators/workspace-join-column.decorator';
|
||||
|
||||
@WorkspaceEntity({
|
||||
standardId: STANDARD_OBJECT_IDS.viewFilter,
|
||||
@ -63,10 +64,12 @@ export class ViewFilterWorkspaceEntity extends BaseWorkspaceEntity {
|
||||
label: 'View',
|
||||
description: 'View Filter related view',
|
||||
icon: 'IconLayoutCollage',
|
||||
joinColumn: 'viewId',
|
||||
inverseSideTarget: () => ViewWorkspaceEntity,
|
||||
inverseSideFieldKey: 'viewFilters',
|
||||
})
|
||||
@WorkspaceIsNullable()
|
||||
view: Relation<ViewWorkspaceEntity> | null;
|
||||
|
||||
@WorkspaceJoinColumn('view')
|
||||
viewId: string | null;
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import { WorkspaceField } from 'src/engine/twenty-orm/decorators/workspace-field
|
||||
import { WorkspaceIsNullable } from 'src/engine/twenty-orm/decorators/workspace-is-nullable.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 { WorkspaceJoinColumn } from 'src/engine/twenty-orm/decorators/workspace-join-column.decorator';
|
||||
|
||||
@WorkspaceEntity({
|
||||
standardId: STANDARD_OBJECT_IDS.viewSort,
|
||||
@ -48,10 +49,12 @@ export class ViewSortWorkspaceEntity extends BaseWorkspaceEntity {
|
||||
label: 'View',
|
||||
description: 'View Sort related view',
|
||||
icon: 'IconLayoutCollage',
|
||||
joinColumn: 'viewId',
|
||||
inverseSideTarget: () => ViewWorkspaceEntity,
|
||||
inverseSideFieldKey: 'viewSorts',
|
||||
})
|
||||
@WorkspaceIsNullable()
|
||||
view: Relation<ViewWorkspaceEntity> | null;
|
||||
|
||||
@WorkspaceJoinColumn('view')
|
||||
viewId: string | null;
|
||||
}
|
||||
|
@ -27,15 +27,11 @@ export class WorkspaceMemberDeleteOnePreQueryHook
|
||||
const authorId = payload.id;
|
||||
|
||||
await this.attachmentRepository.delete({
|
||||
author: {
|
||||
id: authorId,
|
||||
},
|
||||
authorId,
|
||||
});
|
||||
|
||||
await this.commentRepository.delete({
|
||||
author: {
|
||||
id: authorId,
|
||||
},
|
||||
authorId,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ import { EntityManager } from 'typeorm';
|
||||
|
||||
import { WorkspaceDataSourceService } from 'src/engine/workspace-datasource/workspace-datasource.service';
|
||||
import { WorkspaceMemberWorkspaceEntity } from 'src/modules/workspace-member/standard-objects/workspace-member.workspace-entity';
|
||||
import { ObjectRecord } from 'src/engine/workspace-manager/workspace-sync-metadata/types/object-record';
|
||||
|
||||
@Injectable()
|
||||
export class WorkspaceMemberRepository {
|
||||
@ -15,7 +14,7 @@ export class WorkspaceMemberRepository {
|
||||
public async getByIds(
|
||||
userIds: string[],
|
||||
workspaceId: string,
|
||||
): Promise<ObjectRecord<WorkspaceMemberWorkspaceEntity>[]> {
|
||||
): Promise<WorkspaceMemberWorkspaceEntity[]> {
|
||||
const dataSourceSchema =
|
||||
this.workspaceDataSourceService.getSchemaName(workspaceId);
|
||||
|
||||
@ -45,7 +44,7 @@ export class WorkspaceMemberRepository {
|
||||
public async getByIdOrFail(
|
||||
userId: string,
|
||||
workspaceId: string,
|
||||
): Promise<ObjectRecord<WorkspaceMemberWorkspaceEntity>> {
|
||||
): Promise<WorkspaceMemberWorkspaceEntity> {
|
||||
const dataSourceSchema =
|
||||
this.workspaceDataSourceService.getSchemaName(workspaceId);
|
||||
|
||||
@ -68,7 +67,7 @@ export class WorkspaceMemberRepository {
|
||||
public async getAllByWorkspaceId(
|
||||
workspaceId: string,
|
||||
transactionManager?: EntityManager,
|
||||
): Promise<ObjectRecord<WorkspaceMemberWorkspaceEntity>[]> {
|
||||
): Promise<WorkspaceMemberWorkspaceEntity[]> {
|
||||
const dataSourceSchema =
|
||||
this.workspaceDataSourceService.getSchemaName(workspaceId);
|
||||
|
||||
|
@ -8,7 +8,6 @@ export interface ReflectMetadataTypeMap {
|
||||
['workspace:is-system-metadata-args']: true;
|
||||
['workspace:is-audit-logged-metadata-args']: false;
|
||||
['workspace:is-primary-field-metadata-args']: true;
|
||||
['workspace:join-column']: true;
|
||||
}
|
||||
|
||||
export class TypedReflect {
|
||||
|
Loading…
Reference in New Issue
Block a user