import m from "mithril"

export const Choice = {
    list: [],
    current: {},
    message: "",
    error: "",
    fetchList: function() {
        m.request({
            method: "GET",
            url: "/choices"
        })
        .then(function(res) {
            Choice.list = res.data
        })
    },
    fetchCurrent: function() {
        m.request({
            method: "GET",
            url: "/choices/:id",
            data: Choice.current
        })
        .then(function(res) {
            Choice.current = res.data
        })
    },
    upload: function() {
        m.request({
            method: "POST",
            url: "/question/:qId/choices/",
            data: _.assign(Choice.current, {qId: Choice.current.question.id})
        })
    },
    update: function() {
        m.request({
            method: "PUT",
            url: "/choices/:id",
            data: Choice.current
        })
    },
    remove: function() {
        m.request({
            method: "DELETE",
            url: "/choices/:id",
            data: Choice.current
        })
    }
}
