import m from "mithril"
import AccessLog from "./AccessLog"

var model = {
    current: {},
    error: {},
    cariData: data => {
        model.current = {};
        model.error = {},
        m.request({
            method: 'post',
            url: '/api/siswa',
            data
        })
        .then(response => {
            model.current = response;
            AccessLog.fetch(data.src);
        })
        .catch(e => {
            if (e.code === 0) {
                model.error = {
                    message: e.message,
                    errors: {
                        siswa: ['Terjadi kesalahan saat menghubungkan ke server.'],
                    },
                };
            }
            else
                model.error = JSON.parse(e.message);
        });
    },
}

export default model;
