8938dd637f
Fixes https://github.com/twentyhq/core-team-issues/issues/2192 This PR implements what is necessary to re-create the query that we build on the frontend to obtain the returned object record from a mutation, but on the backend, which was only partially implemented for REST API. Usually we want to have relations with only their id and label identifier field to have lighter payloads. In the event we only had depth 0 fields, with this PR we have all events with depth 1 relations. We have depth 2 for many-to-many cases, like updateOne or updateMany result : - Junction tables - Activity target tables
66 lines
2.7 KiB
TypeScript
66 lines
2.7 KiB
TypeScript
import { Injectable } from '@nestjs/common';
|
|
|
|
import { type ObjectRecord } from 'twenty-shared/types';
|
|
import { type FindOptionsRelations, type ObjectLiteral } from 'typeorm';
|
|
|
|
import { ProcessNestedRelationsV2Helper } from 'src/engine/api/common/common-nested-relations-processor/process-nested-relations-v2.helper';
|
|
import { type AggregationField } from 'src/engine/api/graphql/workspace-schema-builder/utils/get-available-aggregations-from-object-fields.util';
|
|
import { AuthContext } from 'src/engine/core-modules/auth/types/auth-context.type';
|
|
import { FlatEntityMaps } from 'src/engine/metadata-modules/flat-entity/types/flat-entity-maps.type';
|
|
import { FlatFieldMetadata } from 'src/engine/metadata-modules/flat-field-metadata/types/flat-field-metadata.type';
|
|
import { FlatObjectMetadata } from 'src/engine/metadata-modules/flat-object-metadata/types/flat-object-metadata.type';
|
|
import { GlobalWorkspaceDataSource } from 'src/engine/twenty-orm/global-workspace-datasource/global-workspace-datasource';
|
|
import { RolePermissionConfig } from 'src/engine/twenty-orm/types/role-permission-config';
|
|
|
|
@Injectable()
|
|
export class ProcessNestedRelationsHelper {
|
|
constructor(
|
|
private readonly processNestedRelationsV2Helper: ProcessNestedRelationsV2Helper,
|
|
) {}
|
|
|
|
public async processNestedRelations<T extends ObjectRecord = ObjectRecord>({
|
|
flatObjectMetadataMaps,
|
|
flatFieldMetadataMaps,
|
|
parentObjectMetadataItem,
|
|
parentObjectRecords,
|
|
parentObjectRecordsAggregatedValues = {},
|
|
relations,
|
|
aggregate = {},
|
|
limit,
|
|
authContext,
|
|
workspaceDataSource,
|
|
rolePermissionConfig,
|
|
selectedFields,
|
|
}: {
|
|
flatObjectMetadataMaps: FlatEntityMaps<FlatObjectMetadata>;
|
|
flatFieldMetadataMaps: FlatEntityMaps<FlatFieldMetadata>;
|
|
parentObjectMetadataItem: FlatObjectMetadata;
|
|
parentObjectRecords: T[];
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
parentObjectRecordsAggregatedValues?: Record<string, any>;
|
|
relations: Record<string, FindOptionsRelations<ObjectLiteral>>;
|
|
aggregate?: Record<string, AggregationField>;
|
|
limit: number;
|
|
authContext: AuthContext;
|
|
workspaceDataSource: GlobalWorkspaceDataSource;
|
|
rolePermissionConfig?: RolePermissionConfig;
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
selectedFields: Record<string, any>;
|
|
}): Promise<void> {
|
|
return this.processNestedRelationsV2Helper.processNestedRelations({
|
|
flatObjectMetadataMaps,
|
|
flatFieldMetadataMaps,
|
|
parentObjectMetadataItem,
|
|
parentObjectRecords,
|
|
parentObjectRecordsAggregatedValues,
|
|
relations,
|
|
aggregate,
|
|
limit,
|
|
authContext,
|
|
workspaceDataSource,
|
|
rolePermissionConfig,
|
|
selectedFields,
|
|
});
|
|
}
|
|
}
|