From 2a1f85c2af82a12a73d2a3321f9526d07177cc04 Mon Sep 17 00:00:00 2001 From: Viet An Date: Thu, 4 Jun 2026 13:57:27 +0700 Subject: [PATCH] changes --- app/components/common/ActionInfo.vue | 4 +-- app/components/common/NoteInfo.vue | 2 +- app/components/customer/Company.vue | 4 ++- app/components/customer/CustomerForm.vue | 18 +++++----- app/components/customer/CustomerQuickAdd.vue | 2 +- app/components/datatable/MenuSave.vue | 2 +- app/components/imports/AddIMEIForm.vue | 2 +- app/components/imports/ProductForm.vue | 2 +- app/components/imports/ProductVariantForm.vue | 8 +++-- .../imports/ProductVariantFormNew.vue | 8 +++-- app/components/imports/addons/AddBattery.vue | 2 +- app/components/imports/addons/AddCPU.vue | 2 +- app/components/imports/addons/AddCamera.vue | 2 +- .../imports/addons/AddChargingTechnology.vue | 2 +- app/components/imports/addons/AddColor.vue | 2 +- app/components/imports/addons/AddDesign.vue | 2 +- .../imports/addons/AddExternalStorage.vue | 2 +- app/components/imports/addons/AddGPU.vue | 2 +- app/components/imports/addons/AddIPRating.vue | 2 +- .../imports/addons/AddInternalStorage.vue | 2 +- .../imports/addons/AddManufacturer.vue | 2 +- .../imports/addons/AddNetworkTechnology.vue | 2 +- app/components/imports/addons/AddOS.vue | 2 +- app/components/imports/addons/AddRAM.vue | 2 +- app/components/imports/addons/AddSIM.vue | 2 +- app/components/imports/addons/AddScreen.vue | 2 +- .../email/dataTemplate/SaveListTemplate.vue | 2 +- .../marketing/email/forms/EmailForm1.vue | 10 +++--- .../marketing/email/viewEmail/ViewEmail.vue | 10 +++--- app/components/media/Camera.vue | 2 +- app/components/media/CropImage.vue | 2 +- app/components/media/FileGallery.vue | 2 +- app/components/media/FileList.vue | 2 +- app/components/media/ImageGallery.vue | 2 +- app/components/media/ImageLayout.vue | 2 +- app/components/media/Imagebox.vue | 4 +-- app/components/media/UploadProgress.vue | 2 +- app/components/parameter/ImportData.vue | 30 ++++++++--------- app/components/people/PeopleInfo.vue | 4 +-- app/components/user/ChangePass.vue | 2 +- app/components/user/EditUser.vue | 2 +- app/components/user/NewUser.vue | 4 +-- app/components/user/SetPassword.vue | 2 +- app/plugins/02-connection.js | 33 ++++++++++--------- 44 files changed, 99 insertions(+), 102 deletions(-) diff --git a/app/components/common/ActionInfo.vue b/app/components/common/ActionInfo.vue index d8ce46a..c52f4e0 100644 --- a/app/components/common/ActionInfo.vue +++ b/app/components/common/ActionInfo.vue @@ -315,8 +315,8 @@ async function update() { data.link = arr1.length === 0 ? null : arr1; let api = $findapi("useraction"); record = data.id - ? await $updateapi("useraction", data, api.params.values) - : await $insertapi("useraction", data, api.params.values); + ? await $updateapi("useraction", { data, values: api.params.values }) + : await $insertapi("useraction", { data, values: api.params.values }); getValue(); } async function removeImage(v, i) { diff --git a/app/components/common/NoteInfo.vue b/app/components/common/NoteInfo.vue index 85afcd7..0c2261e 100644 --- a/app/components/common/NoteInfo.vue +++ b/app/components/common/NoteInfo.vue @@ -119,7 +119,7 @@ export default { data = this.$copy(this.current); data.detail = this.detail; } - let rs = data.id ? await this.$updateapi(this.api, data) : await this.$insertapi(this.api, data); + let rs = data.id ? await this.$updateapi(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 b8b43b8..453f493 100644 --- a/app/components/customer/Company.vue +++ b/app/components/customer/Company.vue @@ -270,7 +270,9 @@ async function update() { if (!record.value.creator) record.value.creator = store.login.id; record.value.updater = store.login.id; record.update_time = new Date(); - let rs = record.value.id ? await $updateapi("company", record.value) : await $insertapi("company", record.value); + let rs = record.value.id + ? await $updateapi("company", 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"); record.value.id = rs.id; diff --git a/app/components/customer/CustomerForm.vue b/app/components/customer/CustomerForm.vue index 3590339..32d1a14 100644 --- a/app/components/customer/CustomerForm.vue +++ b/app/components/customer/CustomerForm.vue @@ -567,7 +567,7 @@ async function update() { customerData.update_time = new Date(); let res = isNewCustomer.value - ? await $insertapi("customer", customerData, undefined, false) + ? await $insertapi("customer", { data: customerData, notify: false }) : await $patchapi("customer", customerData, undefined, false); if (!res || res === "error") return; @@ -579,7 +579,7 @@ async function update() { indPayload.customer = customerId; if (individualData.value.id) await $patchapi("individual", { ...indPayload, id: individualData.value.id }, undefined, false); - else await $insertapi("individual", indPayload, undefined, false); + else await $insertapi("individual", { data: indPayload, notify: false }); } else if (isOrganization.value) { let orgPayload = $resetNull({ ...organizationData.value }); orgPayload.customer = customerId; @@ -587,7 +587,7 @@ async function update() { if (organizationData.value.id) { orgRes = await $patchapi("organization", { ...orgPayload, id: organizationData.value.id }, undefined, false); } else { - orgRes = await $insertapi("organization", orgPayload, undefined, false); + orgRes = await $insertapi("organization", { data: orgPayload, notify: false }); } if (orgRes && orgRes.id) { organizationId = orgRes.id; @@ -622,7 +622,7 @@ async function update() { validLocalPeople.forEach((lp) => { if (!lp.id) { const payload = { ...lp, ...commonPayload }; - $insertapi(apiName, payload); + $insertapi(apiName, { data: payload }); } }); @@ -638,12 +638,10 @@ async function update() { // Ảnh if (record.value.image && record.value.image.length > 0) { - await $insertapi( - "customerfile", - record.value.image.map((v) => ({ ref: customerId, file: v })), - undefined, - false, - ); + await $insertapi("customerfile", { + data: record.value.image.map((v) => ({ ref: customerId, file: v })), + notify: false, + }); } const completeData = await $getdata("customer", { id: customerId }, undefined, true); diff --git a/app/components/customer/CustomerQuickAdd.vue b/app/components/customer/CustomerQuickAdd.vue index d0b1d36..f270ac8 100644 --- a/app/components/customer/CustomerQuickAdd.vue +++ b/app/components/customer/CustomerQuickAdd.vue @@ -169,7 +169,7 @@ async function createCustomer() { } const customerData = $resetNull({ ...record.value }); - const res = await $insertapi("customer", customerData, undefined, false); + const res = await $insertapi("customer", { data: customerData, notify: false }); if (!res || res === "error") return; const completedData = await $getdata("customer", { diff --git a/app/components/datatable/MenuSave.vue b/app/components/datatable/MenuSave.vue index 58f0a52..fb22675 100644 --- a/app/components/datatable/MenuSave.vue +++ b/app/components/datatable/MenuSave.vue @@ -162,7 +162,7 @@ async function saveSetting() { msg: "Tên thiết lập không được bỏ trống", }); } - result = await $insertapi("usersetting", data); + result = await $insertapi("usersetting", { data }); } else { const updatedSetting = { ...$copy(currentsetting), diff --git a/app/components/imports/AddIMEIForm.vue b/app/components/imports/AddIMEIForm.vue index 13308f1..ab70cfe 100644 --- a/app/components/imports/AddIMEIForm.vue +++ b/app/components/imports/AddIMEIForm.vue @@ -13,7 +13,7 @@ const body = ref({ async function submit() { isLoading.value = true; - const res = await $insertapi("IMEI", body.value); + const res = await $insertapi("IMEI", { data: body.value }); isLoading.value = false; if (res !== "error") { emit("created"); diff --git a/app/components/imports/ProductForm.vue b/app/components/imports/ProductForm.vue index 73b0b0d..cd2c0d0 100644 --- a/app/components/imports/ProductForm.vue +++ b/app/components/imports/ProductForm.vue @@ -81,7 +81,7 @@ async function submit() { id: productVariant.value.product, ...body.value, }) - : await $insertapi("product", body.value); + : await $insertapi("product", { data: body.value }); if (res !== "error") { if (refreshData) refreshData(); } diff --git a/app/components/imports/ProductVariantForm.vue b/app/components/imports/ProductVariantForm.vue index f9a840e..078f57a 100644 --- a/app/components/imports/ProductVariantForm.vue +++ b/app/components/imports/ProductVariantForm.vue @@ -86,8 +86,10 @@ async function submit() { // 1. insert row to Product_Image, get back id if (uploadedImage.value) { const productImage = await $insertapi("Product_Image", { - name: uploadedImage.value.name, - path: $buildFileUrl(uploadedImage.value.file), + data: { + name: uploadedImage.value.name, + path: $buildFileUrl(uploadedImage.value.file), + }, }); body.value.image = productImage.id; } @@ -99,7 +101,7 @@ async function submit() { id: props.variantId, ...trimmedBody, }) - : await $insertapi("Product_Variant", trimmedBody); + : await $insertapi("Product_Variant", { data: trimmedBody }); if (res !== "error") { if (refreshData) refreshData(); } diff --git a/app/components/imports/ProductVariantFormNew.vue b/app/components/imports/ProductVariantFormNew.vue index cb915eb..57e1a9c 100644 --- a/app/components/imports/ProductVariantFormNew.vue +++ b/app/components/imports/ProductVariantFormNew.vue @@ -47,15 +47,17 @@ async function submit() { // 1. insert row to Product_Image, get back id if (uploadedImage.value) { const productImage = await $insertapi("Product_Image", { - name: uploadedImage.value.name, - path: $buildFileUrl(uploadedImage.value.file), + data: { + name: uploadedImage.value.name, + path: $buildFileUrl(uploadedImage.value.file), + }, }); body.value.image = productImage.id; } // 2. upload to Product_Variant table const trimmedBody = omitBy(body.value, $empty); - const res = await $insertapi("Product_Variant", trimmedBody); + const res = await $insertapi("Product_Variant", { data: trimmedBody }); if (res !== "error") { if (refreshData) refreshData(); } diff --git a/app/components/imports/addons/AddBattery.vue b/app/components/imports/addons/AddBattery.vue index d18b361..60ded2b 100644 --- a/app/components/imports/addons/AddBattery.vue +++ b/app/components/imports/addons/AddBattery.vue @@ -11,7 +11,7 @@ const body = ref({ async function submit() { isLoading.value = true; - const newRow = await $insertapi("Battery", body.value); + const newRow = await $insertapi("Battery", { data: body.value }); emit("modalevent", { name: "dataevent", data: newRow }); isLoading.value = false; } diff --git a/app/components/imports/addons/AddCPU.vue b/app/components/imports/addons/AddCPU.vue index 4419364..057f50d 100644 --- a/app/components/imports/addons/AddCPU.vue +++ b/app/components/imports/addons/AddCPU.vue @@ -11,7 +11,7 @@ const body = ref({ async function submit() { isLoading.value = true; - const newRow = await $insertapi("CPU", body.value); + const newRow = await $insertapi("CPU", { data: body.value }); emit("modalevent", { name: "dataevent", data: newRow }); isLoading.value = false; } diff --git a/app/components/imports/addons/AddCamera.vue b/app/components/imports/addons/AddCamera.vue index 56428d2..489193e 100644 --- a/app/components/imports/addons/AddCamera.vue +++ b/app/components/imports/addons/AddCamera.vue @@ -11,7 +11,7 @@ const body = ref({ async function submit() { isLoading.value = true; - const newRow = await $insertapi("Camera_System", body.value); + const newRow = await $insertapi("Camera_System", { data: body.value }); emit("modalevent", { name: "dataevent", data: newRow }); isLoading.value = false; } diff --git a/app/components/imports/addons/AddChargingTechnology.vue b/app/components/imports/addons/AddChargingTechnology.vue index 64995fe..aeee127 100644 --- a/app/components/imports/addons/AddChargingTechnology.vue +++ b/app/components/imports/addons/AddChargingTechnology.vue @@ -11,7 +11,7 @@ const body = ref({ async function submit() { isLoading.value = true; - const newRow = await $insertapi("Charging_Technology", body.value); + const newRow = await $insertapi("Charging_Technology", { data: body.value }); emit("modalevent", { name: "dataevent", data: newRow }); isLoading.value = false; } diff --git a/app/components/imports/addons/AddColor.vue b/app/components/imports/addons/AddColor.vue index 977a5c5..b00427c 100644 --- a/app/components/imports/addons/AddColor.vue +++ b/app/components/imports/addons/AddColor.vue @@ -11,7 +11,7 @@ const body = ref({ async function submit() { isLoading.value = true; - const newRow = await $insertapi("Color", body.value); + const newRow = await $insertapi("Color", { data: body.value }); emit("modalevent", { name: "dataevent", data: newRow }); isLoading.value = false; } diff --git a/app/components/imports/addons/AddDesign.vue b/app/components/imports/addons/AddDesign.vue index ac82d4d..e449a53 100644 --- a/app/components/imports/addons/AddDesign.vue +++ b/app/components/imports/addons/AddDesign.vue @@ -11,7 +11,7 @@ const body = ref({ async function submit() { isLoading.value = true; - const newRow = await $insertapi("Design", body.value); + const newRow = await $insertapi("Design", { data: body.value }); emit("modalevent", { name: "dataevent", data: newRow }); isLoading.value = false; } diff --git a/app/components/imports/addons/AddExternalStorage.vue b/app/components/imports/addons/AddExternalStorage.vue index 98f5cf4..3584ce5 100644 --- a/app/components/imports/addons/AddExternalStorage.vue +++ b/app/components/imports/addons/AddExternalStorage.vue @@ -10,7 +10,7 @@ const body = ref({ async function submit() { isLoading.value = true; - const newRow = await $insertapi("External_Storage", body.value); + const newRow = await $insertapi("External_Storage", { data: body.value }); emit("modalevent", { name: "dataevent", data: newRow }); isLoading.value = false; } diff --git a/app/components/imports/addons/AddGPU.vue b/app/components/imports/addons/AddGPU.vue index e953efd..f89d1fe 100644 --- a/app/components/imports/addons/AddGPU.vue +++ b/app/components/imports/addons/AddGPU.vue @@ -10,7 +10,7 @@ const body = ref({ async function submit() { isLoading.value = true; - const newRow = await $insertapi("GPU", body.value); + const newRow = await $insertapi("GPU", { data: body.value }); emit("modalevent", { name: "dataevent", data: newRow }); isLoading.value = false; } diff --git a/app/components/imports/addons/AddIPRating.vue b/app/components/imports/addons/AddIPRating.vue index 10e3850..171f3b2 100644 --- a/app/components/imports/addons/AddIPRating.vue +++ b/app/components/imports/addons/AddIPRating.vue @@ -10,7 +10,7 @@ const body = ref({ async function submit() { isLoading.value = true; - const newRow = await $insertapi("IP_Rating", body.value); + const newRow = await $insertapi("IP_Rating", { data: body.value }); emit("modalevent", { name: "dataevent", data: newRow }); isLoading.value = false; } diff --git a/app/components/imports/addons/AddInternalStorage.vue b/app/components/imports/addons/AddInternalStorage.vue index dec88af..aeb7c4b 100644 --- a/app/components/imports/addons/AddInternalStorage.vue +++ b/app/components/imports/addons/AddInternalStorage.vue @@ -12,7 +12,7 @@ const body = ref({ async function submit() { isLoading.value = true; - const newRow = await $insertapi("Internal_Storage", body.value); + const newRow = await $insertapi("Internal_Storage", { data: body.value }); emit("modalevent", { name: "dataevent", data: newRow }); isLoading.value = false; } diff --git a/app/components/imports/addons/AddManufacturer.vue b/app/components/imports/addons/AddManufacturer.vue index 43812f6..9659efb 100644 --- a/app/components/imports/addons/AddManufacturer.vue +++ b/app/components/imports/addons/AddManufacturer.vue @@ -10,7 +10,7 @@ const body = ref({ async function submit() { isLoading.value = true; - const newRow = await $insertapi("Manufacturer", body.value); + const newRow = await $insertapi("Manufacturer", { data: body.value }); emit("modalevent", { name: "dataevent", data: newRow }); isLoading.value = false; } diff --git a/app/components/imports/addons/AddNetworkTechnology.vue b/app/components/imports/addons/AddNetworkTechnology.vue index 17c2ad7..8754f1a 100644 --- a/app/components/imports/addons/AddNetworkTechnology.vue +++ b/app/components/imports/addons/AddNetworkTechnology.vue @@ -10,7 +10,7 @@ const body = ref({ async function submit() { isLoading.value = true; - const newRow = await $insertapi("Network_Technology", body.value); + const newRow = await $insertapi("Network_Technology", { data: body.value }); emit("modalevent", { name: "dataevent", data: newRow }); isLoading.value = false; } diff --git a/app/components/imports/addons/AddOS.vue b/app/components/imports/addons/AddOS.vue index f13cd85..a96538b 100644 --- a/app/components/imports/addons/AddOS.vue +++ b/app/components/imports/addons/AddOS.vue @@ -11,7 +11,7 @@ const body = ref({ async function submit() { isLoading.value = true; - const newRow = await $insertapi("OS", body.value); + const newRow = await $insertapi("OS", { data: body.value }); emit("modalevent", { name: "dataevent", data: newRow }); isLoading.value = false; diff --git a/app/components/imports/addons/AddRAM.vue b/app/components/imports/addons/AddRAM.vue index 33663ce..8890751 100644 --- a/app/components/imports/addons/AddRAM.vue +++ b/app/components/imports/addons/AddRAM.vue @@ -12,7 +12,7 @@ const body = ref({ async function submit() { isLoading.value = true; - const newRow = await $insertapi("RAM", body.value); + const newRow = await $insertapi("RAM", { data: body.value }); emit("modalevent", { name: "dataevent", data: newRow }); isLoading.value = false; } diff --git a/app/components/imports/addons/AddSIM.vue b/app/components/imports/addons/AddSIM.vue index 78a6801..6c6a5c8 100644 --- a/app/components/imports/addons/AddSIM.vue +++ b/app/components/imports/addons/AddSIM.vue @@ -13,7 +13,7 @@ const body = ref({ async function submit() { isLoading.value = true; - const newRow = await $insertapi("SIM", body.value); + const newRow = await $insertapi("SIM", { data: body.value }); emit("modalevent", { name: "dataevent", data: newRow }); isLoading.value = false; } diff --git a/app/components/imports/addons/AddScreen.vue b/app/components/imports/addons/AddScreen.vue index d4b6e27..542262c 100644 --- a/app/components/imports/addons/AddScreen.vue +++ b/app/components/imports/addons/AddScreen.vue @@ -16,7 +16,7 @@ const body = ref({ async function submit() { isLoading.value = true; - const newRow = await $insertapi("Screen", body.value); + const newRow = await $insertapi("Screen", { data: body.value }); emit("modalevent", { name: "dataevent", data: newRow }); isLoading.value = false; } diff --git a/app/components/marketing/email/dataTemplate/SaveListTemplate.vue b/app/components/marketing/email/dataTemplate/SaveListTemplate.vue index 0976acd..6e48053 100644 --- a/app/components/marketing/email/dataTemplate/SaveListTemplate.vue +++ b/app/components/marketing/email/dataTemplate/SaveListTemplate.vue @@ -176,7 +176,7 @@ const handleSave = async () => { ...props.data, name: templateName.value, }; - response = await $insertapi("Email_Template", insertData); + response = await $insertapi("Email_Template", { data: insertData }); } if (response && response !== "error") { diff --git a/app/components/marketing/email/forms/EmailForm1.vue b/app/components/marketing/email/forms/EmailForm1.vue index 2d31086..31266bd 100644 --- a/app/components/marketing/email/forms/EmailForm1.vue +++ b/app/components/marketing/email/forms/EmailForm1.vue @@ -533,16 +533,14 @@ const handleSendEmail = async () => { }); } - const response = await nuxtApp.$insertapi( - "sendemail", - { + const response = await nuxtApp.$insertapi("sendemail", { + data: { to: formData.value.content.receiver, content: finalEmailHtml, subject: formData.value.content.subject || "Thông báo từ BigDataTech", }, - undefined, - false, - ); + notify: false, + }); if (response !== null) { $snackbar(`Email sent successfully! Sent to ${formData.value.content.receiver.split(";").length} recipient(s)`); diff --git a/app/components/marketing/email/viewEmail/ViewEmail.vue b/app/components/marketing/email/viewEmail/ViewEmail.vue index 5c2b6b5..ae91d2b 100644 --- a/app/components/marketing/email/viewEmail/ViewEmail.vue +++ b/app/components/marketing/email/viewEmail/ViewEmail.vue @@ -173,16 +173,14 @@ const handleSendEmail = async () => { }); } - const response = await $insertapi( - "sendemail", - { + const response = await $insertapi("sendemail", { + data: { to: paymentScheduleItem.value?.txn_detail__transaction__customer__email, content: finalEmailHtml, subject: replaceTemplateVars(templateProps.value.content.subject) || "Thông báo từ Utopia Villas & Resort", }, - undefined, - false, - ); + notify: false, + }); if (response !== null) { isLoading.value = false; $snackbar( diff --git a/app/components/media/Camera.vue b/app/components/media/Camera.vue index b558541..9fa880b 100644 --- a/app/components/media/Camera.vue +++ b/app/components/media/Camera.vue @@ -83,7 +83,7 @@ export default { form.append("type", "image"); form.append("size", 100); form.append("user", this.$store.state.login.id); - let result = await this.$insertapi("upload", form); + let result = await this.$insertapi("upload", { data: form }); if (result === "error") return; let row = result.rows[0]; const file = new File([blod], name, { type: "image/png" }); diff --git a/app/components/media/CropImage.vue b/app/components/media/CropImage.vue index bc34aaf..a022eb8 100644 --- a/app/components/media/CropImage.vue +++ b/app/components/media/CropImage.vue @@ -129,7 +129,7 @@ export default { form.append("type", "file"); form.append("size", this.selected.size); form.append("user", this.$store.state.login.id); - let result = await this.$insertapi("upload", form); + let result = await this.$insertapi("upload", { data: form }); this.loading = false; if (result === "error") return; this.$emit("modalevent", { name: "image", data: result.rows[0] }); diff --git a/app/components/media/FileGallery.vue b/app/components/media/FileGallery.vue index 3b53a29..016343c 100644 --- a/app/components/media/FileGallery.vue +++ b/app/components/media/FileGallery.vue @@ -70,7 +70,7 @@ export default { return { ref: this.row.id, file: v.id }; }); let found = this.$findapi(this.api); - let rs = await this.$insertapi(this.api, arr, found.params.values); + let rs = await this.$insertapi(this.api, { data: arr, values: found.params.values }); if (rs !== "error") { this.files = this.files.concat(rs); this.vbind = undefined; diff --git a/app/components/media/FileList.vue b/app/components/media/FileList.vue index 0f057d9..2dc74e4 100644 --- a/app/components/media/FileList.vue +++ b/app/components/media/FileList.vue @@ -54,7 +54,7 @@ export default { return { ref: this.row.id, file: v.id }; }); let found = this.$findapi(this.api); - let rs = await this.$insertapi(this.api, arr, found.params.values); + let rs = await this.$insertapi(this.api, { data: arr, values: found.params.values }); if (rs === "error") return; this.files = this.files.concat(rs); this.$store.commit("updateState", { diff --git a/app/components/media/ImageGallery.vue b/app/components/media/ImageGallery.vue index b2c155a..7c4f521 100644 --- a/app/components/media/ImageGallery.vue +++ b/app/components/media/ImageGallery.vue @@ -80,7 +80,7 @@ export default { return { ref: this.row.id, file: v.id }; }); let found = this.$findapi(this.api); - let rs = await this.$insertapi(this.api, arr, found.params.values); + let rs = await this.$insertapi(this.api, { data: arr, values: found.params.values }); if (rs === "error") return; this.files = this.files.concat(rs); if (this.pagename) { diff --git a/app/components/media/ImageLayout.vue b/app/components/media/ImageLayout.vue index 50c5c29..4e305d5 100644 --- a/app/components/media/ImageLayout.vue +++ b/app/components/media/ImageLayout.vue @@ -275,7 +275,7 @@ async function attachFiles(files) { product: isForProduct.value ? product.id : undefined, })); - const result = await $insertapi(isForProduct.value ? "productfile" : "projectfile", payload); + const result = await $insertapi(isForProduct.value ? "productfile" : "projectfile", { data: payload }); if (result === "error") { throw new Error("Không thể liên kết tệp"); } diff --git a/app/components/media/Imagebox.vue b/app/components/media/Imagebox.vue index a5c5df2..a32a67d 100644 --- a/app/components/media/Imagebox.vue +++ b/app/components/media/Imagebox.vue @@ -349,14 +349,14 @@ export default { form.append("type", "image"); form.append("size", 100); form.append("user", this.$store.login.id); - let result = await this.$insertapi("upload", form); + let result = await this.$insertapi("upload", { data: form }); if (result === "error") return; this.updateImage(result.rows[0]); this.showUrl = false; }, async uploadImage(file) { this.loading = true; - let result = await this.$insertapi("upload", file.form); + let result = await this.$insertapi("upload", { data: file.form }); this.data.splice(0, 0, result.rows[0]); this.loading = false; }, diff --git a/app/components/media/UploadProgress.vue b/app/components/media/UploadProgress.vue index 957c718..47277eb 100644 --- a/app/components/media/UploadProgress.vue +++ b/app/components/media/UploadProgress.vue @@ -56,7 +56,7 @@ if (!found) upload(); async function doUpload(v, i) { const file = props.files[i]; - const rs = await $insertapi("upload", file.form, undefined, false); + const rs = await $insertapi("upload", { data: file.form, notify: false }); v.status = rs === "error" ? "error" : "success"; vfiles.value[i] = v; const obj = rs.rows[0]; diff --git a/app/components/parameter/ImportData.vue b/app/components/parameter/ImportData.vue index ac39bfb..34f0f23 100644 --- a/app/components/parameter/ImportData.vue +++ b/app/components/parameter/ImportData.vue @@ -205,7 +205,7 @@ export default { this.msgInfo.push({ message, type: "error" }); return (this.isloading = false); } - let result = await this.$insertapi("upload", thefile.form, undefined, false); + let result = await this.$insertapi("upload", { data: thefile.form, notify: false }); if (result === "error") { const message = this.$find( this.$store.syspara, @@ -393,7 +393,7 @@ export default { }; try { - const rs = await this.$insertapi("findkey", payload, undefined, false); + const rs = await this.$insertapi("findkey", { data: payload, notify: false }); if (rs === "error") throw new Error(); else { this.data = rs.data; @@ -539,7 +539,7 @@ export default { file: this.fileInfo.name, fields: this.setting.detail, }; - await this.$insertapi("importlog", importLogPayload); + await this.$insertapi("importlog", { data: importLogPayload }); const interval = setInterval(() => this.getResult(importLogPayload.code), 2000); // Lọc bản ghi KHÔNG có id (bản ghi mới) @@ -553,14 +553,12 @@ export default { // Gửi lên API - Backend sẽ INSERT let result; if (this.setting.call_api) { - result = await this.$insertapi( - this.setting.call_api, - { data: filter, user: this.$store.login.id }, - undefined, - importLogPayload.code, - ); + result = await this.$insertapi(this.setting.call_api, { + data: { data: filter, user: this.$store.login.id }, + notify: importLogPayload.code, + }); } else { - result = await this.$insertapi(this.setting.api, filter, undefined, importLogPayload.code); + result = await this.$insertapi(this.setting.api, { data: filter, notify: importLogPayload.code }); } this.isloading = false; @@ -640,7 +638,7 @@ export default { file: this.fileInfo.name, fields: this.setting.detail, }; - await this.$insertapi("importlog", importlogPayload); + await this.$insertapi("importlog", { data: importlogPayload }); const interval = setInterval(() => this.getResult(importlogPayload.code), 2000); // Lọc bản ghi CÓ id (bản ghi tồn tại) VÀ KHÔNG CÓ LỖI @@ -652,12 +650,10 @@ export default { this.total = filter.length; // Gửi lên API - Backend sẽ UPDATE - const result = await this.$insertapi( - this.setting.call_api || this.setting.api, - filter, - undefined, - importlogPayload.code, - ); + const result = await this.$insertapi(this.setting.call_api || this.setting.api, { + data: filter, + notify: importlogPayload.code, + }); this.isloading = false; clearInterval(interval); this.getResult(importlogPayload.code); diff --git a/app/components/people/PeopleInfo.vue b/app/components/people/PeopleInfo.vue index b70724b..3be7a2d 100644 --- a/app/components/people/PeopleInfo.vue +++ b/app/components/people/PeopleInfo.vue @@ -362,14 +362,14 @@ async function update() { record.value.updater_time = new Date(); let rs = record.value.id ? await $updateapi("people", record.value) - : await $insertapi("people", record.value, undefined, false); + : 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"); record.value.id = rs.id; if (record.value.image ? record.value.image.length > 0 : false) { let arr = []; record.image.map((v) => arr.push({ ref: record.value.id, file: v })); - await $insertapi("customerfile", arr, undefined, false); + await $insertapi("customerfile", { data: arr, notify: false }); } let ele = await $getdata("people", { first: true, filter: { id: rs.id } }); emit("update", ele); diff --git a/app/components/user/ChangePass.vue b/app/components/user/ChangePass.vue index 44c08b8..c49e635 100644 --- a/app/components/user/ChangePass.vue +++ b/app/components/user/ChangePass.vue @@ -158,7 +158,7 @@ export default { name: "currpass", text: "Incorrect password.", }); - let rs0 = await this.$insertapi("gethash", { text: this.password }, undefined, false); + let rs0 = await this.$insertapi("gethash", { data: { text: this.password }, notify: false }); user.password = rs0.rows[0]; let rs = await this.$updateapi("user", user, undefined, false); if (rs !== "error") { diff --git a/app/components/user/EditUser.vue b/app/components/user/EditUser.vue index d1fb48a..26b94fb 100644 --- a/app/components/user/EditUser.vue +++ b/app/components/user/EditUser.vue @@ -169,7 +169,7 @@ export default { }); if (rows.length === 0) return; rows.forEach((v) => (v.expiry = 1)); - this.$insertapi("token", rows, undefined, true); + this.$insertapi("token", { data: rows }); }, }, }; diff --git a/app/components/user/NewUser.vue b/app/components/user/NewUser.vue index 5065f69..0d33f57 100644 --- a/app/components/user/NewUser.vue +++ b/app/components/user/NewUser.vue @@ -319,7 +319,7 @@ export default { }, async createAccount() { if (this.checkError()) return; - let rs = await this.$insertapi("gethash", { text: this.password }); + let rs = await this.$insertapi("gethash", { data: { text: this.password } }); this.hash = rs.rows[0]; let data = await this.$getdata("user", { first: true, filter: { username: this.username } }); if (data) { @@ -342,7 +342,7 @@ export default { if (this.user === "error") return; // add rights //let arr = this.$filter(this.common, {category: 'topmenu'}).map(v=>{return {user: this.user.id, function: v.id}}) - //let result = await this.$insertapi('userrights', arr) + //let result = await this.$insertapi('userrights', { data: arr }) //this.$dialog('Account created successfully.', 'Success', 'Success', 10) this.$emit("close"); }, diff --git a/app/components/user/SetPassword.vue b/app/components/user/SetPassword.vue index a68aa42..2afb2a5 100644 --- a/app/components/user/SetPassword.vue +++ b/app/components/user/SetPassword.vue @@ -108,7 +108,7 @@ export default { first: true, params: { filter: { id: this.row.id } }, }); - let rs = await this.$insertapi("gethash", { text: this.password }); + let rs = await this.$insertapi("gethash", { data: { text: this.password } }); user.password = rs.rows[0]; let rs1 = await this.$updateapi("user", user); if (rs1 !== "error") this.$emit("close"); diff --git a/app/plugins/02-connection.js b/app/plugins/02-connection.js index 2d8ee08..0c0630d 100644 --- a/app/plugins/02-connection.js +++ b/app/plugins/02-connection.js @@ -1160,43 +1160,44 @@ export default defineNuxtPlugin((nuxtApp) => { }; // insert data - const insertapi = async function (name, data, values, notify) { + const insertapi = async function (name, { data, values, notify = true } = {}) { try { - const found = findapi(name); - const curpath = found.path ? paths.find((x) => x.name === found.path).url : path; + const api = findapi(name); + const curpath = api.path ? paths.find((x) => x.name === api.path).url : path; let rs; if (Array.isArray(data)) { - rs = await $fetch(`${curpath}import-data/${found.url.substring(5, found.url.length - 1)}/`, { + rs = await $fetch(`${curpath}import-data/${api.url.substring(5, api.url.length - 1)}/`, { method: "POST", body: data, params: { values, action: "import" }, }); } else { - rs = await $fetch(`${curpath}${found.url}`, { + rs = await $fetch(`${curpath}${api.url}`, { method: "POST", body: data, params: { values }, }); } // update store - if (found.commit) { - if ($store[found.commit]) { - const copy = $copy($store[found.commit]); + if (api.commit) { + if ($store[api.commit]) { + const copy = $copy($store[api.commit]); const rows = Array.isArray(rs) ? rs : [rs]; rows.forEach((v) => { if (v.id && !v.error) { - let idx = copy.findIndex((x) => x.id === v.id); + const idx = copy.findIndex((x) => x.id === v.id); if (idx >= 0) copy[idx] = v; else copy.push(v); } }); - $store.commit(found.commit, copy); + $store.commit(api.commit, copy); } } - if (notify !== false) { - $store.lang === "en" - ? $snackbar("Data has been successfully saved to the system.", "Success") - : $snackbar("Dữ liệu đã được lưu vào hệ thống", "Success"); + if (notify) { + $snackbar( + $store.lang === "en" ? "Data has been successfully saved to the system." : "Dữ liệu đã được lưu vào hệ thống", + "Success", + ); } return rs; } catch (err) { @@ -1394,8 +1395,8 @@ export default defineNuxtPlugin((nuxtApp) => { }; // insert row - var insertrow = async function (name, data, values, pagename, notify) { - let result = await insertapi(name, data, values, notify); + const insertrow = async function (name, data, values, pagename, notify) { + let result = await insertapi(name, { data, values, notify }); if (result === "error" || !pagename || !$store[pagename]) return result; let copy = $clone($store[pagename]); copy.update = { refresh: true };