39 lines
943 B
TypeScript
39 lines
943 B
TypeScript
import { api } from './api';
|
|
import { API_ENDPOINTS } from '@/utils/constants';
|
|
import { User, ApiResponse } from '@/types';
|
|
|
|
export interface UpdateProfileData {
|
|
firstName?: string;
|
|
lastName?: string;
|
|
phone?: string;
|
|
}
|
|
|
|
export interface ChangePasswordData {
|
|
currentPassword: string;
|
|
newPassword: string;
|
|
}
|
|
|
|
export const userService = {
|
|
// Get user profile
|
|
getProfile: async (): Promise<User> => {
|
|
const response = await api.get<ApiResponse<User>>(
|
|
API_ENDPOINTS.USER.PROFILE
|
|
);
|
|
return response.data!;
|
|
},
|
|
|
|
// Update user profile
|
|
updateProfile: async (data: UpdateProfileData): Promise<User> => {
|
|
const response = await api.put<ApiResponse<User>>(
|
|
API_ENDPOINTS.USER.UPDATE_PROFILE,
|
|
data
|
|
);
|
|
return response.data!;
|
|
},
|
|
|
|
// Change password
|
|
changePassword: async (data: ChangePasswordData): Promise<void> => {
|
|
await api.post(API_ENDPOINTS.USER.CHANGE_PASSWORD, data);
|
|
},
|
|
};
|