diff --git a/frontend/src/api/cards.ts b/frontend/src/api/cards.ts index fc8819e..105969e 100644 --- a/frontend/src/api/cards.ts +++ b/frontend/src/api/cards.ts @@ -16,17 +16,38 @@ export async function newCardApi(projectId: number, tags: TagValue[]): Promise (tag.card_id = 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: tags + tags: consistant_tags }; } +export async function updateCardApi(card: Card): Promise { + 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 { const response = await api.delete(`/v1/cards/${cardID}`); @@ -36,6 +57,25 @@ export async function deleteCardApi(cardID: number): Promise { } } +export async function createCardTagApi( + cardId: number, + tagId: number, + optionId: number, + value: string +): Promise { + 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 updateCardTagApi( cardID: number, tagID: number, diff --git a/frontend/src/components/project/card/modal_card.svelte b/frontend/src/components/project/card/modal_card.svelte index 8c2ffc6..99fa0b4 100644 --- a/frontend/src/components/project/card/modal_card.svelte +++ b/frontend/src/components/project/card/modal_card.svelte @@ -1,34 +1,28 @@