Skip to content

Commit f8d092a

Browse files
committed
feat: enhance aggregation handler to support user-defined time zones
1 parent 46061df commit f8d092a

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

adminforth/modules/restApi.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,7 +1572,7 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
15721572
description: 'Performs aggregation queries (sum, count, avg, min, max, median) on a resource, with optional grouping by field value or date truncation.',
15731573
request_schema: aggregateRequestSchema,
15741574
response_schema: aggregateResponseSchema,
1575-
handler: async ({ body, adminUser }) => {
1575+
handler: async ({ body, adminUser, headers }) => {
15761576
const { resourceId, aggregations, filters, groupBy } = body;
15771577
if (!this.adminforth.statuses.dbDiscover) {
15781578
return { error: 'Database discovery not started' };
@@ -1618,11 +1618,16 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
16181618
}
16191619

16201620
try {
1621+
const userTimeZone = headers['X-TimeZone'];
1622+
const aggregateGroupBy = groupBy?.type === 'date_trunc' && userTimeZone
1623+
? { ...groupBy, timezone: userTimeZone }
1624+
: groupBy;
1625+
16211626
const data = await this.adminforth.connectors[resource.dataSource].aggregate({
16221627
resource,
16231628
filters: normalizedFilters as IAdminForthAndOrFilter,
16241629
aggregations,
1625-
groupBy,
1630+
groupBy: aggregateGroupBy,
16261631
});
16271632
return { data };
16281633
} catch (e) {

0 commit comments

Comments
 (0)