fix(analytics): handle statDate as string from database
- Fix toDto method to handle statDate being string or Date - Fix getTrendData method to handle statDate being string or Date - PostgreSQL date type returns string, not Date object Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
9dbd54aefb
commit
dcff831e7d
|
|
@ -133,7 +133,9 @@ export class StatisticsAggregationService {
|
||||||
const result: Record<string, TrendDataPoint[]> = {};
|
const result: Record<string, TrendDataPoint[]> = {};
|
||||||
for (const metric of params.metrics) {
|
for (const metric of params.metrics) {
|
||||||
result[metric] = filtered.map(s => ({
|
result[metric] = filtered.map(s => ({
|
||||||
date: s.statDate.toISOString().split('T')[0],
|
date: s.statDate instanceof Date
|
||||||
|
? s.statDate.toISOString().split('T')[0]
|
||||||
|
: String(s.statDate).split('T')[0],
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
value: Number((s as any)[metric] || 0),
|
value: Number((s as any)[metric] || 0),
|
||||||
}));
|
}));
|
||||||
|
|
@ -373,8 +375,13 @@ export class StatisticsAggregationService {
|
||||||
}
|
}
|
||||||
|
|
||||||
private toDto(orm: DailyStatisticsORM): DailyStatisticsDto {
|
private toDto(orm: DailyStatisticsORM): DailyStatisticsDto {
|
||||||
|
// Handle statDate being either Date or string
|
||||||
|
const statDateStr = orm.statDate instanceof Date
|
||||||
|
? orm.statDate.toISOString().split('T')[0]
|
||||||
|
: String(orm.statDate).split('T')[0];
|
||||||
|
|
||||||
return {
|
return {
|
||||||
statDate: orm.statDate.toISOString().split('T')[0],
|
statDate: statDateStr,
|
||||||
dimension: orm.dimension,
|
dimension: orm.dimension,
|
||||||
dimensionValue: orm.dimensionValue,
|
dimensionValue: orm.dimensionValue,
|
||||||
newUsers: Number(orm.newUsers),
|
newUsers: Number(orm.newUsers),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue