1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-24 20:36:40 +07:00

fixed paths to match refactored backend

This commit is contained in:
Fedor Katurov 2022-08-22 19:06:13 +07:00
parent 1745cc636d
commit 2f6207feaa
2 changed files with 58 additions and 35 deletions

View file

@ -38,7 +38,10 @@ export type ApiGetNodeCommentsRequest = {
take?: number;
skip?: number;
};
export type ApiGetNodeCommentsResponse = { comments: IComment[]; comment_count: number };
export type ApiGetNodeCommentsResponse = {
comments: IComment[];
comment_count: number;
};
export const apiPostNode = ({ node }: ApiPostNodeRequest) =>
api.post<ApiPostNodeResult>(API.NODE.SAVE, node).then(cleanResult);
@ -66,11 +69,14 @@ export const getNodeDiff = ({
})
.then(cleanResult);
export const apiGetNode = ({ id }: ApiGetNodeRequest, config?: AxiosRequestConfig) =>
export const apiGetNode = (
{ id }: ApiGetNodeRequest,
config?: AxiosRequestConfig,
) =>
api
.get<ApiGetNodeResponse>(API.NODE.GET_NODE(id), config)
.then(cleanResult)
.then(data => ({ node: data.node, last_seen: data.last_seen }));
.then((data) => ({ node: data.node, last_seen: data.last_seen }));
export const apiGetNodeWithCancel = ({ id }: ApiGetNodeRequest) => {
const cancelToken = axios.CancelToken.source();
@ -93,7 +99,9 @@ export const apiGetNodeComments = ({
skip = 0,
}: ApiGetNodeCommentsRequest) =>
api
.get<ApiGetNodeCommentsResponse>(API.NODE.COMMENT(id), { params: { take, skip } })
.get<ApiGetNodeCommentsResponse>(API.NODE.COMMENT(id), {
params: { take, skip },
})
.then(cleanResult);
export const apiGetNodeRelated = ({ id }: ApiGetNodeRelatedRequest) =>
@ -105,20 +113,32 @@ export const apiPostNodeTags = ({ id, tags }: ApiPostNodeTagsRequest) =>
.then(cleanResult);
export const apiDeleteNodeTag = ({ id, tagId }: ApiDeleteNodeTagsRequest) =>
api.delete<ApiDeleteNodeTagsResult>(API.NODE.DELETE_TAG(id, tagId)).then(cleanResult);
api
.delete<ApiDeleteNodeTagsResult>(API.NODE.DELETE_TAG(id, tagId))
.then(cleanResult);
export const apiPostNodeLike = ({ id }: ApiPostNodeLikeRequest) =>
api.post<ApiPostNodeLikeResult>(API.NODE.POST_LIKE(id)).then(cleanResult);
export const apiPostNodeHeroic = ({ id }: ApiPostNodeHeroicRequest) =>
api.post<ApiPostNodeHeroicResponse>(API.NODE.POST_HEROIC(id)).then(cleanResult);
api
.post<ApiPostNodeHeroicResponse>(API.NODE.POST_HEROIC(id))
.then(cleanResult);
export const apiLockNode = ({ id, is_locked }: ApiLockNodeRequest) =>
api
.post<ApiLockNodeResult>(API.NODE.POST_LOCK(id), { is_locked })
.then(cleanResult);
export const apiLockComment = ({ id, isLocked, nodeId }: ApiLockCommentRequest) =>
export const apiLockComment = ({
id,
isLocked,
nodeId,
}: ApiLockCommentRequest) =>
api
.post<ApiLockcommentResult>(API.NODE.LOCK_COMMENT(nodeId, id), { is_locked: isLocked })
.delete<ApiLockcommentResult>(API.NODE.LOCK_COMMENT(nodeId, id), {
params: {
is_locked: isLocked,
},
})
.then(cleanResult);

View file

@ -5,15 +5,17 @@ import { CONFIG } from '~/utils/config';
export const API = {
BASE: CONFIG.apiHost,
USER: {
LOGIN: '/user/login',
OAUTH_WINDOW: (provider: OAuthProvider) => `${CONFIG.apiHost}oauth/${provider}/redirect`,
ME: '/user/',
PROFILE: (username: string) => `/user/user/${username}/profile`,
MESSAGES: (username: string) => `/user/user/${username}/messages`,
MESSAGE_SEND: (username: string) => `/user/user/${username}/messages`,
MESSAGE_DELETE: (username: string, id: number) => `/user/user/${username}/messages/${id}`,
GET_UPDATES: '/user/updates',
REQUEST_CODE: (code?: string) => `/user/restore/${code || ''}`,
LOGIN: '/users/login',
OAUTH_WINDOW: (provider: OAuthProvider) =>
`${CONFIG.apiHost}oauth/${provider}/redirect`,
ME: '/users/',
PROFILE: (username: string) => `/users/user/${username}/profile`,
MESSAGES: (username: string) => `/users/user/${username}/messages`,
MESSAGE_SEND: (username: string) => `/users/user/${username}/messages`,
MESSAGE_DELETE: (username: string, id: number) =>
`/users/user/${username}/messages/${id}`,
GET_UPDATES: '/users/updates',
REQUEST_CODE: (code?: string) => `/users/restore/${code || ''}`,
UPLOAD: (target, type) => `/upload/${target}/${type}`,
GET_SOCIALS: '/oauth/',
@ -22,21 +24,22 @@ export const API = {
LOGIN_WITH_SOCIAL: `/oauth/login`,
},
NODE: {
SAVE: '/node/',
GET: '/node/',
GET_DIFF: '/flow/diff',
GET_NODE: (id: number | string) => `/node/${id}`,
SAVE: '/nodes/',
GET_DIFF: '/nodes/',
GET_NODE: (id: number | string) => `/nodes/${id}`,
COMMENT: (id: INode['id'] | string) => `/node/${id}/comment`,
RELATED: (id: INode['id']) => `/node/${id}/related`,
UPDATE_TAGS: (id: INode['id']) => `/node/${id}/tags`,
DELETE_TAG: (id: INode['id'], tagId: ITag['ID']) => `/node/${id}/tags/${tagId}`,
POST_LIKE: (id: INode['id']) => `/node/${id}/like`,
POST_HEROIC: (id: INode['id']) => `/node/${id}/heroic`,
POST_LOCK: (id: INode['id']) => `/node/${id}/lock`,
RELATED: (id: INode['id']) => `/nodes/${id}/related`,
UPDATE_TAGS: (id: INode['id']) => `/nodes/${id}/tags`,
DELETE_TAG: (id: INode['id'], tagId: ITag['ID']) =>
`/nodes/${id}/tags/${tagId}`,
POST_LIKE: (id: INode['id']) => `/nodes/${id}/like`,
POST_HEROIC: (id: INode['id']) => `/nodes/${id}/heroic`,
POST_LOCK: (id: INode['id']) => `/nodes/${id}/lock`,
SET_CELL_VIEW: (id: INode['id']) => `/nodes/${id}/cell-view`,
COMMENT: (id: INode['id'] | string) => `/nodes/${id}/comment`,
LOCK_COMMENT: (id: INode['id'], comment_id: IComment['id']) =>
`/node/${id}/comment/${comment_id}/lock`,
SET_CELL_VIEW: (id: INode['id']) => `/node/${id}/cell-view`,
`/nodes/${id}/comment/${comment_id}`,
},
SEARCH: {
NODES: '/search/nodes',
@ -49,12 +52,12 @@ export const API = {
GITHUB_ISSUES: 'https://api.github.com/repos/muerwre/vault-frontend/issues',
},
TAG: {
NODES: `/tag/nodes`,
AUTOCOMPLETE: `/tag/autocomplete`,
NODES: `/tags/nodes`,
AUTOCOMPLETE: `/tags/autocomplete`,
},
LAB: {
NODES: `/lab/`,
STATS: '/lab/stats',
UPDATES: '/lab/updates',
NODES: `/nodes/lab`,
STATS: '/nodes/lab/stats',
UPDATES: '/nodes/lab/updates',
},
};