feat: added countTrue and countFalse (#10741)
fix: #10603 https://www.loom.com/share/cebc8a19bd8e4ae684a5a215d0fd1f94?sid=cadaa395-285c-45c9-b3ce-2ae6d1330a3c --------- Co-authored-by: Félix Malfait <felix@twenty.com> Co-authored-by: Félix Malfait <felix.malfait@gmail.com>
This commit is contained in:
@ -7,6 +7,8 @@ export enum AGGREGATE_OPERATIONS {
|
||||
countUniqueValues = 'COUNT_UNIQUE_VALUES',
|
||||
countEmpty = 'COUNT_EMPTY',
|
||||
countNotEmpty = 'COUNT_NOT_EMPTY',
|
||||
countTrue = 'COUNT_TRUE',
|
||||
countFalse = 'COUNT_FALSE',
|
||||
percentageEmpty = 'PERCENTAGE_EMPTY',
|
||||
percentageNotEmpty = 'PERCENTAGE_NOT_EMPTY',
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
import { SelectQueryBuilder } from 'typeorm';
|
||||
import { isDefined } from 'twenty-shared';
|
||||
import { SelectQueryBuilder } from 'typeorm';
|
||||
|
||||
import { AGGREGATE_OPERATIONS } from 'src/engine/api/graphql/graphql-query-runner/constants/aggregate-operations.constant';
|
||||
import { AggregationField } from 'src/engine/api/graphql/workspace-schema-builder/utils/get-available-aggregations-from-object-fields.util';
|
||||
@ -87,6 +87,19 @@ export class ProcessAggregateHelper {
|
||||
`${aggregatedFieldName}`,
|
||||
);
|
||||
break;
|
||||
case AGGREGATE_OPERATIONS.countTrue:
|
||||
queryBuilder.addSelect(
|
||||
`CASE WHEN COUNT(*) = 0 THEN NULL ELSE COUNT(CASE WHEN ${columnExpression}::boolean = TRUE THEN 1 ELSE NULL END) END`,
|
||||
`${aggregatedFieldName}`,
|
||||
);
|
||||
break;
|
||||
|
||||
case AGGREGATE_OPERATIONS.countFalse:
|
||||
queryBuilder.addSelect(
|
||||
`CASE WHEN COUNT(*) = 0 THEN NULL ELSE COUNT(CASE WHEN ${columnExpression}::boolean = FALSE THEN 1 ELSE NULL END) END`,
|
||||
`${aggregatedFieldName}`,
|
||||
);
|
||||
break;
|
||||
default: {
|
||||
queryBuilder.addSelect(
|
||||
`${aggregatedField.aggregateOperation}("${columnNameForNumericOperation}")`,
|
||||
|
||||
@ -98,6 +98,24 @@ export const getAvailableAggregationsFromObjectFields = (
|
||||
}
|
||||
|
||||
switch (field.type) {
|
||||
case FieldMetadataType.BOOLEAN:
|
||||
acc[`countTrue${capitalize(field.name)}`] = {
|
||||
type: GraphQLInt,
|
||||
description: `Count of true values in the field ${field.name}`,
|
||||
fromField: field.name,
|
||||
fromFieldType: field.type,
|
||||
aggregateOperation: AGGREGATE_OPERATIONS.countTrue,
|
||||
};
|
||||
|
||||
acc[`countFalse${capitalize(field.name)}`] = {
|
||||
type: GraphQLInt,
|
||||
description: `Count of false values in the field ${field.name}`,
|
||||
fromField: field.name,
|
||||
fromFieldType: field.type,
|
||||
aggregateOperation: AGGREGATE_OPERATIONS.countFalse,
|
||||
};
|
||||
break;
|
||||
|
||||
case FieldMetadataType.NUMBER:
|
||||
acc[`min${capitalize(field.name)}`] = {
|
||||
type: GraphQLFloat,
|
||||
|
||||
Reference in New Issue
Block a user