frontend: add new insight type
Parents:
b5447662 file(s) changed
- frontend/lib/api/client.ts +1 -1
- frontend/lib/api/types.ts +10 -1
frontend/lib/api/client.ts
1 1
import * as SecureStore from "expo-secure-store";
2 2
import {
3 3
User,
4 4
AuthResponse,
5 5
VerifyTokenResponse,
▸ 271 unchanged lines
277 277
// Insights
278 278
async getInsights(filters?: {
279 279
type?: InsightType;
280 280
period?: InsightPeriod;
281 281
limit?: number;
282 -
}): Promise<Insight[]> {
282 +
}): Promise<{ insights: Insight[] }> {
283 283
const query = new URLSearchParams();
284 284
if (filters?.type) query.set("type", filters.type);
285 285
if (filters?.period) query.set("period", filters.period);
286 286
if (filters?.limit) query.set("limit", String(filters.limit));
287 287
▸ 1 unchanged lines
289 289
return this.request(`/insights${qs ? `?${qs}` : ""}`);
290 290
}
291 291
}
292 292
293 293
export const apiClient = new ApiClient();
frontend/lib/api/types.ts
1 1
export interface User {
2 2
id: number;
3 3
email: string;
4 4
firstName: string;
5 5
lastName?: string;
▸ 122 unchanged lines
128 128
// types/insight.ts
129 129
// Gotta keep those in sync with the Prisma schema
130 130
export type InsightType =
131 131
| "MOOD_TREND"
132 132
| "ENERGY_SLEEP_CORRELATION"
133 -
| "TRIGGER_PATTERN";
133 +
| "TRIGGER_PATTERN"
134 +
| "DAILY_ENERGY";
134 135
135 136
export type InsightPeriod = "DAILY" | "WEEKLY" | "MONTHLY";
136 137
137 138
export type InsightMetadata =
138 139
| {
▸ 13 unchanged lines
152 153
type: "TRIGGER_PATTERN";
153 154
topCategory: string;
154 155
topCount: number;
155 156
total: number;
156 157
distribution: Record<string, number>;
158 +
}
159 +
| {
160 +
type: "DAILY_ENERGY";
161 +
avgEnergy: number;
162 +
dayTrend: number | null;
163 +
peak: number;
164 +
trough: number;
165 +
entryCount: number;
157 166
};
158 167
159 168
export type Insight = {
160 169
id: number;
161 170
type: InsightType;
▸ 23 unchanged lines
185 194
}
186 195
187 196
export interface TriggerResponse {
188 197
trigger: Trigger;
189 198
}