frontend: update medicine types, add today/patchMe API methods
Rewrite the scheduledAt to be a native string array, introduce new types for both the user preferences payload and the today's medicine endpoint and rig those with the api client
Parents:
e12acd94 file(s) changed
- frontend/app/care-actions/medicine-new.tsx +3 -5
- frontend/lib/api/client.ts +13 -0
- frontend/lib/api/index.ts +2 -0
- frontend/lib/api/types.ts +15 -3
frontend/app/care-actions/medicine-new.tsx
1 1
import {
2 2
View,
3 3
Text,
4 4
StyleSheet,
5 5
KeyboardAvoidingView,
▸ 42 unchanged lines
48 48
49 49
const createCareAction = useCreateCareAction();
50 50
51 51
const handleSave = async () => {
52 52
const count = getTimePickerCount(medicinePeriodicity);
53 -
const scheduledAt = count > 0
54 -
? scheduledTimes.slice(0, count)
55 -
.map(d => `${d.getHours().toString().padStart(2,'0')}:${d.getMinutes().toString().padStart(2,'0')}`)
56 -
.join(',')
57 -
: undefined;
53 +
const scheduledAt = scheduledTimes.slice(0, count).map(
54 +
d => `${d.getHours().toString().padStart(2,'0')}:${d.getMinutes().toString().padStart(2,'0')}`
55 +
);
58 56
59 57
await createCareAction.mutateAsync({
60 58
type: 'MEDICINE',
61 59
moment: new Date(),
62 60
medicine: {
▸ 144 unchanged lines
207 205
periodicityChipLabelActive: {
208 206
fontWeight: '600',
209 207
color: Colors.light.text,
210 208
},
211 209
});
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,
▸ 20 unchanged lines
26 26
Insight,
27 27
MedicineRegimen,
28 28
MedicineRegimenResponse,
29 29
CreateMedicineRegimenPayload,
30 30
UpdateMedicineRegimenPayload,
31 +
TodayMedicineEntry,
32 +
UserPreferencesPayload,
31 33
CareAction,
32 34
CareActionType,
33 35
CareActionResponse,
34 36
CreateCareActionPayload,
35 37
PatchCareActionPayload,
▸ 318 unchanged lines
354 356
});
355 357
}
356 358
357 359
async deleteMedicineRegimen(id: string): Promise<void> {
358 360
return this.request(`/medicine-regimens/${id}`, { method: 'DELETE' });
361 +
}
362 +
363 +
async getMedicineRegimensToday(): Promise<{ regimens: TodayMedicineEntry[] }> {
364 +
return this.request('/medicine-regimens/today');
365 +
}
366 +
367 +
async patchUserMe(payload: UserPreferencesPayload): Promise<{ user: User }> {
368 +
return this.request('/users/me', {
369 +
method: 'PATCH',
370 +
body: JSON.stringify({ user: payload }),
371 +
});
359 372
}
360 373
361 374
// Care Actions
362 375
async getCareActions(
363 376
params?: {
▸ 53 unchanged lines
417 430
return this.request(`/triggers/${triggerId}/link-mood/${moodId}`, { method: 'DELETE' });
418 431
}
419 432
}
420 433
421 434
export const apiClient = new ApiClient();
frontend/lib/api/index.ts
1 1
export { apiClient } from "@/lib/api/client";
2 2
3 3
export type {
4 4
User,
5 5
AuthResponse,
▸ 28 unchanged lines
34 34
// Medicine Regimens
35 35
MedicineRegimen,
36 36
MedicineRegimenResponse,
37 37
CreateMedicineRegimenPayload,
38 38
UpdateMedicineRegimenPayload,
39 +
TodayMedicineEntry,
40 +
UserPreferencesPayload,
39 41
UpdateTriggerPayload,
40 42
// Trigger-Mood linking
41 43
TriggerMoodLink,
42 44
TriggerMoodLinkWithMood,
43 45
TriggerMoodLinkWithTrigger,
44 46
LinkMoodPayload,
45 47
} from "@/lib/api/types";
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;
6 6
updatedAt: Date;
7 7
avatarKey?: string;
8 8
avatarURL?: string;
9 9
active: boolean;
10 10
pushToken?: string;
11 +
notificationsEnabled?: boolean;
12 +
dailyReminderTime?: string;
11 13
}
12 14
13 15
// Auth
14 16
export interface AuthResponse {
15 17
token: string;
▸ 32 unchanged lines
48 50
id: number;
49 51
}
50 52
51 53
export interface UserUpdateResponse {
52 54
user: User;
55 +
}
56 +
57 +
export interface UserPreferencesPayload {
58 +
notificationsEnabled?: boolean;
59 +
dailyReminderTime?: string | null;
53 60
}
54 61
55 62
// Mood entries
56 63
export interface MoodComponentPayload {
57 64
component: string;
▸ 186 unchanged lines
244 251
export interface MedicineRegimen {
245 252
id: number;
246 253
name: string;
247 254
dosage: string;
248 255
periodicity: MedicinePeriodicity;
249 -
scheduledAt?: string;
256 +
scheduledAt: string[];
250 257
active: boolean;
251 258
userId: number;
252 259
createdAt: Date;
253 260
updatedAt: Date;
261 +
}
262 +
263 +
export interface TodayMedicineEntry {
264 +
regimen: Pick<MedicineRegimen, 'id' | 'name' | 'dosage' | 'scheduledAt'>;
265 +
logs: { id: number; takenAt: Date }[];
254 266
}
255 267
256 268
export interface MedicineLog {
257 269
id: number;
258 270
regimenId?: number;
▸ 50 unchanged lines
309 321
// Payloads
310 322
export interface CreateMedicineRegimenPayload {
311 323
name: string;
312 324
dosage: string;
313 325
periodicity: MedicinePeriodicity;
314 -
scheduledAt?: string;
326 +
scheduledAt?: string[];
315 327
}
316 328
317 329
export interface UpdateMedicineRegimenPayload extends Partial<CreateMedicineRegimenPayload> {
318 330
active?: boolean;
319 331
}
▸ 4 unchanged lines
324 336
regimenId?: number;
325 337
medicine?: {
326 338
name: string;
327 339
dosage: string;
328 340
periodicity: MedicinePeriodicity;
329 -
scheduledAt?: string
341 +
scheduledAt?: string[];
330 342
};
331 343
triggerId?: number;
332 344
moodId?: number;
333 345
}
334 346
▸ 24 unchanged lines
359 371
moodId?: number;
360 372
}
361 373
export interface MedicineRegimenResponse { regimen: MedicineRegimen; }
362 374
363 375
export interface LinkMoodPayload { moodId: number; perceivedImpact: number; }