Files
twenty/packages/twenty-server/src/modules/dashboard/chart-data/utils/get-field-metadata.util.ts
T
Raphaël Bosi d0bc8b9ffe [DASHBOARDS] Move all the graph computing logic to the backend (#17189)
- Create resolvers for each type of charts which needs data
transformation after the group by operation: Bar Chart, Line Chart and
Pie Chart
- Move all the utils to the backend and refactored some into services

This allows all the computation to be done in the backend, improving
performances in the frontend.
2026-01-19 17:25:45 +00:00

28 lines
849 B
TypeScript

import { isDefined } from 'twenty-shared/utils';
import { type FlatFieldMetadata } from 'src/engine/metadata-modules/flat-field-metadata/types/flat-field-metadata.type';
import {
ChartDataException,
ChartDataExceptionCode,
generateChartDataExceptionMessage,
} from 'src/modules/dashboard/chart-data/exceptions/chart-data.exception';
export const getFieldMetadata = (
fieldMetadataId: string,
fieldMetadataById: Partial<Record<string, FlatFieldMetadata>>,
): FlatFieldMetadata => {
const fieldMetadata = fieldMetadataById[fieldMetadataId];
if (!isDefined(fieldMetadata)) {
throw new ChartDataException(
generateChartDataExceptionMessage(
ChartDataExceptionCode.FIELD_METADATA_NOT_FOUND,
fieldMetadataId,
),
ChartDataExceptionCode.FIELD_METADATA_NOT_FOUND,
);
}
return fieldMetadata;
};