This commit is contained in:
Viet An
2026-07-03 09:24:05 +07:00
parent f519573c19
commit 4404c4654b
22 changed files with 59 additions and 39 deletions

View File

@@ -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,

View File

@@ -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) {

View File

@@ -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ã <b>${rs.code}</b>`, "Success");

View File

@@ -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 });
}
});

View File

@@ -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") {

View File

@@ -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 });

View File

@@ -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");

View File

@@ -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") {

View File

@@ -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") {

View File

@@ -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,

View File

@@ -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 });
},
},
};

View File

@@ -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 });

View File

@@ -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();

View File

@@ -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, {

View File

@@ -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ã <b>${rs.code}</b>`, "Success");

View File

@@ -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" });

View File

@@ -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();

View File

@@ -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;

View File

@@ -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;

View File

@@ -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");

View File

@@ -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 };

View File

@@ -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;