import m from "mithril"

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