1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 12:56:41 +07:00

added transforms and request wrappers

This commit is contained in:
muerwre 2019-08-05 16:33:03 +07:00
parent e119ae5fc4
commit cb8ca5248d
3 changed files with 68 additions and 22 deletions

View file

@ -1,22 +1,31 @@
import {api, authMiddleware, errorMiddleware, resultMiddleware} from "~/utils/api";
import { API } from "~/constants/api";
import {IResultWithStatus} from "~/redux/types";
import {authMeTransform, userLoginTransform} from "~/redux/auth/transforms";
import {IUser} from "~/redux/auth/types";
import {
api,
authMiddleware,
errorMiddleware,
resultMiddleware,
configWithToken,
} from '~/utils/api';
import { API } from '~/constants/api';
import { IResultWithStatus } from '~/redux/types';
import { authMeTransform, userLoginTransform } from '~/redux/auth/transforms';
import { IUser } from '~/redux/auth/types';
export const apiUserLogin = (
{ username, password }:
{ username: string, password: string }
): Promise<IResultWithStatus<{ token: string, status?: number }>> => (
api.post(API.USER.LOGIN, { username, password })
export const apiUserLogin = ({
username,
password,
}: {
username: string;
password: string;
}): Promise<IResultWithStatus<{ token: string; status?: number }>> =>
api
.post(API.USER.LOGIN, { username, password })
.then(resultMiddleware)
.catch(errorMiddleware)
.then(userLoginTransform)
);
.then(userLoginTransform);
export const getAuthSelf = (): Promise<IResultWithStatus<{ user: IUser }>> => (
api.get(API.USER.ME)
export const getAuthSelf = ({ access }): Promise<IResultWithStatus<{ user: IUser }>> =>
api
.get(API.USER.ME, configWithToken(access))
.then(resultMiddleware)
.catch(errorMiddleware)
.then(authMeTransform)
);
.then(authMeTransform);