Skip to content
Snippets Groups Projects
Commit 0a9a5e56 authored by Erwan Rouchet's avatar Erwan Rouchet Committed by Valentin Rigal
Browse files

Entypescripten the corpus API helpers

parent 2ff43432
No related branches found
No related tags found
1 merge request!1525Entypescripten the corpus API helpers
import axios from 'axios'
import { unique } from '.'
// Get all visible corpora.
export const listCorpora = unique(async () => (await axios.get('/corpus/')).data)
// Create a corpus.
export const createCorpus = async corpus => (await axios.post('/corpus/', corpus)).data
/*
* Update a single corpus.
* Expects an object with an ID.
* Fields other than the ID will be sent in the request.
*/
export const updateCorpus = async ({ id, ...data }) => (await axios.patch(`/corpus/${id}/`, data)).data
// Delete a corpus by ID
export const destroyCorpus = unique(corpusId => axios.delete(`/corpus/${corpusId}/`))
import axios from 'axios'
import { Corpus, UUID } from '@/types'
import { unique } from '.'
export const listCorpora = unique(async (): Promise<Corpus[]> => (await axios.get('/corpus/')).data)
// The name is required, everything else is optional
type CorpusEditPayload = Pick<Corpus, 'name'> & Partial<Pick<Corpus, 'description' | 'public' | 'top_level_type' | 'indexable'>>
export const createCorpus = async (corpus: CorpusEditPayload): Promise<Corpus> => (await axios.post('/corpus/', corpus)).data
export const updateCorpus = async (id: UUID, payload: CorpusEditPayload) => (await axios.patch(`/corpus/${id}/`, payload)).data
export const destroyCorpus = unique((corpusId: UUID) => axios.delete(`/corpus/${corpusId}/`))
......@@ -241,9 +241,9 @@ export const actions = {
return data
},
async update ({ state, commit, dispatch }, corpus) {
async update ({ state, commit, dispatch }, { id, ...payload }) {
if (isEmpty(state.corpora) && !state.corporaLoaded) await dispatch('$_fetch')
commit('update', await api.updateCorpus(corpus))
commit('update', await api.updateCorpus(id, payload))
},
async delete ({ state, commit, dispatch }, { id }) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment