Remote double api
This commit is contained in:
parent
a60a010bc5
commit
1156bfca40
|
@ -1,104 +0,0 @@
|
|||
import type TagValue from '$lib/types/TagValue';
|
||||
import type Card from '$lib/types/Card';
|
||||
import api, { processError } from '$lib/utils/api';
|
||||
import status from '$lib/utils/status';
|
||||
|
||||
export async function newCardApi(projectId: number, tags: TagValue[]): Promise<Card> {
|
||||
const response = await api.post(`/v1/cards`, {
|
||||
project_id: projectId,
|
||||
title: 'Untitled',
|
||||
content: ''
|
||||
});
|
||||
|
||||
if (response.status !== status.Created) {
|
||||
processError(response, 'Failed to create card');
|
||||
return Promise.reject();
|
||||
}
|
||||
|
||||
const id: number = response.data.id;
|
||||
|
||||
const consistant_tags = [];
|
||||
|
||||
for (const tag of tags) {
|
||||
if ((tag.option_id === -1 && tag.value == '') || tag.tag_id === -1) continue;
|
||||
await createCardTagApi(id, tag.tag_id, tag.option_id, tag.value);
|
||||
consistant_tags.push({ ...tag, card_id: id });
|
||||
}
|
||||
|
||||
return {
|
||||
id: id,
|
||||
project_id: projectId,
|
||||
title: 'Untitled',
|
||||
content: '',
|
||||
tags: consistant_tags
|
||||
};
|
||||
}
|
||||
|
||||
export async function updateCardApi(card: Card): Promise<boolean> {
|
||||
const response = await api.put(`/v1/cards/${card.id}`, {
|
||||
project_id: card.project_id,
|
||||
title: card.title,
|
||||
content: card.content
|
||||
});
|
||||
|
||||
if (response.status !== status.NoContent) {
|
||||
processError(response, 'Failed to update card');
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
export async function deleteCardApi(cardID: number): Promise<void> {
|
||||
const response = await api.delete(`/v1/cards/${cardID}`);
|
||||
|
||||
if (response.status !== status.NoContent) {
|
||||
processError(response, 'Failed to delete card');
|
||||
return Promise.reject();
|
||||
}
|
||||
}
|
||||
|
||||
export async function createCardTagApi(
|
||||
cardId: number,
|
||||
tagId: number,
|
||||
optionId: number | null,
|
||||
value: string | null
|
||||
): Promise<boolean> {
|
||||
const response = await api.post(`/v1/cards/${cardId}/tags/${tagId}`, {
|
||||
option_id: optionId,
|
||||
value: value
|
||||
});
|
||||
|
||||
if (response.status !== status.Created) {
|
||||
processError(response, 'Failed to create card tag');
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
export async function deleteCardTagApi(cardID: number, tagID: number): Promise<void> {
|
||||
const response = await api.delete(`/v1/cards/${cardID}/tags/${tagID}`);
|
||||
|
||||
if (response.status !== status.NoContent) {
|
||||
processError(response, 'Failed to delete tag');
|
||||
return Promise.reject();
|
||||
}
|
||||
}
|
||||
|
||||
export async function updateCardTagApi(
|
||||
cardID: number,
|
||||
tagID: number,
|
||||
option_id: number | null,
|
||||
value: string | null
|
||||
): Promise<void> {
|
||||
const response = await api.put(`/v1/cards/${cardID}/tags/${tagID}`, {
|
||||
option_id: option_id == -1 ? null : option_id,
|
||||
value: value == '' ? null : value
|
||||
});
|
||||
|
||||
if (response.status !== status.NoContent) {
|
||||
processError(response, 'Failed to update card tag');
|
||||
return Promise.reject();
|
||||
}
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
import type Card from '$lib/types/Card';
|
||||
import type Project from '$lib/types/Project';
|
||||
import api, { processError } from '$lib/utils/api';
|
||||
import { parseCards } from '$lib/utils/parser';
|
||||
import status from '$lib/utils/status';
|
||||
|
||||
export async function getProjectAPI(projectId: number): Promise<Project> {
|
||||
const response = await api.get(`/v1/projects/${projectId}`);
|
||||
|
||||
if (response.status !== status.OK) {
|
||||
processError(response, 'Failed to fetch project');
|
||||
return Promise.reject();
|
||||
}
|
||||
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export async function getProjectCardsAPI(projectId: number): Promise<Card[]> {
|
||||
const response = await api.get(`/v1/projects/${projectId}/cards`);
|
||||
|
||||
if (response.status !== status.OK) {
|
||||
processError(response, 'Failed to fetch cards');
|
||||
return Promise.reject();
|
||||
}
|
||||
|
||||
return parseCards(response.data);
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
import type TagOption from '$lib/types/TagOption';
|
||||
import api, { processError } from '$lib/utils/api';
|
||||
import status from '$lib/utils/status';
|
||||
|
||||
export async function updateTagAPI(option: TagOption): Promise<boolean> {
|
||||
const response =
|
||||
option.value === ''
|
||||
? await api.delete(`/v1/tags/${option.tag_id}/options/${option.id}`)
|
||||
: await api.put(`/v1/tags/${option.tag_id}/options/${option.id}`, option);
|
||||
|
||||
if (response.status !== status.NoContent) {
|
||||
processError(response, 'Failed to update tag option');
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
Loading…
Reference in New Issue