[groupBy][Requires cache flush] Add WEEK date granularity (#16099)
Closes https://github.com/twentyhq/core-team-issues/issues/1921 https://github.com/user-attachments/assets/bf400ec1-ce25-4d9e-b875-774168452514
This commit is contained in:
+26
-3
@@ -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.',
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user