Skip to content

Commit

Permalink
Use Constants instead of raw ids
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesBochet committed Mar 21, 2024
1 parent 6f94292 commit 9042f66
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 57 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { EntityManager } from 'typeorm';

export const pipelineStepPrefillData = async (
entityManager: EntityManager,
schemaName: string,
) => {
await entityManager
.createQueryBuilder()
.insert()
.into(`${schemaName}.pipelineStep`, ['name', 'color', 'position'])
.orIgnore()
.values([
{
name: 'NEW',
color: 'red',
position: 0,
},
{
name: 'SCREENING',
color: 'purple',
position: 1,
},
{
name: 'MEETING',
color: 'sky',
position: 2,
},
{
name: 'PROPOSAL',
color: 'turquoise',
position: 3,
},
{
name: 'CUSTOMER',
color: 'yellow',
position: 4,
},
])
.returning('*')
.execute();
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ export const standardObjectsPrefillData = async (
objectMetadata: ObjectMetadataEntity[],
) => {
const objectMetadataMap = objectMetadata.reduce((acc, object) => {
acc[object.nameSingular] = {
acc[object.standardId ?? ''] = {
id: object.id,
fields: object.fields.reduce((acc, field) => {
acc[field.name] = field.id;
acc[field.standardId ?? ''] = field.id;

return acc;
}, {}),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
import {
baseObjectStandardFieldIds,
companyStandardFieldIds,
} from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids';
import { standardObjectIds } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-ids';

export const viewCompanyFields = (
viewId: string,
Expand All @@ -7,8 +12,8 @@ export const viewCompanyFields = (
return [
{
fieldMetadataId:
objectMetadataMap['20202020-b374-4779-a561-80086cb2e17f'].fields[
'20202020-4d99-4e2e-a84c-4a27837b1ece'
objectMetadataMap[standardObjectIds.company].fields[
companyStandardFieldIds.name
],
viewId: viewId,
position: 0,
Expand All @@ -17,8 +22,8 @@ export const viewCompanyFields = (
},
{
fieldMetadataId:
objectMetadataMap['20202020-b374-4779-a561-80086cb2e17f'].fields[
'20202020-0c28-43d8-8ba5-3659924d3489'
objectMetadataMap[standardObjectIds.company].fields[
companyStandardFieldIds.domainName
],
viewId: viewId,
position: 1,
Expand All @@ -27,8 +32,8 @@ export const viewCompanyFields = (
},
{
fieldMetadataId:
objectMetadataMap['20202020-b374-4779-a561-80086cb2e17f'].fields[
'20202020-95b8-4e10-9881-edb5d4765f9d'
objectMetadataMap[standardObjectIds.company].fields[
companyStandardFieldIds.accountOwner
],
viewId: viewId,
position: 2,
Expand All @@ -37,8 +42,8 @@ export const viewCompanyFields = (
},
{
fieldMetadataId:
objectMetadataMap['20202020-b374-4779-a561-80086cb2e17f'].fields[
'20202020-66ac-4502-9975-e4d959c50311'
objectMetadataMap[standardObjectIds.company].fields[
baseObjectStandardFieldIds.createdAt
],
viewId: viewId,
position: 3,
Expand All @@ -47,8 +52,8 @@ export const viewCompanyFields = (
},
{
fieldMetadataId:
objectMetadataMap['20202020-b374-4779-a561-80086cb2e17f'].fields[
'20202020-8965-464a-8a75-74bafc152a0b'
objectMetadataMap[standardObjectIds.company].fields[
companyStandardFieldIds.employees
],
viewId: viewId,
position: 4,
Expand All @@ -57,8 +62,8 @@ export const viewCompanyFields = (
},
{
fieldMetadataId:
objectMetadataMap['20202020-b374-4779-a561-80086cb2e17f'].fields[
'20202020-ebeb-4beb-b9ad-6848036fb451'
objectMetadataMap[standardObjectIds.company].fields[
companyStandardFieldIds.linkedinLink
],
viewId: viewId,
position: 5,
Expand All @@ -67,8 +72,8 @@ export const viewCompanyFields = (
},
{
fieldMetadataId:
objectMetadataMap['20202020-b374-4779-a561-80086cb2e17f'].fields[
'20202020-a82a-4ee2-96cc-a18a3259d953'
objectMetadataMap[standardObjectIds.company].fields[
companyStandardFieldIds.address
],
viewId: viewId,
position: 6,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
import { opportunityStandardFieldIds } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids';
import { standardObjectIds } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-ids';

export const viewOpportunityFields = (
viewId: string,
Expand All @@ -7,8 +9,8 @@ export const viewOpportunityFields = (
return [
{
fieldMetadataId:
objectMetadataMap['20202020-9549-49dd-b2b2-883999db8938'].fields[
'20202020-8609-4f65-a2d9-44009eb422b5'
objectMetadataMap[standardObjectIds.opportunity].fields[
opportunityStandardFieldIds.name
],
viewId: viewId,
position: 0,
Expand All @@ -17,8 +19,8 @@ export const viewOpportunityFields = (
},
{
fieldMetadataId:
objectMetadataMap['20202020-9549-49dd-b2b2-883999db8938'].fields[
'20202020-583e-4642-8533-db761d5fa82f'
objectMetadataMap[standardObjectIds.opportunity].fields[
opportunityStandardFieldIds.amount
],
viewId: viewId,
position: 1,
Expand All @@ -27,8 +29,8 @@ export const viewOpportunityFields = (
},
{
fieldMetadataId:
objectMetadataMap['20202020-9549-49dd-b2b2-883999db8938'].fields[
'20202020-527e-44d6-b1ac-c4158d307b97'
objectMetadataMap[standardObjectIds.opportunity].fields[
opportunityStandardFieldIds.closeDate
],
viewId: viewId,
position: 2,
Expand All @@ -37,8 +39,8 @@ export const viewOpportunityFields = (
},
{
fieldMetadataId:
objectMetadataMap['20202020-9549-49dd-b2b2-883999db8938'].fields[
'20202020-69d4-45f3-9703-690b09fafcf0'
objectMetadataMap[standardObjectIds.opportunity].fields[
opportunityStandardFieldIds.probability
],
viewId: viewId,
position: 3,
Expand All @@ -47,8 +49,8 @@ export const viewOpportunityFields = (
},
{
fieldMetadataId:
objectMetadataMap['20202020-9549-49dd-b2b2-883999db8938'].fields[
'20202020-8dfb-42fc-92b6-01afb759ed16'
objectMetadataMap[standardObjectIds.opportunity].fields[
opportunityStandardFieldIds.pointOfContact
],
viewId: viewId,
position: 4,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
import {
baseObjectStandardFieldIds,
personStandardFieldIds,
} from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids';
import { standardObjectIds } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-ids';

export const viewPersonFields = (
viewId: string,
Expand All @@ -7,8 +12,8 @@ export const viewPersonFields = (
return [
{
fieldMetadataId:
objectMetadataMap['20202020-e674-48e5-a542-72570eee7213'].fields[
'20202020-3875-44d5-8c33-a6239011cab8'
objectMetadataMap[standardObjectIds.person].fields[
personStandardFieldIds.name
],
viewId: viewId,
position: 0,
Expand All @@ -17,8 +22,8 @@ export const viewPersonFields = (
},
{
fieldMetadataId:
objectMetadataMap['20202020-e674-48e5-a542-72570eee7213'].fields[
'20202020-a740-42bb-8849-8980fb3f12e1'
objectMetadataMap[standardObjectIds.person].fields[
personStandardFieldIds.email
],
viewId: viewId,
position: 1,
Expand All @@ -27,8 +32,8 @@ export const viewPersonFields = (
},
{
fieldMetadataId:
objectMetadataMap['20202020-e674-48e5-a542-72570eee7213'].fields[
'20202020-e2f3-448e-b34c-2d625f0025fd'
objectMetadataMap[standardObjectIds.person].fields[
personStandardFieldIds.company
],
viewId: viewId,
position: 2,
Expand All @@ -37,8 +42,8 @@ export const viewPersonFields = (
},
{
fieldMetadataId:
objectMetadataMap['20202020-e674-48e5-a542-72570eee7213'].fields[
'20202020-4564-4b8b-a09f-05445f2e0bce'
objectMetadataMap[standardObjectIds.person].fields[
personStandardFieldIds.phone
],
viewId: viewId,
position: 3,
Expand All @@ -47,8 +52,8 @@ export const viewPersonFields = (
},
{
fieldMetadataId:
objectMetadataMap['20202020-e674-48e5-a542-72570eee7213'].fields[
'20202020-66ac-4502-9975-e4d959c50311'
objectMetadataMap[standardObjectIds.person].fields[
baseObjectStandardFieldIds.createdAt
],
viewId: viewId,
position: 4,
Expand All @@ -57,8 +62,8 @@ export const viewPersonFields = (
},
{
fieldMetadataId:
objectMetadataMap['20202020-e674-48e5-a542-72570eee7213'].fields[
'20202020-5243-4ffb-afc5-2c675da41346'
objectMetadataMap[standardObjectIds.person].fields[
personStandardFieldIds.city
],
viewId: viewId,
position: 5,
Expand All @@ -67,8 +72,8 @@ export const viewPersonFields = (
},
{
fieldMetadataId:
objectMetadataMap['20202020-e674-48e5-a542-72570eee7213'].fields[
'20202020-b0d0-415a-bef9-640a26dacd9b'
objectMetadataMap[standardObjectIds.person].fields[
personStandardFieldIds.jobTitle
],
viewId: viewId,
position: 6,
Expand All @@ -77,8 +82,8 @@ export const viewPersonFields = (
},
{
fieldMetadataId:
objectMetadataMap['20202020-e674-48e5-a542-72570eee7213'].fields[
'20202020-f1af-48f7-893b-2007a73dd508'
objectMetadataMap[standardObjectIds.person].fields[
personStandardFieldIds.linkedinLink
],
viewId: viewId,
position: 7,
Expand All @@ -87,8 +92,8 @@ export const viewPersonFields = (
},
{
fieldMetadataId:
objectMetadataMap['20202020-e674-48e5-a542-72570eee7213'].fields[
'20202020-8fc2-487c-b84a-55a99b145cfd'
objectMetadataMap[standardObjectIds.person].fields[
personStandardFieldIds.xLink
],
viewId: viewId,
position: 8,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadat
import { viewCompanyFields } from 'src/engine/workspace-manager/standard-objects-prefill-data/view-company-fields';
import { viewPersonFields } from 'src/engine/workspace-manager/standard-objects-prefill-data/view-person-fields';
import { viewOpportunityFields } from 'src/engine/workspace-manager/standard-objects-prefill-data/view-opportunity-fields';
import { standardObjectIds } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-ids';

export const viewPrefillData = async (
entityManager: EntityManager,
Expand All @@ -25,8 +26,7 @@ export const viewPrefillData = async (
.values([
{
name: 'Index Companies',
objectMetadataId:
objectMetadataMap['20202020-b374-4779-a561-80086cb2e17f'].id,
objectMetadataId: objectMetadataMap[standardObjectIds.company].id,
type: 'table',
key: 'INDEX',
position: 0,
Expand All @@ -35,8 +35,7 @@ export const viewPrefillData = async (
},
{
name: 'All Companies',
objectMetadataId:
objectMetadataMap['20202020-b374-4779-a561-80086cb2e17f'].id,
objectMetadataId: objectMetadataMap[standardObjectIds.company].id,
type: 'table',
key: null,
position: 1,
Expand All @@ -45,8 +44,7 @@ export const viewPrefillData = async (
},
{
name: 'Index People',
objectMetadataId:
objectMetadataMap['20202020-e674-48e5-a542-72570eee7213'].id,
objectMetadataId: objectMetadataMap[standardObjectIds.person].id,
type: 'table',
key: 'INDEX',
position: 0,
Expand All @@ -55,8 +53,7 @@ export const viewPrefillData = async (
},
{
name: 'All People',
objectMetadataId:
objectMetadataMap['20202020-e674-48e5-a542-72570eee7213'].id,
objectMetadataId: objectMetadataMap[standardObjectIds.person].id,
type: 'table',
key: null,
position: 1,
Expand All @@ -65,8 +62,7 @@ export const viewPrefillData = async (
},
{
name: 'Index Opportunities',
objectMetadataId:
objectMetadataMap['20202020-9549-49dd-b2b2-883999db8938'].id,
objectMetadataId: objectMetadataMap[standardObjectIds.opportunity].id,
type: 'table',
key: 'INDEX',
position: 0,
Expand All @@ -75,14 +71,13 @@ export const viewPrefillData = async (
},
{
name: 'By Stage',
objectMetadataId:
objectMetadataMap['20202020-9549-49dd-b2b2-883999db8938'].id,
objectMetadataId: objectMetadataMap[standardObjectIds.opportunity].id,
type: 'kanban',
key: null,
position: 1,
icon: 'IconLayoutKanban',
kanbanFieldMetadataId:
objectMetadataMap['20202020-9549-49dd-b2b2-883999db8938'].fields[
objectMetadataMap[standardObjectIds.opportunity].fields[
'20202020-d09b-4f65-ac42-06a2f20ba0e8'
],
},
Expand Down

0 comments on commit 9042f66

Please sign in to comment.