diff --git a/app/components/common/Note.vue b/app/components/common/Note.vue index caf3fcc..ab34776 100644 --- a/app/components/common/Note.vue +++ b/app/components/common/Note.vue @@ -31,7 +31,7 @@ let record = await $getdata("application", { first: true, }); async function save() { - await $patchapi("application", record); + await $patchapi("application", { data: record }); record = await $getdata("application", { filter: { id: props.row.id }, first: true, diff --git a/app/components/common/NoteInfo.vue b/app/components/common/NoteInfo.vue index c755ad3..a5a91ac 100644 --- a/app/components/common/NoteInfo.vue +++ b/app/components/common/NoteInfo.vue @@ -125,7 +125,7 @@ export default { data = this.$copy(this.current); data.detail = this.detail; } - let rs = data.id ? await this.$patchapi(this.api, data) : await this.$insertapi(this.api, { data }); + let rs = data.id ? await this.$patchapi(this.api, { data }) : await this.$insertapi(this.api, { data }); if (!rs) return; this.detail = undefined; if (this.current) { diff --git a/app/components/customer/Company.vue b/app/components/customer/Company.vue index 1ea7cae..26af902 100644 --- a/app/components/customer/Company.vue +++ b/app/components/customer/Company.vue @@ -270,7 +270,7 @@ async function update() { record.value.updater = store.login.id; record.update_time = new Date(); let rs = record.value.id - ? await $patchapi("company", record.value) + ? await $patchapi("company", { data: record.value }) : await $insertapi("company", { data: record.value }); if (rs === "error") return; if (!record.value.id) $snackbar(`Khách hàng đã được khởi tạo với mã ${rs.code}`, "Success"); diff --git a/app/components/customer/CustomerForm.vue b/app/components/customer/CustomerForm.vue index 9687e07..6f60d55 100644 --- a/app/components/customer/CustomerForm.vue +++ b/app/components/customer/CustomerForm.vue @@ -413,7 +413,7 @@ async function update() { let res = isNewCustomer.value ? await $insertapi("customer", { data: customerData, notify: false }) - : await $patchapi("customer", customerData, undefined, false); + : await $patchapi("customer", { data: customerData, notify: false }); if (!res || res === "error") return; const customerId = res.id; @@ -423,14 +423,20 @@ async function update() { let indPayload = $resetNull({ ...individualData.value }); indPayload.customer = customerId; if (individualData.value.id) - await $patchapi("individual", { ...indPayload, id: individualData.value.id }, undefined, false); + await $patchapi("individual", { + data: { ...indPayload, id: individualData.value.id }, + notify: false, + }); else await $insertapi("individual", { data: indPayload, notify: false }); } else if (isOrganization.value) { let orgPayload = $resetNull({ ...organizationData.value }); orgPayload.customer = customerId; let orgRes; if (organizationData.value.id) { - orgRes = await $patchapi("organization", { ...orgPayload, id: organizationData.value.id }, undefined, false); + orgRes = await $patchapi("organization", { + data: { ...orgPayload, id: organizationData.value.id }, + notify: false, + }); } else { orgRes = await $insertapi("organization", { data: orgPayload, notify: false }); } @@ -459,7 +465,7 @@ async function update() { const payload = { ...lp, ...commonPayload }; if (!match) { - $patchapi(apiName, payload); + $patchapi(apiName, { data: payload }); } }); diff --git a/app/components/datatable/MenuSave.vue b/app/components/datatable/MenuSave.vue index ebf699b..3dde4ed 100644 --- a/app/components/datatable/MenuSave.vue +++ b/app/components/datatable/MenuSave.vue @@ -185,7 +185,7 @@ async function saveSetting() { detail, update_time: new Date(), }; - result = await $patchapi("usersetting", updatedSetting); + result = await $patchapi("usersetting", { data: updatedSetting }); } isLoading.value = false; if (radioSave.value === "new") { diff --git a/app/components/dialog/ApprovalCode.vue b/app/components/dialog/ApprovalCode.vue index 25eb8d1..8c75f5b 100644 --- a/app/components/dialog/ApprovalCode.vue +++ b/app/components/dialog/ApprovalCode.vue @@ -31,12 +31,11 @@ export default { }; }, async created() { - if (!this.approvalcode && this.$store.state.login.approval_code) - this.approvalcode = this.$store.state.login.approval_code; + if (!this.approvalcode && this.$store.login.approval_code) this.approvalcode = this.$store.login.approval_code; if (!this.approvalcode) { const user = await this.$getdata("user", { first: true, - filter: { id: this.$store.state.login.id }, + filter: { id: this.$store.login.id }, }); this.approvalcode = user.approval_code; } @@ -47,7 +46,7 @@ export default { computed: { approvalcode: { get() { - return this.$store.state["approvalcode"]; + return this.$store.approvalcode; }, set(val) { this.$store.commit("updateStore", { name: "approvalcode", data: val }); diff --git a/app/components/dialog/Delete.vue b/app/components/dialog/Delete.vue index 2fc0490..4f3fbdf 100644 --- a/app/components/dialog/Delete.vue +++ b/app/components/dialog/Delete.vue @@ -46,7 +46,7 @@ export default { if (this.setdeleted) { let record = await this.$getdata(name, { first: true, filter: { id } }); record.deleted = 1; - result = await this.$patchapi(name, record); + result = await this.$patchapi(name, { data: record }); } else result = await this.$deleteapi(name, id); if (result === "error") return this.$dialog("Đã xảy ra lỗi, xóa dữ liệu thất bại", "Lỗi", "Error"); this.$snackbar("Dữ liệu đã được xoá khỏi hệ thống", "Success"); diff --git a/app/components/imports/ProductForm.vue b/app/components/imports/ProductForm.vue index 1f74675..4abce64 100644 --- a/app/components/imports/ProductForm.vue +++ b/app/components/imports/ProductForm.vue @@ -74,8 +74,10 @@ async function submit() { isPending.value = true; const res = props.variantId ? await $patchapi("Product", { - id: productVariant.value.product, - ...body.value, + data: { + id: productVariant.value.product, + ...body.value, + }, }) : await $insertapi("Product", { data: body.value }); if (res !== "error") { diff --git a/app/components/imports/ProductVariantForm.vue b/app/components/imports/ProductVariantForm.vue index 36316b8..432d91a 100644 --- a/app/components/imports/ProductVariantForm.vue +++ b/app/components/imports/ProductVariantForm.vue @@ -98,8 +98,10 @@ async function submit() { const trimmedBody = omitBy(body.value, $empty); const res = props.variantId ? await $patchapi("Product_Variant", { - id: props.variantId, - ...trimmedBody, + data: { + id: props.variantId, + ...trimmedBody, + }, }) : await $insertapi("Product_Variant", { data: trimmedBody }); if (res !== "error") { diff --git a/app/components/marketing/email/dataTemplate/SaveListTemplate.vue b/app/components/marketing/email/dataTemplate/SaveListTemplate.vue index 2eb93d7..eb0be78 100644 --- a/app/components/marketing/email/dataTemplate/SaveListTemplate.vue +++ b/app/components/marketing/email/dataTemplate/SaveListTemplate.vue @@ -170,7 +170,7 @@ const handleSave = async () => { ...props.data, name: templateName.value, }; - response = await $patchapi("Email_Template", patchData); + response = await $patchapi("Email_Template", { data: patchData }); } else { const insertData = { ...props.data, diff --git a/app/components/media/FileInfo.vue b/app/components/media/FileInfo.vue index a8204b6..38f54f3 100644 --- a/app/components/media/FileInfo.vue +++ b/app/components/media/FileInfo.vue @@ -45,7 +45,7 @@ export default { }, methods: { async save() { - let rs = await this.$patchapi("file", this.record); + let rs = await this.$patchapi("file", { data: this.record }); }, }, }; diff --git a/app/components/media/FileList.vue b/app/components/media/FileList.vue index f60d072..cd31bb5 100644 --- a/app/components/media/FileList.vue +++ b/app/components/media/FileList.vue @@ -41,7 +41,7 @@ export default { computed: { pagedata: { get() { - return this.$store.state[this.pagename1]; + return this.$store[this.pagename1]; }, set(val) { this.$store.commit("updateStore", { name: this.pagename1, data: val }); diff --git a/app/components/media/ImageCard.vue b/app/components/media/ImageCard.vue index 4a96c23..742a1d4 100644 --- a/app/components/media/ImageCard.vue +++ b/app/components/media/ImageCard.vue @@ -33,10 +33,12 @@ function editImage(image) { async function saveEditImage() { try { await $patchapi("file", { - id: editingImage.value.file, - name: editingImageName.value, - caption: editingImageCaption.value?.trim() || null, - hashtag: editingImageHashtag.value?.trim() || null, + data: { + id: editingImage.value.file, + name: editingImageName.value, + caption: editingImageCaption.value?.trim() || null, + hashtag: editingImageHashtag.value?.trim() || null, + }, }); props.loadImages(); diff --git a/app/components/parameter/ImportSetting.vue b/app/components/parameter/ImportSetting.vue index c7dd451..04259cb 100644 --- a/app/components/parameter/ImportSetting.vue +++ b/app/components/parameter/ImportSetting.vue @@ -168,7 +168,7 @@ export default { }, async saveData() { if (!this.row) return this.insertData(); - await this.$patchapi("importsetting", this.current, undefined, this.pagename); + await this.$patchapi("importsetting", { data: this.current, notify: this.pagename }); }, updateFromModel() { let filter = this.$filter(this.pagedata2.data, { diff --git a/app/components/people/PeopleInfo.vue b/app/components/people/PeopleInfo.vue index 5e99b2b..ccce926 100644 --- a/app/components/people/PeopleInfo.vue +++ b/app/components/people/PeopleInfo.vue @@ -360,7 +360,7 @@ async function update() { record.value.updater = store.login.id; record.value.updater_time = new Date(); let rs = record.value.id - ? await $patchapi("people", record.value) + ? await $patchapi("people", { data: record.value }) : await $insertapi("people", { data: record.value, notify: false }); if (rs === "error") return; if (!record.value.id) $snackbar(`Người liên quan đã được khởi tạo với mã ${rs.code}`, "Success"); diff --git a/app/components/pos/AddressForm.vue b/app/components/pos/AddressForm.vue index 71b4bda..01678f6 100644 --- a/app/components/pos/AddressForm.vue +++ b/app/components/pos/AddressForm.vue @@ -19,7 +19,7 @@ async function submitAddress() { customer: props.customerId, }; const res = props.address - ? await $patchapi("Customer_Address", payload) + ? await $patchapi("Customer_Address", { data: payload }) : await $insertapi("Customer_Address", { data: payload }); isLoading.value = false; emit("modalevent", { name: "submit" }); diff --git a/app/components/pos/composables/usePlaceOrder.js b/app/components/pos/composables/usePlaceOrder.js index 107b6f0..2b06d36 100644 --- a/app/components/pos/composables/usePlaceOrder.js +++ b/app/components/pos/composables/usePlaceOrder.js @@ -120,7 +120,12 @@ export default function usePlaceOrder({ onSuccess }) { } // update invoice.payment_status from PENDING to PAID - await $patchapi("Invoice", { id: invoiceId, payment_status: paidPaymentStatus.value.id }); + await $patchapi("Invoice", { + data: { + id: invoiceId, + payment_status: paidPaymentStatus.value.id, + }, + }); await onOrderSuccess(); } @@ -206,8 +211,10 @@ export default function usePlaceOrder({ onSuccess }) { activeCartItems.value.map((c) => c.id), ), $patchapi("Cart", { - id: activeCartItems.value[0].cart, - customer: null, + data: { + id: activeCartItems.value[0].cart, + customer: null, + }, }), ]); posStore.getCarts(); diff --git a/app/components/user/ChangePass.vue b/app/components/user/ChangePass.vue index 538a7f1..bc09c5f 100644 --- a/app/components/user/ChangePass.vue +++ b/app/components/user/ChangePass.vue @@ -48,7 +48,7 @@ async function changePassword() { let rs0 = await proxy.$insertapi("gethash", { data: { text: password.value }, notify: false }); user.password = rs0.rows[0]; - let rs = await proxy.$patchapi("user", user, undefined, false); + let rs = await proxy.$patchapi("user", { data: user, notify: false }); if (rs !== "error") { currpass.value = undefined; diff --git a/app/components/user/ConfirmCode.vue b/app/components/user/ConfirmCode.vue index b9a1818..b1cac6a 100644 --- a/app/components/user/ConfirmCode.vue +++ b/app/components/user/ConfirmCode.vue @@ -51,9 +51,9 @@ export default { methods: { async confirm() { if (this.checkError()) return this.$snackbar("Mã phê duyệt gồm 4 số từ 0-9"); - let user = await this.$getdata("user", { first: true, filter: { id: this.$store.state.login.id } }); + let user = await this.$getdata("user", { first: true, filter: { id: this.$store.login.id } }); user.approval_code = this.code; - await this.$patchapi("user", user); + await this.$patchapi("user", { data: user }); }, checkError() { if (Object.keys(this.data).length < 4) return true; diff --git a/app/components/user/SetPassword.vue b/app/components/user/SetPassword.vue index 81476d2..b89c4d5 100644 --- a/app/components/user/SetPassword.vue +++ b/app/components/user/SetPassword.vue @@ -110,7 +110,7 @@ export default { }); let rs = await this.$insertapi("gethash", { data: { text: this.password } }); user.password = rs.rows[0]; - let rs1 = await this.$patchapi("user", user); + let rs1 = await this.$patchapi("user", { data: user }); if (rs1 !== "error") this.$emit("close"); else { this.$snackbar("Có lỗi xảy ra. Hãy thử lại một lần nữa", "Error"); diff --git a/app/plugins/02-connection.js b/app/plugins/02-connection.js index c8f3663..fb4fead 100644 --- a/app/plugins/02-connection.js +++ b/app/plugins/02-connection.js @@ -132,10 +132,10 @@ export default defineNuxtPlugin((nuxtApp) => { /** * @param {ApiName} name */ - const patchapi = async function (name, data, values, notify) { + const patchapi = async function (name, { data, values, notify = true } = {}) { try { const api = findapi(name); - const curpath = api.path ? paths.find((x) => x.name === api.path).url : path; + const curpath = getpath(api.path); const updateUrl = api.url_detail || api.url; const rs = await $fetch(`${curpath}${updateUrl}${data.id}/`, { @@ -312,7 +312,7 @@ export default defineNuxtPlugin((nuxtApp) => { }; const updaterow = async function (name, data, values, pagename, notify) { - let result = await patchapi(name, data, values, notify); + let result = await patchapi(name, { data, values, notify }); if (result === "error" || !pagename || !store[pagename]) return result; let copy = cloneDeep(store[pagename]); copy.update = { refresh: true }; diff --git a/app/stores/usePosStore.js b/app/stores/usePosStore.js index 5a647d3..dd0aebe 100644 --- a/app/stores/usePosStore.js +++ b/app/stores/usePosStore.js @@ -37,8 +37,10 @@ export const usePosStore = defineStore("pos", () => { async function changeCustomer(cusId) { isChangingCus.value = true; const updatedCart = await $patchapi("Cart", { - id: activeCartId.value, - customer: cusId, + data: { + id: activeCartId.value, + customer: cusId, + }, }); await getCarts(); isChangingCus.value = false;