Add KanbanFieldMetadataId on View standard object (#4604)
* Add KanbanFieldMetadataId on View standard object * Deprecate Pipeline step * Fix * Use Constants instead of raw ids * Fix * Fix query runner * Fix according to review * Fix tests * Fix tests * Fix tests
This commit is contained in:
@ -1,12 +1,10 @@
|
||||
import { Command, CommandRunner } from 'nest-commander';
|
||||
import { DataSource } from 'typeorm';
|
||||
import { DataSource, EntityManager } from 'typeorm';
|
||||
|
||||
import { DataSourceService } from 'src/engine/metadata-modules/data-source/data-source.service';
|
||||
import { seedCompanies } from 'src/database/typeorm-seeds/workspace/companies';
|
||||
import { seedViews } from 'src/database/typeorm-seeds/workspace/views';
|
||||
import { TypeORMService } from 'src/database/typeorm/typeorm.service';
|
||||
import { seedOpportunity } from 'src/database/typeorm-seeds/workspace/opportunity';
|
||||
import { seedPipelineStep } from 'src/database/typeorm-seeds/workspace/pipeline-step';
|
||||
import { seedWorkspaceMember } from 'src/database/typeorm-seeds/workspace/workspaceMember';
|
||||
import { seedPeople } from 'src/database/typeorm-seeds/workspace/people';
|
||||
import { seedCoreSchema } from 'src/database/typeorm-seeds/core';
|
||||
@ -19,6 +17,7 @@ import {
|
||||
SeedAppleWorkspaceId,
|
||||
SeedTwentyWorkspaceId,
|
||||
} from 'src/database/typeorm-seeds/core/workspaces';
|
||||
import { viewPrefillData } from 'src/engine/workspace-manager/standard-objects-prefill-data/view';
|
||||
|
||||
// TODO: implement dry-run
|
||||
@Command({
|
||||
@ -95,10 +94,10 @@ export class DataSeedWorkspaceCommand extends CommandRunner {
|
||||
const objectMetadata =
|
||||
await this.objectMetadataService.findManyWithinWorkspace(workspaceId);
|
||||
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;
|
||||
}, {}),
|
||||
@ -107,24 +106,24 @@ export class DataSeedWorkspaceCommand extends CommandRunner {
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
await seedCompanies(workspaceDataSource, dataSourceMetadata.schema);
|
||||
await seedPeople(workspaceDataSource, dataSourceMetadata.schema);
|
||||
await seedPipelineStep(workspaceDataSource, dataSourceMetadata.schema);
|
||||
await seedOpportunity(workspaceDataSource, dataSourceMetadata.schema);
|
||||
await seedCalendarEvents(
|
||||
workspaceDataSource,
|
||||
dataSourceMetadata.schema,
|
||||
);
|
||||
await workspaceDataSource.transaction(
|
||||
async (entityManager: EntityManager) => {
|
||||
await seedCompanies(entityManager, dataSourceMetadata.schema);
|
||||
await seedPeople(entityManager, dataSourceMetadata.schema);
|
||||
await seedOpportunity(entityManager, dataSourceMetadata.schema);
|
||||
await seedCalendarEvents(entityManager, dataSourceMetadata.schema);
|
||||
await seedWorkspaceMember(
|
||||
entityManager,
|
||||
dataSourceMetadata.schema,
|
||||
workspaceId,
|
||||
);
|
||||
|
||||
await seedViews(
|
||||
workspaceDataSource,
|
||||
dataSourceMetadata.schema,
|
||||
objectMetadataMap,
|
||||
);
|
||||
await seedWorkspaceMember(
|
||||
workspaceDataSource,
|
||||
dataSourceMetadata.schema,
|
||||
workspaceId,
|
||||
await viewPrefillData(
|
||||
entityManager,
|
||||
dataSourceMetadata.schema,
|
||||
objectMetadataMap,
|
||||
);
|
||||
},
|
||||
);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
import { DataSource } from 'typeorm';
|
||||
import { EntityManager } from 'typeorm';
|
||||
|
||||
const tableName = 'calendarEvent';
|
||||
|
||||
export const seedCalendarEvents = async (
|
||||
workspaceDataSource: DataSource,
|
||||
entityManager: EntityManager,
|
||||
schemaName: string,
|
||||
) => {
|
||||
await workspaceDataSource
|
||||
await entityManager
|
||||
.createQueryBuilder()
|
||||
.insert()
|
||||
.into(`${schemaName}.${tableName}`, [
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
import { DataSource } from 'typeorm';
|
||||
import { EntityManager } from 'typeorm';
|
||||
|
||||
const tableName = 'company';
|
||||
|
||||
export const seedCompanies = async (
|
||||
workspaceDataSource: DataSource,
|
||||
entityManager: EntityManager,
|
||||
schemaName: string,
|
||||
) => {
|
||||
await workspaceDataSource
|
||||
await entityManager
|
||||
.createQueryBuilder()
|
||||
.insert()
|
||||
.into(`${schemaName}.${tableName}`, [
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
import { DataSource } from 'typeorm';
|
||||
import { EntityManager } from 'typeorm';
|
||||
|
||||
const tableName = 'opportunity';
|
||||
|
||||
export const seedOpportunity = async (
|
||||
workspaceDataSource: DataSource,
|
||||
entityManager: EntityManager,
|
||||
schemaName: string,
|
||||
) => {
|
||||
await workspaceDataSource
|
||||
await entityManager
|
||||
.createQueryBuilder()
|
||||
.insert()
|
||||
.into(`${schemaName}.${tableName}`, [
|
||||
@ -18,7 +18,6 @@ export const seedOpportunity = async (
|
||||
'probability',
|
||||
'stage',
|
||||
'position',
|
||||
'pipelineStepId',
|
||||
'pointOfContactId',
|
||||
'companyId',
|
||||
])
|
||||
@ -33,7 +32,6 @@ export const seedOpportunity = async (
|
||||
probability: 0.5,
|
||||
stage: 'NEW',
|
||||
position: 1,
|
||||
pipelineStepId: '6edf4ead-006a-46e1-9c6d-228f1d0143c9',
|
||||
pointOfContactId: '86083141-1c0e-494c-a1b6-85b1c6fefaa5',
|
||||
companyId: 'fe256b39-3ec3-4fe3-8997-b76aa0bfa408',
|
||||
},
|
||||
@ -46,7 +44,6 @@ export const seedOpportunity = async (
|
||||
probability: 0.5,
|
||||
stage: 'MEETING',
|
||||
position: 2,
|
||||
pipelineStepId: 'd8361722-03fb-4e65-bd4f-ec9e52e5ec0a',
|
||||
pointOfContactId: '93c72d2e-f517-42fd-80ae-14173b3b70ae',
|
||||
companyId: '118995f3-5d81-46d6-bf83-f7fd33ea6102',
|
||||
},
|
||||
@ -59,7 +56,6 @@ export const seedOpportunity = async (
|
||||
probability: 0.5,
|
||||
stage: 'PROPOSAL',
|
||||
position: 3,
|
||||
pipelineStepId: '30b14887-d592-427d-bd97-6e670158db02',
|
||||
pointOfContactId: '9b324a88-6784-4449-afdf-dc62cb8702f2',
|
||||
companyId: '460b6fb1-ed89-413a-b31a-962986e67bb4',
|
||||
},
|
||||
@ -72,7 +68,6 @@ export const seedOpportunity = async (
|
||||
probability: 0.5,
|
||||
stage: 'PROPOSAL',
|
||||
position: 4,
|
||||
pipelineStepId: '30b14887-d592-427d-bd97-6e670158db02',
|
||||
pointOfContactId: '98406e26-80f1-4dff-b570-a74942528de3',
|
||||
companyId: '460b6fb1-ed89-413a-b31a-962986e67bb4',
|
||||
},
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
import { DataSource } from 'typeorm';
|
||||
import { EntityManager } from 'typeorm';
|
||||
|
||||
const tableName = 'person';
|
||||
|
||||
export const seedPeople = async (
|
||||
workspaceDataSource: DataSource,
|
||||
entityManager: EntityManager,
|
||||
schemaName: string,
|
||||
) => {
|
||||
await workspaceDataSource
|
||||
await entityManager
|
||||
.createQueryBuilder()
|
||||
.insert()
|
||||
.into(`${schemaName}.${tableName}`, [
|
||||
|
||||
@ -1,47 +0,0 @@
|
||||
import { DataSource } from 'typeorm';
|
||||
|
||||
const tableName = 'pipelineStep';
|
||||
|
||||
export const seedPipelineStep = async (
|
||||
workspaceDataSource: DataSource,
|
||||
schemaName: string,
|
||||
) => {
|
||||
await workspaceDataSource
|
||||
.createQueryBuilder()
|
||||
.insert()
|
||||
.into(`${schemaName}.${tableName}`, ['id', 'name', 'color', 'position'])
|
||||
.orIgnore()
|
||||
.values([
|
||||
{
|
||||
id: '6edf4ead-006a-46e1-9c6d-228f1d0143c9',
|
||||
name: 'NEW',
|
||||
color: 'red',
|
||||
position: 0,
|
||||
},
|
||||
{
|
||||
id: 'd8361722-03fb-4e65-bd4f-ec9e52e5ec0a',
|
||||
name: 'SCREENING',
|
||||
color: 'purple',
|
||||
position: 1,
|
||||
},
|
||||
{
|
||||
id: '30b14887-d592-427d-bd97-6e670158db02',
|
||||
name: 'MEETING',
|
||||
color: 'sky',
|
||||
position: 2,
|
||||
},
|
||||
{
|
||||
id: 'db5a6648-d80d-4020-af64-4817ab4a12e8',
|
||||
name: 'PROPOSAL',
|
||||
color: 'turquoise',
|
||||
position: 3,
|
||||
},
|
||||
{
|
||||
id: 'bea8bb7b-5467-48a6-9a8a-a8fa500123fe',
|
||||
name: 'CUSTOMER',
|
||||
color: 'yellow',
|
||||
position: 4,
|
||||
},
|
||||
])
|
||||
.execute();
|
||||
};
|
||||
@ -1,263 +0,0 @@
|
||||
import { DataSource } from 'typeorm';
|
||||
|
||||
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
|
||||
|
||||
export const seedViews = async (
|
||||
workspaceDataSource: DataSource,
|
||||
schemaName: string,
|
||||
objectMetadataMap: Record<string, ObjectMetadataEntity>,
|
||||
) => {
|
||||
const createdViews = await workspaceDataSource
|
||||
.createQueryBuilder()
|
||||
.insert()
|
||||
.into(`${schemaName}.view`, [
|
||||
'name',
|
||||
'objectMetadataId',
|
||||
'type',
|
||||
'key',
|
||||
'position',
|
||||
'icon',
|
||||
])
|
||||
.values([
|
||||
{
|
||||
name: 'All Companies',
|
||||
objectMetadataId: objectMetadataMap['company'].id,
|
||||
type: 'table',
|
||||
key: 'INDEX',
|
||||
position: 0,
|
||||
icon: 'IconBuildingSkyscraper',
|
||||
},
|
||||
{
|
||||
name: 'All People',
|
||||
objectMetadataId: objectMetadataMap['person'].id,
|
||||
type: 'table',
|
||||
key: 'INDEX',
|
||||
position: 0,
|
||||
icon: 'IconUser',
|
||||
},
|
||||
{
|
||||
name: 'By Stage',
|
||||
objectMetadataId: objectMetadataMap['opportunity'].id,
|
||||
type: 'kanban',
|
||||
key: null,
|
||||
position: 0,
|
||||
icon: 'IconLayoutKanban',
|
||||
},
|
||||
{
|
||||
name: 'All Opportunities',
|
||||
objectMetadataId: objectMetadataMap['opportunity'].id,
|
||||
type: 'table',
|
||||
key: 'INDEX',
|
||||
position: 1,
|
||||
icon: 'IconTargetArrow',
|
||||
},
|
||||
])
|
||||
.returning('*')
|
||||
.execute();
|
||||
|
||||
const viewIdMap = createdViews.raw.reduce((acc, view) => {
|
||||
acc[`${view.name}`] = view.id;
|
||||
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
await workspaceDataSource
|
||||
.createQueryBuilder()
|
||||
.insert()
|
||||
.into(`${schemaName}.viewField`, [
|
||||
'fieldMetadataId',
|
||||
'viewId',
|
||||
'position',
|
||||
'isVisible',
|
||||
'size',
|
||||
])
|
||||
.values([
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['company'].fields['name'],
|
||||
viewId: viewIdMap['All Companies'],
|
||||
position: 0,
|
||||
isVisible: true,
|
||||
size: 180,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['company'].fields['domainName'],
|
||||
viewId: viewIdMap['All Companies'],
|
||||
position: 1,
|
||||
isVisible: true,
|
||||
size: 100,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['company'].fields['accountOwner'],
|
||||
viewId: viewIdMap['All Companies'],
|
||||
position: 2,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['company'].fields['createdAt'],
|
||||
viewId: viewIdMap['All Companies'],
|
||||
position: 3,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['company'].fields['employees'],
|
||||
viewId: viewIdMap['All Companies'],
|
||||
position: 4,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['company'].fields['linkedinLink'],
|
||||
viewId: viewIdMap['All Companies'],
|
||||
position: 5,
|
||||
isVisible: true,
|
||||
size: 170,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['company'].fields['address'],
|
||||
viewId: viewIdMap['All Companies'],
|
||||
position: 6,
|
||||
isVisible: true,
|
||||
size: 170,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['person'].fields['name'],
|
||||
viewId: viewIdMap['All People'],
|
||||
position: 0,
|
||||
isVisible: true,
|
||||
size: 210,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['person'].fields['email'],
|
||||
viewId: viewIdMap['All People'],
|
||||
position: 1,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['person'].fields['company'],
|
||||
viewId: viewIdMap['All People'],
|
||||
position: 2,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['person'].fields['phone'],
|
||||
viewId: viewIdMap['All People'],
|
||||
position: 3,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['person'].fields['createdAt'],
|
||||
viewId: viewIdMap['All People'],
|
||||
position: 4,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['person'].fields['city'],
|
||||
viewId: viewIdMap['All People'],
|
||||
position: 5,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['person'].fields['jobTitle'],
|
||||
viewId: viewIdMap['All People'],
|
||||
position: 6,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['person'].fields['linkedinLink'],
|
||||
viewId: viewIdMap['All People'],
|
||||
position: 7,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['person'].fields['xLink'],
|
||||
viewId: viewIdMap['All People'],
|
||||
position: 8,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['opportunity'].fields['name'],
|
||||
viewId: viewIdMap['All Opportunities'],
|
||||
position: 0,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['opportunity'].fields['amount'],
|
||||
viewId: viewIdMap['All Opportunities'],
|
||||
position: 1,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['opportunity'].fields['closeDate'],
|
||||
viewId: viewIdMap['All Opportunities'],
|
||||
position: 2,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['opportunity'].fields['probability'],
|
||||
viewId: viewIdMap['All Opportunities'],
|
||||
position: 3,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId:
|
||||
objectMetadataMap['opportunity'].fields['pointOfContact'],
|
||||
viewId: viewIdMap['All Opportunities'],
|
||||
position: 4,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['opportunity'].fields['name'],
|
||||
viewId: viewIdMap['By Stage'],
|
||||
position: 0,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['opportunity'].fields['amount'],
|
||||
viewId: viewIdMap['By Stage'],
|
||||
position: 1,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['opportunity'].fields['closeDate'],
|
||||
viewId: viewIdMap['By Stage'],
|
||||
position: 2,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['opportunity'].fields['probability'],
|
||||
viewId: viewIdMap['By Stage'],
|
||||
position: 3,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId:
|
||||
objectMetadataMap['opportunity'].fields['pointOfContact'],
|
||||
viewId: viewIdMap['By Stage'],
|
||||
position: 4,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
])
|
||||
.execute();
|
||||
};
|
||||
@ -1,4 +1,4 @@
|
||||
import { DataSource } from 'typeorm';
|
||||
import { EntityManager } from 'typeorm';
|
||||
|
||||
import { SeedUserIds } from 'src/database/typeorm-seeds/core/users';
|
||||
import {
|
||||
@ -26,7 +26,7 @@ type WorkspaceMembers = Pick<
|
||||
};
|
||||
|
||||
export const seedWorkspaceMember = async (
|
||||
workspaceDataSource: DataSource,
|
||||
entityManager: EntityManager,
|
||||
schemaName: string,
|
||||
workspaceId: string,
|
||||
) => {
|
||||
@ -77,7 +77,7 @@ export const seedWorkspaceMember = async (
|
||||
},
|
||||
];
|
||||
}
|
||||
await workspaceDataSource
|
||||
await entityManager
|
||||
.createQueryBuilder()
|
||||
.insert()
|
||||
.into(`${schemaName}.${tableName}`, [
|
||||
|
||||
@ -2,7 +2,7 @@ import { EntityManager } from 'typeorm';
|
||||
|
||||
import companiesDemo from './companies-demo.json';
|
||||
|
||||
export const companyPrefillData = async (
|
||||
export const companyPrefillDemoData = async (
|
||||
entityManager: EntityManager,
|
||||
schemaName: string,
|
||||
) => {
|
||||
|
||||
@ -1,12 +1,11 @@
|
||||
import { DataSource, EntityManager } from 'typeorm';
|
||||
|
||||
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
|
||||
import { viewPrefillData } from 'src/engine/workspace-manager/demo-objects-prefill-data/view';
|
||||
import { companyPrefillData } from 'src/engine/workspace-manager/demo-objects-prefill-data/company';
|
||||
import { personPrefillData } from 'src/engine/workspace-manager/demo-objects-prefill-data/person';
|
||||
import { pipelineStepPrefillData } from 'src/engine/workspace-manager/demo-objects-prefill-data/pipeline-step';
|
||||
import { workspaceMemberPrefillData } from 'src/engine/workspace-manager/demo-objects-prefill-data/workspace-member';
|
||||
import { seedDemoOpportunity } from 'src/engine/workspace-manager/demo-objects-prefill-data/opportunity';
|
||||
import { viewPrefillData } from 'src/engine/workspace-manager/standard-objects-prefill-data/view';
|
||||
import { companyPrefillDemoData } from 'src/engine/workspace-manager/demo-objects-prefill-data/company';
|
||||
import { personPrefillDemoData } from 'src/engine/workspace-manager/demo-objects-prefill-data/person';
|
||||
import { opportunityPrefillDemoData } from 'src/engine/workspace-manager/demo-objects-prefill-data/opportunity';
|
||||
|
||||
export const demoObjectsPrefillData = async (
|
||||
workspaceDataSource: DataSource,
|
||||
@ -14,10 +13,10 @@ export const demoObjectsPrefillData = 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;
|
||||
}, {}),
|
||||
@ -26,18 +25,15 @@ export const demoObjectsPrefillData = async (
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
// TODO: udnerstand why only with this createQueryRunner transaction below works
|
||||
const queryRunner = workspaceDataSource.createQueryRunner();
|
||||
await workspaceDataSource.transaction(
|
||||
async (entityManager: EntityManager) => {
|
||||
await companyPrefillDemoData(entityManager, schemaName);
|
||||
await personPrefillDemoData(entityManager, schemaName);
|
||||
await opportunityPrefillDemoData(entityManager, schemaName);
|
||||
|
||||
await queryRunner.connect();
|
||||
await viewPrefillData(entityManager, schemaName, objectMetadataMap);
|
||||
|
||||
workspaceDataSource.transaction(async (entityManager: EntityManager) => {
|
||||
await companyPrefillData(entityManager, schemaName);
|
||||
await personPrefillData(entityManager, schemaName);
|
||||
await viewPrefillData(entityManager, schemaName, objectMetadataMap);
|
||||
await pipelineStepPrefillData(entityManager, schemaName);
|
||||
await seedDemoOpportunity(entityManager, schemaName);
|
||||
|
||||
await workspaceMemberPrefillData(entityManager, schemaName);
|
||||
});
|
||||
await workspaceMemberPrefillData(entityManager, schemaName);
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
@ -9,9 +9,6 @@ const getRandomProbability = () => {
|
||||
return firstDigit / 10;
|
||||
};
|
||||
|
||||
const getRandomPipelineStepId = (pipelineStepIds: { id: string }[]) =>
|
||||
pipelineStepIds[Math.floor(Math.random() * pipelineStepIds.length)].id;
|
||||
|
||||
const getRandomStage = () => {
|
||||
const stages = ['NEW', 'SCREENING', 'MEETING', 'PROPOSAL', 'CUSTOMER'];
|
||||
|
||||
@ -24,14 +21,7 @@ const generateRandomAmountMicros = () => {
|
||||
return firstDigit * 10000000000;
|
||||
};
|
||||
|
||||
// Function to generate the array of opportunities
|
||||
// companiesWithPeople - selecting from the db companies and 1 person related to the company.id to use companyId, pointOfContactId and personId
|
||||
// pipelineStepIds - selecting from the db pipeline, getting random id from selected to use as pipelineStepId
|
||||
|
||||
const generateOpportunities = (
|
||||
companies,
|
||||
pipelineStepIds: { id: string }[],
|
||||
) => {
|
||||
const generateOpportunities = (companies) => {
|
||||
return companies.map((company) => ({
|
||||
id: v4(),
|
||||
amountAmountMicros: generateRandomAmountMicros(),
|
||||
@ -39,13 +29,12 @@ const generateOpportunities = (
|
||||
closeDate: new Date(),
|
||||
stage: getRandomStage(),
|
||||
probability: getRandomProbability(),
|
||||
pipelineStepId: getRandomPipelineStepId(pipelineStepIds),
|
||||
pointOfContactId: company.personId,
|
||||
companyId: company.id,
|
||||
}));
|
||||
};
|
||||
|
||||
export const seedDemoOpportunity = async (
|
||||
export const opportunityPrefillDemoData = async (
|
||||
entityManager: EntityManager,
|
||||
schemaName: string,
|
||||
) => {
|
||||
@ -55,14 +44,8 @@ export const seedDemoOpportunity = async (
|
||||
LEFT JOIN ${schemaName}.person ON company.id = "person"."companyId"
|
||||
LIMIT 50`,
|
||||
);
|
||||
const pipelineStepIds = await entityManager?.query(
|
||||
`SELECT id FROM ${schemaName}."pipelineStep"`,
|
||||
);
|
||||
|
||||
const opportunities = generateOpportunities(
|
||||
companiesWithPeople,
|
||||
pipelineStepIds,
|
||||
);
|
||||
const opportunities = generateOpportunities(companiesWithPeople);
|
||||
|
||||
await entityManager
|
||||
.createQueryBuilder()
|
||||
@ -74,7 +57,6 @@ export const seedDemoOpportunity = async (
|
||||
'closeDate',
|
||||
'stage',
|
||||
'probability',
|
||||
'pipelineStepId',
|
||||
'pointOfContactId',
|
||||
'companyId',
|
||||
'position',
|
||||
|
||||
@ -2,7 +2,7 @@ import { EntityManager } from 'typeorm';
|
||||
|
||||
import peopleDemo from './people-demo.json';
|
||||
|
||||
export const personPrefillData = async (
|
||||
export const personPrefillDemoData = async (
|
||||
entityManager: EntityManager,
|
||||
schemaName: string,
|
||||
) => {
|
||||
|
||||
@ -1,41 +0,0 @@
|
||||
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();
|
||||
};
|
||||
@ -1,269 +0,0 @@
|
||||
import { EntityManager } from 'typeorm';
|
||||
|
||||
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
|
||||
|
||||
export const viewPrefillData = async (
|
||||
entityManager: EntityManager,
|
||||
schemaName: string,
|
||||
objectMetadataMap: Record<string, ObjectMetadataEntity>,
|
||||
) => {
|
||||
// Creating views
|
||||
const createdViews = await entityManager
|
||||
.createQueryBuilder()
|
||||
.insert()
|
||||
.into(`${schemaName}.view`, [
|
||||
'name',
|
||||
'objectMetadataId',
|
||||
'type',
|
||||
'key',
|
||||
'position',
|
||||
'icon',
|
||||
])
|
||||
.orIgnore()
|
||||
.values([
|
||||
{
|
||||
name: 'All Companies',
|
||||
objectMetadataId: objectMetadataMap['company'].id,
|
||||
type: 'table',
|
||||
key: 'INDEX',
|
||||
position: 0,
|
||||
icon: 'IconBuildingSkyscraper',
|
||||
},
|
||||
{
|
||||
name: 'All People',
|
||||
objectMetadataId: objectMetadataMap['person'].id,
|
||||
type: 'table',
|
||||
key: 'INDEX',
|
||||
position: 0,
|
||||
icon: 'IconUser',
|
||||
},
|
||||
{
|
||||
name: 'By Stage',
|
||||
objectMetadataId: objectMetadataMap['opportunity'].id,
|
||||
type: 'kanban',
|
||||
key: null,
|
||||
position: 0,
|
||||
icon: 'IconLayoutKanban',
|
||||
},
|
||||
{
|
||||
name: 'All Opportunities',
|
||||
objectMetadataId: objectMetadataMap['opportunity'].id,
|
||||
type: 'table',
|
||||
key: 'INDEX',
|
||||
position: 1,
|
||||
icon: 'IconTargetArrow',
|
||||
},
|
||||
])
|
||||
.returning('*')
|
||||
.execute();
|
||||
|
||||
const viewIdMap = createdViews.raw.reduce((acc, view) => {
|
||||
acc[view.name] = view.id;
|
||||
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
// Creating viewFields
|
||||
await entityManager
|
||||
.createQueryBuilder()
|
||||
.insert()
|
||||
.into(`${schemaName}.viewField`, [
|
||||
'fieldMetadataId',
|
||||
'viewId',
|
||||
'position',
|
||||
'isVisible',
|
||||
'size',
|
||||
])
|
||||
.orIgnore()
|
||||
.values([
|
||||
// Company
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['company'].fields['name'],
|
||||
viewId: viewIdMap['All Companies'],
|
||||
position: 0,
|
||||
isVisible: true,
|
||||
size: 180,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['company'].fields['domainName'],
|
||||
viewId: viewIdMap['All Companies'],
|
||||
position: 1,
|
||||
isVisible: true,
|
||||
size: 100,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['company'].fields['accountOwner'],
|
||||
viewId: viewIdMap['All Companies'],
|
||||
position: 2,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['company'].fields['createdAt'],
|
||||
viewId: viewIdMap['All Companies'],
|
||||
position: 3,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['company'].fields['employees'],
|
||||
viewId: viewIdMap['All Companies'],
|
||||
position: 4,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['company'].fields['linkedinLink'],
|
||||
viewId: viewIdMap['All Companies'],
|
||||
position: 5,
|
||||
isVisible: true,
|
||||
size: 170,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['company'].fields['address'],
|
||||
viewId: viewIdMap['All Companies'],
|
||||
position: 6,
|
||||
isVisible: true,
|
||||
size: 170,
|
||||
},
|
||||
// Person
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['person'].fields['name'],
|
||||
viewId: viewIdMap['All People'],
|
||||
position: 0,
|
||||
isVisible: true,
|
||||
size: 210,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['person'].fields['email'],
|
||||
viewId: viewIdMap['All People'],
|
||||
position: 1,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['person'].fields['company'],
|
||||
viewId: viewIdMap['All People'],
|
||||
position: 2,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['person'].fields['phone'],
|
||||
viewId: viewIdMap['All People'],
|
||||
position: 3,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['person'].fields['createdAt'],
|
||||
viewId: viewIdMap['All People'],
|
||||
position: 4,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['person'].fields['city'],
|
||||
viewId: viewIdMap['All People'],
|
||||
position: 5,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['person'].fields['jobTitle'],
|
||||
viewId: viewIdMap['All People'],
|
||||
position: 6,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['person'].fields['linkedinLink'],
|
||||
viewId: viewIdMap['All People'],
|
||||
position: 7,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['person'].fields['xLink'],
|
||||
viewId: viewIdMap['All People'],
|
||||
position: 8,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
// Opportunity
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['opportunity'].fields['name'],
|
||||
viewId: viewIdMap['All Opportunities'],
|
||||
position: 0,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['opportunity'].fields['amount'],
|
||||
viewId: viewIdMap['All Opportunities'],
|
||||
position: 1,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['opportunity'].fields['closeDate'],
|
||||
viewId: viewIdMap['All Opportunities'],
|
||||
position: 2,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['opportunity'].fields['probability'],
|
||||
viewId: viewIdMap['All Opportunities'],
|
||||
position: 3,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId:
|
||||
objectMetadataMap['opportunity'].fields['pointOfContact'],
|
||||
viewId: viewIdMap['All Opportunities'],
|
||||
position: 4,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['opportunity'].fields['name'],
|
||||
viewId: viewIdMap['By Stage'],
|
||||
position: 0,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['opportunity'].fields['amount'],
|
||||
viewId: viewIdMap['By Stage'],
|
||||
position: 1,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['opportunity'].fields['closeDate'],
|
||||
viewId: viewIdMap['By Stage'],
|
||||
position: 2,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['opportunity'].fields['probability'],
|
||||
viewId: viewIdMap['By Stage'],
|
||||
position: 3,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId:
|
||||
objectMetadataMap['opportunity'].fields['pointOfContact'],
|
||||
viewId: viewIdMap['By Stage'],
|
||||
position: 4,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
])
|
||||
.execute();
|
||||
};
|
||||
@ -4,7 +4,6 @@ import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadat
|
||||
import { viewPrefillData } from 'src/engine/workspace-manager/standard-objects-prefill-data/view';
|
||||
import { companyPrefillData } from 'src/engine/workspace-manager/standard-objects-prefill-data/company';
|
||||
import { personPrefillData } from 'src/engine/workspace-manager/standard-objects-prefill-data/person';
|
||||
import { pipelineStepPrefillData } from 'src/engine/workspace-manager/standard-objects-prefill-data/pipeline-step';
|
||||
|
||||
export const standardObjectsPrefillData = async (
|
||||
workspaceDataSource: DataSource,
|
||||
@ -12,10 +11,18 @@ export const standardObjectsPrefillData = async (
|
||||
objectMetadata: ObjectMetadataEntity[],
|
||||
) => {
|
||||
const objectMetadataMap = objectMetadata.reduce((acc, object) => {
|
||||
acc[object.nameSingular] = {
|
||||
if (!object.standardId) {
|
||||
throw new Error('Standard Id is not set for object: ${object.name}');
|
||||
}
|
||||
|
||||
acc[object.standardId] = {
|
||||
id: object.id,
|
||||
fields: object.fields.reduce((acc, field) => {
|
||||
acc[field.name] = field.id;
|
||||
if (!field.standardId) {
|
||||
throw new Error('Standard Id is not set for field: ${field.name}');
|
||||
}
|
||||
|
||||
acc[field.standardId] = field.id;
|
||||
|
||||
return acc;
|
||||
}, {}),
|
||||
@ -28,6 +35,5 @@ export const standardObjectsPrefillData = async (
|
||||
await companyPrefillData(entityManager, schemaName);
|
||||
await personPrefillData(entityManager, schemaName);
|
||||
await viewPrefillData(entityManager, schemaName, objectMetadataMap);
|
||||
await pipelineStepPrefillData(entityManager, schemaName);
|
||||
});
|
||||
};
|
||||
|
||||
@ -0,0 +1,84 @@
|
||||
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,
|
||||
objectMetadataMap: Record<string, ObjectMetadataEntity>,
|
||||
) => {
|
||||
return [
|
||||
{
|
||||
fieldMetadataId:
|
||||
objectMetadataMap[standardObjectIds.company].fields[
|
||||
companyStandardFieldIds.name
|
||||
],
|
||||
viewId: viewId,
|
||||
position: 0,
|
||||
isVisible: true,
|
||||
size: 180,
|
||||
},
|
||||
{
|
||||
fieldMetadataId:
|
||||
objectMetadataMap[standardObjectIds.company].fields[
|
||||
companyStandardFieldIds.domainName
|
||||
],
|
||||
viewId: viewId,
|
||||
position: 1,
|
||||
isVisible: true,
|
||||
size: 100,
|
||||
},
|
||||
{
|
||||
fieldMetadataId:
|
||||
objectMetadataMap[standardObjectIds.company].fields[
|
||||
companyStandardFieldIds.accountOwner
|
||||
],
|
||||
viewId: viewId,
|
||||
position: 2,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId:
|
||||
objectMetadataMap[standardObjectIds.company].fields[
|
||||
baseObjectStandardFieldIds.createdAt
|
||||
],
|
||||
viewId: viewId,
|
||||
position: 3,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId:
|
||||
objectMetadataMap[standardObjectIds.company].fields[
|
||||
companyStandardFieldIds.employees
|
||||
],
|
||||
viewId: viewId,
|
||||
position: 4,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId:
|
||||
objectMetadataMap[standardObjectIds.company].fields[
|
||||
companyStandardFieldIds.linkedinLink
|
||||
],
|
||||
viewId: viewId,
|
||||
position: 5,
|
||||
isVisible: true,
|
||||
size: 170,
|
||||
},
|
||||
{
|
||||
fieldMetadataId:
|
||||
objectMetadataMap[standardObjectIds.company].fields[
|
||||
companyStandardFieldIds.address
|
||||
],
|
||||
viewId: viewId,
|
||||
position: 6,
|
||||
isVisible: true,
|
||||
size: 170,
|
||||
},
|
||||
];
|
||||
};
|
||||
@ -0,0 +1,61 @@
|
||||
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,
|
||||
objectMetadataMap: Record<string, ObjectMetadataEntity>,
|
||||
) => {
|
||||
return [
|
||||
{
|
||||
fieldMetadataId:
|
||||
objectMetadataMap[standardObjectIds.opportunity].fields[
|
||||
opportunityStandardFieldIds.name
|
||||
],
|
||||
viewId: viewId,
|
||||
position: 0,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId:
|
||||
objectMetadataMap[standardObjectIds.opportunity].fields[
|
||||
opportunityStandardFieldIds.amount
|
||||
],
|
||||
viewId: viewId,
|
||||
position: 1,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId:
|
||||
objectMetadataMap[standardObjectIds.opportunity].fields[
|
||||
opportunityStandardFieldIds.closeDate
|
||||
],
|
||||
viewId: viewId,
|
||||
position: 2,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId:
|
||||
objectMetadataMap[standardObjectIds.opportunity].fields[
|
||||
opportunityStandardFieldIds.probability
|
||||
],
|
||||
viewId: viewId,
|
||||
position: 3,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId:
|
||||
objectMetadataMap[standardObjectIds.opportunity].fields[
|
||||
opportunityStandardFieldIds.pointOfContact
|
||||
],
|
||||
viewId: viewId,
|
||||
position: 4,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
];
|
||||
};
|
||||
@ -0,0 +1,104 @@
|
||||
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,
|
||||
objectMetadataMap: Record<string, ObjectMetadataEntity>,
|
||||
) => {
|
||||
return [
|
||||
{
|
||||
fieldMetadataId:
|
||||
objectMetadataMap[standardObjectIds.person].fields[
|
||||
personStandardFieldIds.name
|
||||
],
|
||||
viewId: viewId,
|
||||
position: 0,
|
||||
isVisible: true,
|
||||
size: 210,
|
||||
},
|
||||
{
|
||||
fieldMetadataId:
|
||||
objectMetadataMap[standardObjectIds.person].fields[
|
||||
personStandardFieldIds.email
|
||||
],
|
||||
viewId: viewId,
|
||||
position: 1,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId:
|
||||
objectMetadataMap[standardObjectIds.person].fields[
|
||||
personStandardFieldIds.company
|
||||
],
|
||||
viewId: viewId,
|
||||
position: 2,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId:
|
||||
objectMetadataMap[standardObjectIds.person].fields[
|
||||
personStandardFieldIds.phone
|
||||
],
|
||||
viewId: viewId,
|
||||
position: 3,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId:
|
||||
objectMetadataMap[standardObjectIds.person].fields[
|
||||
baseObjectStandardFieldIds.createdAt
|
||||
],
|
||||
viewId: viewId,
|
||||
position: 4,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId:
|
||||
objectMetadataMap[standardObjectIds.person].fields[
|
||||
personStandardFieldIds.city
|
||||
],
|
||||
viewId: viewId,
|
||||
position: 5,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId:
|
||||
objectMetadataMap[standardObjectIds.person].fields[
|
||||
personStandardFieldIds.jobTitle
|
||||
],
|
||||
viewId: viewId,
|
||||
position: 6,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId:
|
||||
objectMetadataMap[standardObjectIds.person].fields[
|
||||
personStandardFieldIds.linkedinLink
|
||||
],
|
||||
viewId: viewId,
|
||||
position: 7,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId:
|
||||
objectMetadataMap[standardObjectIds.person].fields[
|
||||
personStandardFieldIds.xLink
|
||||
],
|
||||
viewId: viewId,
|
||||
position: 8,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
];
|
||||
};
|
||||
@ -1,13 +1,17 @@
|
||||
import { EntityManager } from 'typeorm';
|
||||
|
||||
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
|
||||
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';
|
||||
import { opportunityStandardFieldIds } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids';
|
||||
|
||||
export const viewPrefillData = async (
|
||||
entityManager: EntityManager,
|
||||
schemaName: string,
|
||||
objectMetadataMap: Record<string, ObjectMetadataEntity>,
|
||||
) => {
|
||||
// Creating views
|
||||
const createdViews = await entityManager
|
||||
.createQueryBuilder()
|
||||
.insert()
|
||||
@ -18,40 +22,47 @@ export const viewPrefillData = async (
|
||||
'key',
|
||||
'position',
|
||||
'icon',
|
||||
'kanbanFieldMetadataId',
|
||||
])
|
||||
.orIgnore()
|
||||
.values([
|
||||
{
|
||||
name: 'All Companies',
|
||||
objectMetadataId: objectMetadataMap['company'].id,
|
||||
objectMetadataId: objectMetadataMap[standardObjectIds.company].id,
|
||||
type: 'table',
|
||||
key: 'INDEX',
|
||||
position: 0,
|
||||
icon: 'IconBuildingSkyscraper',
|
||||
kanbanFieldMetadataId: '',
|
||||
},
|
||||
{
|
||||
name: 'All People',
|
||||
objectMetadataId: objectMetadataMap['person'].id,
|
||||
objectMetadataId: objectMetadataMap[standardObjectIds.person].id,
|
||||
type: 'table',
|
||||
key: 'INDEX',
|
||||
position: 0,
|
||||
icon: 'IconUser',
|
||||
},
|
||||
{
|
||||
name: 'By Stage',
|
||||
objectMetadataId: objectMetadataMap['opportunity'].id,
|
||||
type: 'kanban',
|
||||
key: null,
|
||||
position: 0,
|
||||
icon: 'IconLayoutKanban',
|
||||
kanbanFieldMetadataId: '',
|
||||
},
|
||||
{
|
||||
name: 'All Opportunities',
|
||||
objectMetadataId: objectMetadataMap['opportunity'].id,
|
||||
objectMetadataId: objectMetadataMap[standardObjectIds.opportunity].id,
|
||||
type: 'table',
|
||||
key: 'INDEX',
|
||||
position: 1,
|
||||
position: 0,
|
||||
icon: 'IconTargetArrow',
|
||||
kanbanFieldMetadataId: '',
|
||||
},
|
||||
{
|
||||
name: 'By Stage',
|
||||
objectMetadataId: objectMetadataMap[standardObjectIds.opportunity].id,
|
||||
type: 'kanban',
|
||||
key: null,
|
||||
position: 1,
|
||||
icon: 'IconLayoutKanban',
|
||||
kanbanFieldMetadataId:
|
||||
objectMetadataMap[standardObjectIds.opportunity].fields[
|
||||
opportunityStandardFieldIds.stage
|
||||
],
|
||||
},
|
||||
])
|
||||
.returning('*')
|
||||
@ -63,7 +74,6 @@ export const viewPrefillData = async (
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
// Creating viewFields
|
||||
await entityManager
|
||||
.createQueryBuilder()
|
||||
.insert()
|
||||
@ -74,196 +84,16 @@ export const viewPrefillData = async (
|
||||
'isVisible',
|
||||
'size',
|
||||
])
|
||||
.orIgnore()
|
||||
.values([
|
||||
// Company
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['company'].fields['name'],
|
||||
viewId: viewIdMap['All Companies'],
|
||||
position: 0,
|
||||
isVisible: true,
|
||||
size: 180,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['company'].fields['domainName'],
|
||||
viewId: viewIdMap['All Companies'],
|
||||
position: 1,
|
||||
isVisible: true,
|
||||
size: 100,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['company'].fields['accountOwner'],
|
||||
viewId: viewIdMap['All Companies'],
|
||||
position: 2,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['company'].fields['createdAt'],
|
||||
viewId: viewIdMap['All Companies'],
|
||||
position: 3,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['company'].fields['employees'],
|
||||
viewId: viewIdMap['All Companies'],
|
||||
position: 4,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['company'].fields['linkedinLink'],
|
||||
viewId: viewIdMap['All Companies'],
|
||||
position: 5,
|
||||
isVisible: true,
|
||||
size: 170,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['company'].fields['address'],
|
||||
viewId: viewIdMap['All Companies'],
|
||||
position: 6,
|
||||
isVisible: true,
|
||||
size: 170,
|
||||
},
|
||||
// Person
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['person'].fields['name'],
|
||||
viewId: viewIdMap['All People'],
|
||||
position: 0,
|
||||
isVisible: true,
|
||||
size: 210,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['person'].fields['email'],
|
||||
viewId: viewIdMap['All People'],
|
||||
position: 1,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['person'].fields['company'],
|
||||
viewId: viewIdMap['All People'],
|
||||
position: 2,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['person'].fields['phone'],
|
||||
viewId: viewIdMap['All People'],
|
||||
position: 3,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['person'].fields['createdAt'],
|
||||
viewId: viewIdMap['All People'],
|
||||
position: 4,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['person'].fields['city'],
|
||||
viewId: viewIdMap['All People'],
|
||||
position: 5,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['person'].fields['jobTitle'],
|
||||
viewId: viewIdMap['All People'],
|
||||
position: 6,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['person'].fields['linkedinLink'],
|
||||
viewId: viewIdMap['All People'],
|
||||
position: 7,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['person'].fields['xLink'],
|
||||
viewId: viewIdMap['All People'],
|
||||
position: 8,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
// Opportunity
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['opportunity'].fields['name'],
|
||||
viewId: viewIdMap['All Opportunities'],
|
||||
position: 0,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['opportunity'].fields['amount'],
|
||||
viewId: viewIdMap['All Opportunities'],
|
||||
position: 1,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['opportunity'].fields['closeDate'],
|
||||
viewId: viewIdMap['All Opportunities'],
|
||||
position: 2,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['opportunity'].fields['probability'],
|
||||
viewId: viewIdMap['All Opportunities'],
|
||||
position: 3,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId:
|
||||
objectMetadataMap['opportunity'].fields['pointOfContact'],
|
||||
viewId: viewIdMap['All Opportunities'],
|
||||
position: 4,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['opportunity'].fields['name'],
|
||||
viewId: viewIdMap['By Stage'],
|
||||
position: 0,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['opportunity'].fields['amount'],
|
||||
viewId: viewIdMap['By Stage'],
|
||||
position: 1,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['opportunity'].fields['closeDate'],
|
||||
viewId: viewIdMap['By Stage'],
|
||||
position: 2,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['opportunity'].fields['probability'],
|
||||
viewId: viewIdMap['By Stage'],
|
||||
position: 3,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId:
|
||||
objectMetadataMap['opportunity'].fields['pointOfContact'],
|
||||
viewId: viewIdMap['By Stage'],
|
||||
position: 4,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
...viewCompanyFields(viewIdMap['Index Companies'], objectMetadataMap),
|
||||
...viewPersonFields(viewIdMap['Index People'], objectMetadataMap),
|
||||
...viewOpportunityFields(
|
||||
viewIdMap['Index Opportunities'],
|
||||
objectMetadataMap,
|
||||
),
|
||||
...viewCompanyFields(viewIdMap['All Companies'], objectMetadataMap),
|
||||
...viewPersonFields(viewIdMap['All People'], objectMetadataMap),
|
||||
...viewOpportunityFields(viewIdMap['By Stage'], objectMetadataMap),
|
||||
])
|
||||
.execute();
|
||||
};
|
||||
|
||||
@ -203,7 +203,6 @@ export const opportunityStandardFieldIds = {
|
||||
probability: '20202020-69d4-45f3-9703-690b09fafcf0',
|
||||
stage: '20202020-6f76-477d-8551-28cd65b2b4b9',
|
||||
position: '20202020-806d-493a-bbc6-6313e62958e2',
|
||||
pipelineStep: '20202020-cc8c-4ae7-8d83-25c3addaec5a',
|
||||
pointOfContact: '20202020-8dfb-42fc-92b6-01afb759ed16',
|
||||
company: '20202020-cbac-457e-b565-adece5fc815f',
|
||||
favorites: '20202020-a1c2-4500-aaae-83ba8a0e827a',
|
||||
@ -232,13 +231,6 @@ export const personStandardFieldIds = {
|
||||
events: '20202020-a43e-4873-9c23-e522de906ce5',
|
||||
};
|
||||
|
||||
export const pipelineStepStandardFieldIds = {
|
||||
name: '20202020-e10a-4119-9466-97873e86fa47',
|
||||
color: '20202020-4a09-4088-90b8-ce1c72730f43',
|
||||
position: '20202020-44e8-4520-af64-4a3cb37fa0c5',
|
||||
opportunities: '20202020-0442-482a-867f-6d8fd4145ed1',
|
||||
};
|
||||
|
||||
export const viewFieldStandardFieldIds = {
|
||||
fieldMetadataId: '20202020-135f-4c5b-b361-15f24870473c',
|
||||
isVisible: '20202020-e966-473c-9c18-f00d3347e0ba',
|
||||
@ -267,6 +259,7 @@ export const viewStandardFieldIds = {
|
||||
type: '20202020-dd11-4607-9ec7-c57217262a7f',
|
||||
key: '20202020-298e-49fa-9f4a-7b416b110443',
|
||||
icon: '20202020-1f08-4fd9-929b-cbc07f317166',
|
||||
kanbanFieldMetadataId: '20202020-d09b-4f65-ac42-06a2f20ba0e8',
|
||||
position: '20202020-e9db-4303-b271-e8250c450172',
|
||||
isCompact: '20202020-674e-4314-994d-05754ea7b22b',
|
||||
viewFields: '20202020-542b-4bdc-b177-b63175d48edf',
|
||||
|
||||
@ -27,7 +27,6 @@ export const standardObjectIds = {
|
||||
message: '20202020-3f6b-4425-80ab-e468899ab4b2',
|
||||
opportunity: '20202020-9549-49dd-b2b2-883999db8938',
|
||||
person: '20202020-e674-48e5-a542-72570eee7213',
|
||||
pipelineStep: '20202020-f9a3-45f3-82e2-28952a8b19bf',
|
||||
viewField: '20202020-4d19-4655-95bf-b2a04cf206d4',
|
||||
viewFilter: '20202020-6fb6-4631-aded-b7d67e952ec8',
|
||||
viewSort: '20202020-e46a-47a8-939a-e5d911f83531',
|
||||
|
||||
@ -17,7 +17,6 @@ import { MessageThreadObjectMetadata } from 'src/modules/messaging/standard-obje
|
||||
import { MessageObjectMetadata } from 'src/modules/messaging/standard-objects/message.object-metadata';
|
||||
import { OpportunityObjectMetadata } from 'src/modules/opportunity/standard-objects/opportunity.object-metadata';
|
||||
import { PersonObjectMetadata } from 'src/modules/person/standard-objects/person.object-metadata';
|
||||
import { PipelineStepObjectMetadata } from 'src/modules/pipeline-step/standard-objects/pipeline-step.object-metadata';
|
||||
import { ViewFieldObjectMetadata } from 'src/modules/view/standard-objects/view-field.object-metadata';
|
||||
import { ViewFilterObjectMetadata } from 'src/modules/view/standard-objects/view-filter.object-metadata';
|
||||
import { ViewSortObjectMetadata } from 'src/modules/view/standard-objects/view-sort.object-metadata';
|
||||
@ -40,7 +39,6 @@ export const standardObjectMetadataDefinitions = [
|
||||
FavoriteObjectMetadata,
|
||||
OpportunityObjectMetadata,
|
||||
PersonObjectMetadata,
|
||||
PipelineStepObjectMetadata,
|
||||
ViewFieldObjectMetadata,
|
||||
ViewFilterObjectMetadata,
|
||||
ViewSortObjectMetadata,
|
||||
|
||||
@ -17,7 +17,6 @@ import { BaseObjectMetadata } from 'src/engine/workspace-manager/workspace-sync-
|
||||
import { CompanyObjectMetadata } from 'src/modules/company/standard-objects/company.object-metadata';
|
||||
import { FavoriteObjectMetadata } from 'src/modules/favorite/standard-objects/favorite.object-metadata';
|
||||
import { PersonObjectMetadata } from 'src/modules/person/standard-objects/person.object-metadata';
|
||||
import { PipelineStepObjectMetadata } from 'src/modules/pipeline-step/standard-objects/pipeline-step.object-metadata';
|
||||
import { EventObjectMetadata } from 'src/modules/event/standard-objects/event.object-metadata';
|
||||
import { Gate } from 'src/engine/workspace-manager/workspace-sync-metadata/decorators/gate.decorator';
|
||||
|
||||
@ -102,18 +101,6 @@ export class OpportunityObjectMetadata extends BaseObjectMetadata {
|
||||
@IsNullable()
|
||||
position: number;
|
||||
|
||||
// Relations
|
||||
@FieldMetadata({
|
||||
standardId: opportunityStandardFieldIds.pipelineStep,
|
||||
type: FieldMetadataType.RELATION,
|
||||
label: 'Pipeline Step',
|
||||
description: 'Opportunity pipeline step',
|
||||
icon: 'IconKanban',
|
||||
joinColumn: 'pipelineStepId',
|
||||
})
|
||||
@IsNullable()
|
||||
pipelineStep: PipelineStepObjectMetadata;
|
||||
|
||||
@FieldMetadata({
|
||||
standardId: opportunityStandardFieldIds.pointOfContact,
|
||||
type: FieldMetadataType.RELATION,
|
||||
|
||||
@ -1,66 +0,0 @@
|
||||
import { FieldMetadataType } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
|
||||
import { RelationMetadataType } from 'src/engine/metadata-modules/relation-metadata/relation-metadata.entity';
|
||||
import { pipelineStepStandardFieldIds } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids';
|
||||
import { standardObjectIds } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-ids';
|
||||
import { FieldMetadata } from 'src/engine/workspace-manager/workspace-sync-metadata/decorators/field-metadata.decorator';
|
||||
import { IsNullable } from 'src/engine/workspace-manager/workspace-sync-metadata/decorators/is-nullable.decorator';
|
||||
import { IsSystem } from 'src/engine/workspace-manager/workspace-sync-metadata/decorators/is-system.decorator';
|
||||
import { ObjectMetadata } from 'src/engine/workspace-manager/workspace-sync-metadata/decorators/object-metadata.decorator';
|
||||
import { RelationMetadata } from 'src/engine/workspace-manager/workspace-sync-metadata/decorators/relation-metadata.decorator';
|
||||
import { BaseObjectMetadata } from 'src/engine/workspace-manager/workspace-sync-metadata/standard-objects/base.object-metadata';
|
||||
import { OpportunityObjectMetadata } from 'src/modules/opportunity/standard-objects/opportunity.object-metadata';
|
||||
|
||||
@ObjectMetadata({
|
||||
standardId: standardObjectIds.pipelineStep,
|
||||
namePlural: 'pipelineSteps',
|
||||
labelSingular: 'Pipeline Step',
|
||||
labelPlural: 'Pipeline Steps',
|
||||
description: 'A pipeline step',
|
||||
icon: 'IconLayoutKanban',
|
||||
})
|
||||
@IsSystem()
|
||||
export class PipelineStepObjectMetadata extends BaseObjectMetadata {
|
||||
@FieldMetadata({
|
||||
standardId: pipelineStepStandardFieldIds.name,
|
||||
type: FieldMetadataType.TEXT,
|
||||
label: 'Name',
|
||||
description: 'Pipeline Step name',
|
||||
icon: 'IconCurrencyDollar',
|
||||
})
|
||||
name: string;
|
||||
|
||||
@FieldMetadata({
|
||||
standardId: pipelineStepStandardFieldIds.color,
|
||||
type: FieldMetadataType.TEXT,
|
||||
label: 'Color',
|
||||
description: 'Pipeline Step color',
|
||||
icon: 'IconColorSwatch',
|
||||
})
|
||||
color: string;
|
||||
|
||||
@FieldMetadata({
|
||||
standardId: pipelineStepStandardFieldIds.position,
|
||||
type: FieldMetadataType.NUMBER,
|
||||
label: 'Position',
|
||||
description: 'Pipeline Step position',
|
||||
icon: 'IconHierarchy2',
|
||||
defaultValue: { value: 0 },
|
||||
})
|
||||
@IsNullable()
|
||||
position: number;
|
||||
|
||||
// Relations
|
||||
@FieldMetadata({
|
||||
standardId: pipelineStepStandardFieldIds.opportunities,
|
||||
type: FieldMetadataType.RELATION,
|
||||
label: 'Opportunities',
|
||||
description: 'Opportunities linked to the step.',
|
||||
icon: 'IconTargetArrow',
|
||||
})
|
||||
@RelationMetadata({
|
||||
type: RelationMetadataType.ONE_TO_MANY,
|
||||
inverseSideTarget: () => OpportunityObjectMetadata,
|
||||
})
|
||||
@IsNullable()
|
||||
opportunities: OpportunityObjectMetadata[];
|
||||
}
|
||||
@ -66,6 +66,14 @@ export class ViewObjectMetadata extends BaseObjectMetadata {
|
||||
})
|
||||
icon: string;
|
||||
|
||||
@FieldMetadata({
|
||||
standardId: viewStandardFieldIds.kanbanFieldMetadataId,
|
||||
type: FieldMetadataType.TEXT,
|
||||
label: 'kanbanfieldMetadataId',
|
||||
description: 'View Kanban column field',
|
||||
})
|
||||
kanbanFieldMetadataId: string;
|
||||
|
||||
@FieldMetadata({
|
||||
standardId: viewStandardFieldIds.position,
|
||||
type: FieldMetadataType.POSITION,
|
||||
|
||||
Reference in New Issue
Block a user