Marie
2025-11-27 11:22:57 +01:00
committed by GitHub
parent 7e90dd888c
commit 9c9a01d55a
25 changed files with 437 additions and 42 deletions
@@ -1,7 +1,10 @@
import { Injectable } from '@nestjs/common';
import { GraphQLEnumType, GraphQLInputObjectType } from 'graphql';
import { ObjectRecordGroupByDateGranularity } from 'twenty-shared/types';
import {
FirstDayOfTheWeek,
ObjectRecordGroupByDateGranularity,
} from 'twenty-shared/types';
import { isDefined } from 'twenty-shared/utils';
import { OrderByDirectionType } from 'src/engine/api/graphql/workspace-schema-builder/graphql-types/enum';
@@ -30,7 +33,7 @@ export class GroupByDateGranularityInputTypeGenerator {
{} as Record<string, { value: string }>,
),
description:
'Date granularity (e.g. day, month, quarter, year, day of the week, quarter of the year, month of the year)',
'Date granularity (e.g. day, month, quarter, year, week, day of the week, quarter of the year, month of the year)',
}),
);
@@ -42,13 +45,33 @@ export class GroupByDateGranularityInputTypeGenerator {
throw new Error('DateGranularityEnum not found');
}
const firstDayOfWeekEnum = new GraphQLEnumType({
name: 'FirstDayOfTheWeek',
values: Object.values(FirstDayOfTheWeek).reduce(
(acc, option) => {
acc[option] = { value: option };
return acc;
},
{} as Record<string, { value: string }>,
),
description: 'First day of the week (MONDAY, SUNDAY, SATURDAY)',
});
this.gqlTypesStorage.addGqlType('FirstDayOfTheWeek', firstDayOfWeekEnum);
const groupByDateField = new GraphQLInputObjectType({
name: GROUP_BY_DATE_GRANULARITY_INPUT_KEY,
fields: {
granularity: {
type: dateGranularityEnum,
description:
'Date granularity (e.g. day, month, quarter, year, day of the week, quarter of the year, month of the year)',
'Date granularity (e.g. day, month, quarter, year, week, day of the week, quarter of the year, month of the year)',
},
weekStartDay: {
type: firstDayOfWeekEnum,
description:
'First day of the week (only applicable when granularity is WEEK). Defaults to MONDAY if not specified.',
},
},
});