Deprecate address standard field (#6087)
Closes #5916 --------- Co-authored-by: Weiko <corentin@twenty.com>
This commit is contained in:
@ -1,15 +1,15 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
|
||||
import { MessageQueue } from 'src/engine/integrations/message-queue/message-queue.constants';
|
||||
import { MessageQueueService } from 'src/engine/integrations/message-queue/services/message-queue.service';
|
||||
import { ObjectRecordCreateEvent } from 'src/engine/integrations/event-emitter/types/object-record-create.event';
|
||||
import { objectRecordChangedValues } from 'src/engine/integrations/event-emitter/utils/object-record-changed-values';
|
||||
import { ObjectRecordUpdateEvent } from 'src/engine/integrations/event-emitter/types/object-record-update.event';
|
||||
import { ObjectRecordBaseEvent } from 'src/engine/integrations/event-emitter/types/object-record.base.event';
|
||||
import { UpsertTimelineActivityFromInternalEvent } from 'src/modules/timeline/jobs/upsert-timeline-activity-from-internal-event.job';
|
||||
import { objectRecordChangedValues } from 'src/engine/integrations/event-emitter/utils/object-record-changed-values';
|
||||
import { InjectMessageQueue } from 'src/engine/integrations/message-queue/decorators/message-queue.decorator';
|
||||
import { MessageQueue } from 'src/engine/integrations/message-queue/message-queue.constants';
|
||||
import { MessageQueueService } from 'src/engine/integrations/message-queue/services/message-queue.service';
|
||||
import { CreateAuditLogFromInternalEvent } from 'src/modules/timeline/jobs/create-audit-log-from-internal-event';
|
||||
import { UpsertTimelineActivityFromInternalEvent } from 'src/modules/timeline/jobs/upsert-timeline-activity-from-internal-event.job';
|
||||
|
||||
@Injectable()
|
||||
export class EntityEventsToDbListener {
|
||||
|
||||
@ -46,6 +46,13 @@ export function WorkspaceField<T extends FieldMetadataType>(
|
||||
object,
|
||||
propertyKey.toString(),
|
||||
);
|
||||
const isDeprecated =
|
||||
TypedReflect.getMetadata(
|
||||
'workspace:is-deprecated-field-metadata-args',
|
||||
object,
|
||||
propertyKey.toString(),
|
||||
) ?? false;
|
||||
|
||||
const defaultValue = (options.defaultValue ??
|
||||
generateDefaultValue(
|
||||
options.type,
|
||||
@ -65,6 +72,7 @@ export function WorkspaceField<T extends FieldMetadataType>(
|
||||
isNullable,
|
||||
isSystem,
|
||||
gate,
|
||||
isDeprecated,
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
@ -0,0 +1,12 @@
|
||||
import { TypedReflect } from 'src/utils/typed-reflect';
|
||||
|
||||
export function WorkspaceIsDeprecated(): PropertyDecorator {
|
||||
return (object, propertyKey) => {
|
||||
TypedReflect.defineMetadata(
|
||||
'workspace:is-deprecated-field-metadata-args',
|
||||
true,
|
||||
object,
|
||||
propertyKey.toString(),
|
||||
);
|
||||
};
|
||||
}
|
||||
@ -73,4 +73,9 @@ export interface WorkspaceFieldMetadataArgs {
|
||||
* Field gate.
|
||||
*/
|
||||
readonly gate?: Gate;
|
||||
|
||||
/**
|
||||
* Is deprecated field.
|
||||
*/
|
||||
readonly isDeprecated?: boolean;
|
||||
}
|
||||
|
||||
@ -10,7 +10,12 @@ export const companyPrefillData = async (
|
||||
.into(`${schemaName}.company`, [
|
||||
'name',
|
||||
'domainName',
|
||||
'address',
|
||||
'addressAddressStreet1',
|
||||
'addressAddressStreet2',
|
||||
'addressAddressCity',
|
||||
'addressAddressState',
|
||||
'addressAddressPostcode',
|
||||
'addressAddressCountry',
|
||||
'employees',
|
||||
'position',
|
||||
])
|
||||
@ -19,35 +24,60 @@ export const companyPrefillData = async (
|
||||
{
|
||||
name: 'Airbnb',
|
||||
domainName: 'airbnb.com',
|
||||
address: 'San Francisco',
|
||||
addressAddressStreet1: '888 Brannan St',
|
||||
addressAddressStreet2: null,
|
||||
addressAddressCity: 'San Francisco',
|
||||
addressAddressState: 'CA',
|
||||
addressAddressPostcode: '94103',
|
||||
addressAddressCountry: 'United States',
|
||||
employees: 5000,
|
||||
position: 1,
|
||||
},
|
||||
{
|
||||
name: 'Qonto',
|
||||
domainName: 'qonto.com',
|
||||
address: 'San Francisco',
|
||||
addressAddressStreet1: '18 rue de navarrin',
|
||||
addressAddressStreet2: null,
|
||||
addressAddressCity: 'Paris',
|
||||
addressAddressState: null,
|
||||
addressAddressPostcode: '75009',
|
||||
addressAddressCountry: 'France',
|
||||
employees: 800,
|
||||
position: 2,
|
||||
},
|
||||
{
|
||||
name: 'Stripe',
|
||||
domainName: 'stripe.com',
|
||||
address: 'San Francisco',
|
||||
addressAddressStreet1: 'Eutaw Street',
|
||||
addressAddressStreet2: null,
|
||||
addressAddressCity: 'Dublin',
|
||||
addressAddressState: null,
|
||||
addressAddressPostcode: null,
|
||||
addressAddressCountry: 'Ireland',
|
||||
employees: 8000,
|
||||
position: 3,
|
||||
},
|
||||
{
|
||||
name: 'Figma',
|
||||
domainName: 'figma.com',
|
||||
address: 'San Francisco',
|
||||
addressAddressStreet1: '760 Market St',
|
||||
addressAddressStreet2: 'Floor 10',
|
||||
addressAddressCity: 'San Francisco',
|
||||
addressAddressState: null,
|
||||
addressAddressPostcode: '94102',
|
||||
addressAddressCountry: 'United States',
|
||||
employees: 800,
|
||||
position: 4,
|
||||
},
|
||||
{
|
||||
name: 'Notion',
|
||||
domainName: 'notion.com',
|
||||
address: 'San Francisco',
|
||||
addressAddressStreet1: '2300 Harrison St',
|
||||
addressAddressStreet2: null,
|
||||
addressAddressCity: 'San Francisco',
|
||||
addressAddressState: 'CA',
|
||||
addressAddressPostcode: '94110',
|
||||
addressAddressCountry: 'United States',
|
||||
employees: 400,
|
||||
position: 5,
|
||||
},
|
||||
|
||||
@ -8,11 +8,11 @@ import {
|
||||
} from 'src/engine/workspace-manager/workspace-sync-metadata/interfaces/comparator.interface';
|
||||
import { ComputedPartialFieldMetadata } from 'src/engine/workspace-manager/workspace-sync-metadata/interfaces/partial-field-metadata.interface';
|
||||
|
||||
import { transformMetadataForComparison } from 'src/engine/workspace-manager/workspace-sync-metadata/comparators/utils/transform-metadata-for-comparison.util';
|
||||
import {
|
||||
FieldMetadataEntity,
|
||||
FieldMetadataType,
|
||||
} from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
|
||||
import { transformMetadataForComparison } from 'src/engine/workspace-manager/workspace-sync-metadata/comparators/utils/transform-metadata-for-comparison.util';
|
||||
|
||||
const commonFieldPropertiesToIgnore = [
|
||||
'id',
|
||||
@ -28,6 +28,12 @@ const commonFieldPropertiesToIgnore = [
|
||||
|
||||
const fieldPropertiesToStringify = ['defaultValue'] as const;
|
||||
|
||||
const shouldSkipFieldCreation = (
|
||||
standardFieldMetadata: ComputedPartialFieldMetadata | undefined,
|
||||
) => {
|
||||
return standardFieldMetadata?.isCustom;
|
||||
};
|
||||
|
||||
@Injectable()
|
||||
export class WorkspaceFieldComparator {
|
||||
constructor() {}
|
||||
@ -108,10 +114,6 @@ export class WorkspaceFieldComparator {
|
||||
const findField = (
|
||||
field: ComputedPartialFieldMetadata | FieldMetadataEntity,
|
||||
) => {
|
||||
if (field.isCustom) {
|
||||
return field.name === fieldName;
|
||||
}
|
||||
|
||||
return field.standardId === fieldName;
|
||||
};
|
||||
// Object shouldn't have thousands of fields, so we can use find here
|
||||
@ -122,6 +124,9 @@ export class WorkspaceFieldComparator {
|
||||
|
||||
switch (difference.type) {
|
||||
case 'CREATE': {
|
||||
if (shouldSkipFieldCreation(standardFieldMetadata)) {
|
||||
break;
|
||||
}
|
||||
if (!standardFieldMetadata) {
|
||||
throw new Error(
|
||||
`Field ${fieldName} not found in standardObjectMetadata`,
|
||||
|
||||
@ -114,7 +114,8 @@ export const COMMENT_STANDARD_FIELD_IDS = {
|
||||
export const COMPANY_STANDARD_FIELD_IDS = {
|
||||
name: '20202020-4d99-4e2e-a84c-4a27837b1ece',
|
||||
domainName: '20202020-0c28-43d8-8ba5-3659924d3489',
|
||||
address: '20202020-a82a-4ee2-96cc-a18a3259d953',
|
||||
address_deprecated: '20202020-a82a-4ee2-96cc-a18a3259d953',
|
||||
address: '20202020-c5ce-4adc-b7b6-9c0979fc55e7',
|
||||
employees: '20202020-8965-464a-8a75-74bafc152a0b',
|
||||
linkedinLink: '20202020-ebeb-4beb-b9ad-6848036fb451',
|
||||
xLink: '20202020-6f64-4fd9-9580-9c1991c7d8c3',
|
||||
|
||||
@ -162,7 +162,7 @@ export class StandardFieldFactory {
|
||||
options: workspaceFieldMetadataArgs.options,
|
||||
workspaceId: context.workspaceId,
|
||||
isNullable: workspaceFieldMetadataArgs.isNullable,
|
||||
isCustom: false,
|
||||
isCustom: workspaceFieldMetadataArgs.isDeprecated ? true : false,
|
||||
isSystem:
|
||||
workspaceEntityMetadataArgs?.isSystem ||
|
||||
workspaceFieldMetadataArgs.isSystem,
|
||||
|
||||
@ -125,16 +125,6 @@ export class WorkspaceMetadataUpdaterService {
|
||||
updatedFieldMetadataCollection: FieldMetadataUpdate[];
|
||||
}> {
|
||||
const fieldMetadataRepository = manager.getRepository(FieldMetadataEntity);
|
||||
|
||||
/**
|
||||
* Create field metadata
|
||||
*/
|
||||
const createdFieldMetadataCollection = await fieldMetadataRepository.save(
|
||||
storage.fieldMetadataCreateCollection.map((field) =>
|
||||
this.prepareFieldMetadataForCreation(field),
|
||||
) as DeepPartial<FieldMetadataEntity>[],
|
||||
);
|
||||
|
||||
/**
|
||||
* Update field metadata
|
||||
*/
|
||||
@ -145,6 +135,15 @@ export class WorkspaceMetadataUpdaterService {
|
||||
'workspaceId',
|
||||
]);
|
||||
|
||||
/**
|
||||
* Create field metadata
|
||||
*/
|
||||
const createdFieldMetadataCollection = await fieldMetadataRepository.save(
|
||||
storage.fieldMetadataCreateCollection.map((field) =>
|
||||
this.prepareFieldMetadataForCreation(field),
|
||||
) as DeepPartial<FieldMetadataEntity>[],
|
||||
);
|
||||
|
||||
/**
|
||||
* Delete field metadata
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user