UNPKG

@mee4dy/crud

Version:

Create a backend and frontend in 5 minutes! With our powerful full stack crud system, customize it to suit you.

50 lines (49 loc) 1.72 kB
import { replacePK as o } from "../../common/helpers/pk.helper.js"; import { FormTypesEnum as s } from "./enums/form-types.enum.js"; const y = { async fetch({ state: f, commit: a, getters: e, dispatch: r }, t) { var l, n; if (t != null && t.pk && a("setPK", t == null ? void 0 : t.pk), e.getType !== s.edit) return; ((t == null ? void 0 : t.reset) === void 0 || t.reset) && r("reset", !0); const c = e.getEndpoint("fetch"); if (!c) return console.error('Endpoint for "fetch" not found! Please configure CrudStoreForm'); try { a("setLoading", !0); const i = o(c, e.getPK), d = await this.$axios.get(i); let u = (n = (l = d == null ? void 0 : d.data) == null ? void 0 : l.data) == null ? void 0 : n.item; return typeof f.prepareData == "function" && (u = f.prepareData(u)), u && (a("setDataDefault", u), a("setData", u)), d == null ? void 0 : d.data; } catch (i) { console.log(i); } finally { a("setLoading", !1); } }, async submit({ commit: f, dispatch: a, getters: e }) { const r = e.getEndpointSubmit; if (!r) return console.error('Endpoint for "submit" not found! Please configure CrudStoreForm'); const t = o(r, e.getPK), c = e.getPK, l = e.getData; try { f("setSending", !0); const n = await this.$axios.post(t, { pk: c || void 0, data: l }); return n == null ? void 0 : n.data; } catch (n) { console.log(n); } finally { f("setSending", !1); } }, reset({ commit: f, getters: a }, e = !1) { let r = a.getDataDefault; return e && (r = {}), f("setData", r), r; } }; export { y as default }; //# sourceMappingURL=actions.js.map