eletrotupi / tcc/ commit / fa18535

frontend: patch care actions + prepare for fetching trigger/moods' care actions

Pedro Lucas Porcellis porcellis@eletrotupi.com 1 month ago fa18535ea443601fc1f62853fabb636e0930bcb5
Parents: 4e6e379
3 file(s) changed
  • frontend/lib/api/client.ts +11 -0
  • frontend/lib/api/index.ts +3 -0
  • frontend/lib/api/types.ts +6 -0
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,
▸ 24 unchanged lines
30 30
  UpdateMedicineRegimenPayload,
31 31
  CareAction,
32 32
  CareActionType,
33 33
  CareActionResponse,
34 34
  CreateCareActionPayload,
35 +
  PatchCareActionPayload,
35 36
  TriggerMoodLink,
36 37
  LinkMoodPayload,
37 38
} from "@/lib/api/types";
38 39

39 40
const API_BASE_URL = process.env.EXPO_PUBLIC_API_BASE_URL;
▸ 343 unchanged lines
383 384
  }
384 385

385 386
  async createCareAction(payload: CreateCareActionPayload): Promise<CareActionResponse> {
386 387
    return this.request('/care-actions', {
387 388
      method: 'POST', body: JSON.stringify({ careAction: payload })
389 +
    });
390 +
  }
391 +

392 +
  async patchCareAction(
393 +
    id: string,
394 +
    payload: PatchCareActionPayload,
395 +
  ): Promise<CareAction> {
396 +
    return this.request(`/care-actions/${id}`, {
397 +
      method: 'PATCH',
398 +
      body: JSON.stringify({ careAction: payload }),
388 399
    });
389 400
  }
390 401

391 402
  async deleteCareAction(id: string): Promise<void> {
392 403
    return this.request(`/care-actions/${id}`, { method: 'DELETE' });
▸ 13 unchanged lines
406 417
    return this.request(`/triggers/${triggerId}/link-mood/${moodId}`, { method: 'DELETE' });
407 418
  }
408 419
}
409 420

410 421
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,
▸ 15 unchanged lines
21 21
  InsightType,
22 22
  InsightPeriod,
23 23
  // Care Actions
24 24
  CareAction,
25 25
  CareActionType,
26 +
  AppointmentType,
27 +
  ActivityType,
26 28
  CareActionResponse,
27 29
  CreateCareActionPayload,
28 30
  CreateCareActionMedicinePayload,
29 31
  CreateCareActionAppointmentPayload,
30 32
  CreateCareActionActivityPayload,
33 +
  PatchCareActionPayload,
31 34
  // Medicine Regimens
32 35
  MedicineRegimen,
33 36
  MedicineRegimenResponse,
34 37
  CreateMedicineRegimenPayload,
35 38
  UpdateMedicineRegimenPayload,
▸ 2 unchanged lines
38 41
  TriggerMoodLink,
39 42
  TriggerMoodLinkWithMood,
40 43
  TriggerMoodLinkWithTrigger,
41 44
  LinkMoodPayload,
42 45
} 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;
▸ 78 unchanged lines
84 84
  anxietyLevel: number;
85 85
  energyLevel: number;
86 86
  stressLevel: number;
87 87
  moodComponents: MoodComponent[];
88 88
  triggerLinks?: TriggerMoodLinkWithTrigger[];
89 +
  careActions?: CareAction[];
89 90
  createdAt: Date;
90 91
  updatedAt: Date;
91 92
}
92 93

93 94
// Sleep Records
▸ 23 unchanged lines
117 118
  category: string;
118 119
  moment: Date;
119 120
  createdAt: Date;
120 121
  updatedAt: Date;
121 122
  moodLinks?: TriggerMoodLinkWithMood[];
123 +
  careActions?: CareAction[];
122 124
}
123 125

124 126
export interface CreateTriggerPayload {
125 127
  comment: string;
126 128
  category: string;
▸ 223 unchanged lines
350 352
  | CreateCareActionMedicinePayload
351 353
  | CreateCareActionAppointmentPayload
352 354
  | CreateCareActionActivityPayload;
353 355

354 356
export interface CareActionResponse { careAction: CareAction; }
357 +
export interface PatchCareActionPayload {
358 +
  triggerId?: number;
359 +
  moodId?: number;
360 +
}
355 361
export interface MedicineRegimenResponse { regimen: MedicineRegimen; }
356 362

357 363
export interface LinkMoodPayload { moodId: number; perceivedImpact: number; }