eletrotupi / tcc/ commit / 7822d9e

frontend: add methods to add/yeet user's avatar

Pedro Lucas Porcellis porcellis@eletrotupi.com · 5 months ago 7822d9e99b09af4dfe1e8e53c16fa9ec92016599 Browse files
Parents e44ddbf
Changed files
1
Additions
+18
Deletions
0
frontend/lib/api.ts modified+18
frontend/lib/api.ts
1 1
import * as SecureStore from 'expo-secure-store';
2 2

3 3
const API_BASE_URL = process.env.EXPO_PUBLIC_API_BASE_URL;
4 4
const TOKEN_KEY = process.env.EXPO_PUBLIC_TOKEN_KEY; // Gary B.B Coleman fucking slaps
5 5

7 7
  id: number;
8 8
  email: string;
9 9
  firstName: string;
10 10
  lastName?: string;
11 11
  updatedAt: Date;
12 +
  avatarKey?: string;
13 +
  avatarURL?: string;
12 14
}
13 15

14 16
export interface AuthResponse {
15 17
  token: string;
16 18
  user: User;
72 74

73 75
      throw new Error(error.error || `HTTP ${response.status}`);
74 76
    }
75 77

76 78
    return response.json();
79 +
  }
80 +

81 +
  async avatar(formData: FormData): Promise<void> {
82 +
    return await this.request(`/users/me/avatar`, {
83 +
      method: 'POST',
84 +
      body: formData,
85 +
      headers: {
86 +
        'Content-Type': 'multipart/form-data',
87 +
      } as any,
88 +
    })
89 +
  }
90 +

91 +
  async removeAvatar(): Promise<void> {
92 +
    return await this.request(`/users/me/avatar`, {
93 +
      method: 'DELETE'
94 +
    });
77 95
  }
78 96

79 97
  async login(email: string, password: string): Promise<AuthResponse> {
80 98
    const response = await this.request<AuthResponse>('/auth/login', {
81 99
      method: 'POST',
148 166
    })
149 167
  }
150 168
}
151 169

152 170
export const apiClient = new ApiClient();