mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-05-01 07:36:40 +07:00
105 lines
3.1 KiB
TypeScript
105 lines
3.1 KiB
TypeScript
import { TelegramUser } from '@v9v/ts-react-telegram-login';
|
|
|
|
import {
|
|
ApiAttachSocialRequest,
|
|
ApiAttachSocialResult,
|
|
ApiAuthGetUpdatesRequest,
|
|
ApiAuthGetUpdatesResult,
|
|
ApiAuthGetUserProfileRequest,
|
|
ApiAuthGetUserProfileResult,
|
|
ApiAuthGetUserResult,
|
|
ApiCheckRestoreCodeRequest,
|
|
ApiCheckRestoreCodeResult,
|
|
ApiDropSocialRequest,
|
|
ApiDropSocialResult,
|
|
ApiGetSocialsResult,
|
|
ApiLoginWithSocialRequest,
|
|
ApiLoginWithSocialResult,
|
|
ApiRestoreCodeRequest,
|
|
ApiRestoreCodeResult,
|
|
ApiUpdatePhotoRequest,
|
|
ApiUpdateUserRequest,
|
|
ApiUpdateUserResult,
|
|
ApiUserLoginRequest,
|
|
ApiUserLoginResult,
|
|
} from '~/api/auth/types';
|
|
import { API } from '~/constants/api';
|
|
import { api, cleanResult } from '~/utils/api';
|
|
|
|
export const apiUserLogin = ({ username, password }: ApiUserLoginRequest) =>
|
|
api
|
|
.post<ApiUserLoginResult>(API.USER.LOGIN, { username, password })
|
|
.then(cleanResult);
|
|
|
|
export const apiAuthGetUser = () =>
|
|
api.get<ApiAuthGetUserResult>(API.USER.ME).then(cleanResult);
|
|
|
|
export const apiAuthGetUserProfile = ({
|
|
username,
|
|
}: ApiAuthGetUserProfileRequest) =>
|
|
api
|
|
.get<ApiAuthGetUserProfileResult>(API.USER.PROFILE(username))
|
|
.then(cleanResult);
|
|
|
|
export const apiAuthGetUpdates = ({
|
|
exclude_dialogs,
|
|
last,
|
|
}: ApiAuthGetUpdatesRequest) =>
|
|
api
|
|
.get<ApiAuthGetUpdatesResult>(API.USER.GET_UPDATES, {
|
|
params: { exclude_dialogs, last },
|
|
})
|
|
.then(cleanResult);
|
|
|
|
export const apiUpdateUser = ({ user }: ApiUpdateUserRequest) =>
|
|
api.patch<ApiUpdateUserResult>(API.USER.ME, user).then(cleanResult);
|
|
|
|
export const apiUpdatePhoto = ({ file }: ApiUpdatePhotoRequest) =>
|
|
api.post<ApiUpdateUserResult>(API.USER.UPDATE_PHOTO, file).then(cleanResult);
|
|
|
|
export const apiUpdateCover = ({ file }: ApiUpdatePhotoRequest) =>
|
|
api.post<ApiUpdateUserResult>(API.USER.UPDATE_COVER, file).then(cleanResult);
|
|
|
|
export const apiRequestRestoreCode = (field: string) =>
|
|
api
|
|
.post<{ field: string }>(API.USER.REQUEST_CODE(), { field })
|
|
.then(cleanResult);
|
|
|
|
export const apiCheckRestoreCode = ({ code }: ApiCheckRestoreCodeRequest) =>
|
|
api
|
|
.get<ApiCheckRestoreCodeResult>(API.USER.REQUEST_CODE(code))
|
|
.then(cleanResult);
|
|
|
|
export const apiRestoreCode = ({ code, password }: ApiRestoreCodeRequest) =>
|
|
api
|
|
.put<ApiRestoreCodeResult>(API.USER.REQUEST_CODE(code), { password })
|
|
.then(cleanResult);
|
|
|
|
export const apiGetSocials = () =>
|
|
api.get<ApiGetSocialsResult>(API.USER.GET_SOCIALS).then(cleanResult);
|
|
|
|
export const apiDropSocial = ({ id, provider }: ApiDropSocialRequest) =>
|
|
api
|
|
.delete<ApiDropSocialResult>(API.USER.DROP_SOCIAL(provider, id))
|
|
.then(cleanResult);
|
|
|
|
export const apiAttachSocial = ({ token }: ApiAttachSocialRequest) =>
|
|
api
|
|
.post<ApiAttachSocialResult>(API.USER.ATTACH_SOCIAL, { token })
|
|
.then(cleanResult);
|
|
|
|
export const apiLoginWithSocial = ({
|
|
token,
|
|
username,
|
|
password,
|
|
}: ApiLoginWithSocialRequest) =>
|
|
api
|
|
.put<ApiLoginWithSocialResult>(API.USER.LOGIN_WITH_SOCIAL, {
|
|
token,
|
|
username,
|
|
password,
|
|
})
|
|
.then(cleanResult);
|
|
|
|
export const apiAttachTelegram = (data: TelegramUser) =>
|
|
api.post(API.USER.ATTACH_TELEGRAM, data);
|