refactor(github): replace generateRequest with $.http
This commit is contained in:
@@ -4,7 +4,7 @@ import getCurrentUser from '../common/get-current-user';
|
|||||||
const isStillVerified = async ($: IGlobalVariable) => {
|
const isStillVerified = async ($: IGlobalVariable) => {
|
||||||
try {
|
try {
|
||||||
const user = await getCurrentUser($);
|
const user = await getCurrentUser($);
|
||||||
return !!user;
|
return !!user.id;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@@ -1,28 +0,0 @@
|
|||||||
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
|
|
||||||
import { Method } from 'axios';
|
|
||||||
|
|
||||||
type IGenereateRequestOptons = {
|
|
||||||
requestPath: string;
|
|
||||||
method: string;
|
|
||||||
data?: IJSONObject;
|
|
||||||
};
|
|
||||||
|
|
||||||
const generateRequest = async (
|
|
||||||
$: IGlobalVariable,
|
|
||||||
options: IGenereateRequestOptons
|
|
||||||
) => {
|
|
||||||
const { requestPath, method, data } = options;
|
|
||||||
|
|
||||||
const response = await $.http.request({
|
|
||||||
url: requestPath,
|
|
||||||
method: method as Method,
|
|
||||||
data,
|
|
||||||
headers: {
|
|
||||||
Authorization: `Bearer ${$.auth.data.accessToken}`
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
return response;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default generateRequest;
|
|
@@ -1,11 +1,7 @@
|
|||||||
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
|
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
|
||||||
import generateRequest from './generate-request';
|
|
||||||
|
|
||||||
const getCurrentUser = async ($: IGlobalVariable): Promise<IJSONObject> => {
|
const getCurrentUser = async ($: IGlobalVariable): Promise<IJSONObject> => {
|
||||||
const response = await generateRequest($, {
|
const response = await $.http.get('/user');
|
||||||
requestPath: '/user',
|
|
||||||
method: 'GET',
|
|
||||||
});
|
|
||||||
|
|
||||||
const currentUser = response.data;
|
const currentUser = response.data;
|
||||||
return currentUser;
|
return currentUser;
|
||||||
|
Reference in New Issue
Block a user