eletrotupi / tcc/ commit / f9e8c48

frontend/lib: mapping sleep & triggers api update

Pedro Lucas Porcellis porcellis@eletrotupi.com 1 month ago f9e8c48e8060613464a074cf3f6336a360a9c3c6
Parents: f57cb46
2 file(s) changed
  • frontend/lib/api/client.ts +22 -0
  • frontend/lib/api/types.ts +4 -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,
▸ 1 unchanged lines
7 7
  ResetPasswordRequestResponse,
8 8
  ResetPasswordResponse,
9 9
  UserUpdatePayload,
10 10
  CreateMoodEntryPayload,
11 11
  SleepRecordPayload,
12 +
  UpdateSleepRecordPayload,
12 13
  MoodEntry,
13 14
  SleepRecord,
14 15
  SleepRecordResponse,
15 16
  MoodEntryResponse,
16 17
  Trigger,
17 18
  TriggerResponse,
18 19
  CreateTriggerPayload,
20 +
  UpdateTriggerPayload,
19 21
  ActivateResponse,
20 22
  PaginatedResponse,
21 23
  InsightType,
22 24
  InsightPeriod,
23 25
  InsightMetadata,
▸ 220 unchanged lines
244 246

245 247
  async getSleepRecord(id: string): Promise<SleepRecord> {
246 248
    return this.request(`/sleep_records/${id}`);
247 249
  }
248 250

251 +
  async updateSleepRecord(
252 +
    id: string,
253 +
    sleepRecord: UpdateSleepRecordPayload,
254 +
  ): Promise<SleepRecordResponse> {
255 +
    return await this.request(`/sleep_records/${id}`, {
256 +
      method: "PUT",
257 +
      body: JSON.stringify({ sleepRecord }),
258 +
    });
259 +
  }
260 +

249 261
  async deleteSleepRecord(id: string): Promise<void> {
250 262
    return this.request(`/sleep_records/${id}`, { method: "DELETE" });
251 263
  }
252 264

253 265
  // Trigger
▸ 20 unchanged lines
274 286
    return this.request(`/triggers${qs ? `?${qs}` : ""}`);
275 287
  }
276 288

277 289
  async getTrigger(id: string): Promise<Trigger> {
278 290
    return this.request(`/triggers/${id}`);
291 +
  }
292 +

293 +
  async updateTrigger(
294 +
    id: string,
295 +
    trigger: UpdateTriggerPayload,
296 +
  ): Promise<TriggerResponse> {
297 +
    return await this.request(`/triggers/${id}`, {
298 +
      method: "PUT",
299 +
      body: JSON.stringify({ trigger }),
300 +
    });
279 301
  }
280 302

281 303
  async deleteTrigger(id: string): Promise<void> {
282 304
    return this.request(`/triggers/${id}`, { method: "DELETE" });
283 305
  }
▸ 13 unchanged lines
297 319
    return this.request(`/insights${qs ? `?${qs}` : ""}`);
298 320
  }
299 321
}
300 322

301 323
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;
▸ 89 unchanged lines
95 95
  average: number;
96 96
  annotations: string;
97 97
  date: Date;
98 98
}
99 99

100 +
export interface UpdateSleepRecordPayload extends Partial<SleepRecordPayload> {}
101 +

100 102
export interface SleepRecord {
101 103
  id: number;
102 104
  annotations: string;
103 105
  date: Date;
104 106
  average: number;
▸ 15 unchanged lines
120 122
export interface CreateTriggerPayload {
121 123
  comment: string;
122 124
  category: string;
123 125
  moment: Date;
124 126
}
127 +

128 +
export interface UpdateTriggerPayload extends Partial<CreateTriggerPayload> {}
125 129

126 130
// Insights
127 131

128 132
// types/insight.ts
129 133
// Gotta keep those in sync with the Prisma schema
▸ 72 unchanged lines
202 206
}
203 207

204 208
export interface TriggerResponse {
205 209
  trigger: Trigger;
206 210
}