import { api, configWithToken, errorMiddleware, resultMiddleware } from '~/utils/api'; import { API } from '~/constants/api'; import { IMessage, INotification, IResultWithStatus } from '~/redux/types'; import { userLoginTransform } from '~/redux/auth/transforms'; import { ISocialAccount, IToken, IUser } from './types'; export const apiUserLogin = ({ username, password, }: { username: string; password: string; }): Promise> => api .post(API.USER.LOGIN, { username, password }) .then(resultMiddleware) .catch(errorMiddleware) .then(userLoginTransform); export const apiAuthGetUser = ({ access }): Promise> => api .get(API.USER.ME, configWithToken(access)) .then(resultMiddleware) .catch(errorMiddleware); export const apiAuthGetUserProfile = ({ access, username, }): Promise> => api .get(API.USER.PROFILE(username), configWithToken(access)) .then(resultMiddleware) .catch(errorMiddleware); export const apiAuthGetUserMessages = ({ access, username, }): Promise> => api .get(API.USER.MESSAGES(username), configWithToken(access)) .then(resultMiddleware) .catch(errorMiddleware); export const apiAuthSendMessage = ({ access, username, message, }): Promise> => api .post(API.USER.MESSAGE_SEND(username), { message }, configWithToken(access)) .then(resultMiddleware) .catch(errorMiddleware); export const apiAuthGetUpdates = ({ access, exclude_dialogs, last, }): Promise> => api .get(API.USER.GET_UPDATES, configWithToken(access, { params: { exclude_dialogs, last } })) .then(resultMiddleware) .catch(errorMiddleware); export const apiUpdateUser = ({ access, user }): Promise> => api .patch(API.USER.ME, user, configWithToken(access)) .then(resultMiddleware) .catch(errorMiddleware); export const apiRequestRestoreCode = ({ field }): Promise> => api .post(API.USER.REQUEST_CODE(), { field }) .then(resultMiddleware) .catch(errorMiddleware); export const apiCheckRestoreCode = ({ code }): Promise> => api .get(API.USER.REQUEST_CODE(code)) .then(resultMiddleware) .catch(errorMiddleware); export const apiRestoreCode = ({ code, password }): Promise> => api .post(API.USER.REQUEST_CODE(code), { password }) .then(resultMiddleware) .catch(errorMiddleware); export const apiGetSocials = ({ access, }: { access: string; }): Promise> => api .get(API.USER.GET_SOCIALS, configWithToken(access)) .then(resultMiddleware) .catch(errorMiddleware); export const apiDropSocial = ({ access, id, provider, }: { access: string; id: string; provider: string; }): Promise> => api .delete(API.USER.DROP_SOCIAL(provider, id), configWithToken(access)) .then(resultMiddleware) .catch(errorMiddleware); export const apiAttachSocial = ({ access, token, }: { access: string; token: string; }): Promise> => api .post(API.USER.ATTACH_SOCIAL, { token }, configWithToken(access)) .then(resultMiddleware) .catch(errorMiddleware); export const apiLoginWithSocial = ({ token, username, password, }: { token: string; username?: string; password?: string; }): Promise; needs_register: boolean; }>> => api .post(API.USER.LOGIN_WITH_SOCIAL, { token, username, password }) .then(resultMiddleware) .catch(errorMiddleware);