Rework relations (#3431)

* Rework relations

* Fix tests
This commit is contained in:
Charles Bochet
2024-01-15 12:07:23 +01:00
committed by GitHub
parent 8c96acc2a3
commit 16a24c5f0c
60 changed files with 392 additions and 463 deletions

View File

@ -35,7 +35,7 @@ describe('FilterInputFactory', () => {
};
expect(() => service.create(request, objectMetadata)).toThrow(
"field 'wrongField' does not exist in 'testingObject' object",
"field 'wrongField' does not exist in 'objectName' object",
);
});

View File

@ -112,7 +112,7 @@ describe('OrderByInputFactory', () => {
};
expect(() => service.create(request, objectMetadata)).toThrow(
"field 'wrongField' does not exist in 'testingObject' object",
"field 'wrongField' does not exist in 'objectName' object",
);
});
});

View File

@ -1,6 +1,7 @@
import { BadRequestException } from '@nestjs/common';
import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity';
import { computeObjectTargetTable } from 'src/workspace/utils/compute-object-target-table.util';
export const getFieldType = (
objectMetadataItem,
@ -28,7 +29,9 @@ export const checkFields = (objectMetadataItem, fieldNames): void => {
.includes(fieldName)
) {
throw new BadRequestException(
`field '${fieldName}' does not exist in '${objectMetadataItem.targetTableName}' object`,
`field '${fieldName}' does not exist in '${computeObjectTargetTable(
objectMetadataItem,
)}' object`,
);
}
}

View File

@ -3,6 +3,7 @@ import { Injectable } from '@nestjs/common';
import { v4 as uuidv4 } from 'uuid';
import { Record as IRecord } from 'src/workspace/workspace-query-builder/interfaces/record.interface';
import { ObjectMetadataInterface } from 'src/metadata/field-metadata/interfaces/object-metadata.interface';
import { isWorkEmail } from 'src/utils/is-work-email';
import { stringifyWithoutKeyQuote } from 'src/workspace/workspace-query-builder/utils/stringify-without-key-quote.util';
@ -17,7 +18,19 @@ export class QuickActionsService {
private readonly intelligenceService: IntelligenceService,
) {}
async createCompanyFromPerson(id: string, workspaceId: string) {
async createCompanyFromPerson(
id: string,
workspaceId: string,
objectMetadataItemCollection: ObjectMetadataInterface[],
) {
const personObjectMetadata = objectMetadataItemCollection.find(
(item) => item.nameSingular === 'person',
);
if (!personObjectMetadata) {
return;
}
const personRequest =
await this.workspaceQueryRunnunerService.executeAndParse<IRecord>(
`query {
@ -32,7 +45,7 @@ export class QuickActionsService {
}
}
`,
'person',
personObjectMetadata,
'',
workspaceId,
);
@ -47,6 +60,14 @@ export class QuickActionsService {
const companyName = capitalize(companyDomainName.split('.')[0]);
let relatedCompanyId = uuidv4();
const companyObjectMetadata = objectMetadataItemCollection.find(
(item) => item.nameSingular === 'company',
);
if (!companyObjectMetadata) {
return;
}
const existingCompany =
await this.workspaceQueryRunnunerService.executeAndParse<IRecord>(
`query {companyCollection(filter: {domainName: {eq: "${companyDomainName}"}}) {
@ -58,7 +79,7 @@ export class QuickActionsService {
}
}
`,
'company',
companyObjectMetadata,
'',
workspaceId,
);
@ -105,7 +126,11 @@ export class QuickActionsService {
}
}
async executeQuickActionOnCompany(id: string, workspaceId: string) {
async executeQuickActionOnCompany(
id: string,
workspaceId: string,
objectMetadataItem: ObjectMetadataInterface,
) {
const companyQuery = `query {
companyCollection(filter: {id: {eq: "${id}"}}) {
edges {
@ -123,7 +148,7 @@ export class QuickActionsService {
const companyRequest =
await this.workspaceQueryRunnunerService.executeAndParse<IRecord>(
companyQuery,
'company',
objectMetadataItem,
'',
workspaceId,
);