Skip to content

Instantly share code, notes, and snippets.

@nartoan
Created July 7, 2025 18:10
Show Gist options
  • Save nartoan/a10496bc98f40725d3747eda68892181 to your computer and use it in GitHub Desktop.
Save nartoan/a10496bc98f40725d3747eda68892181 to your computer and use it in GitHub Desktop.
const updateDistrict = async (id, diachi_vn, diachi_en) => {
const request = await fetch(
`http://103.237.147.12:8090/KhoiTaoToaNha/PNG_1TCHUNG_XEM_CT?id=${id}`,
{
headers: {
accept: "application/json, text/javascript, */*; q=0.01",
"accept-language": "en-US,en;q=0.9,es;q=0.8,ja;q=0.7",
"content-type": "application/json; charset=utf-8",
"x-requested-with": "XMLHttpRequest",
},
referrerPolicy: "strict-origin-when-cross-origin",
body: null,
method: "POST",
mode: "cors",
credentials: "include",
}
);
const response = await request.json();
const result = response[0].flat(6).reduce((newData, item) => {
if (item.Key.endsWith("_nsd") || item.Key.endsWith("_tgian")) {
return newData;
}
return { ...newData, [item.Key]: item.Value };
}, {});
const newBody = {
...result,
id_tn: id,
matbang: [],
matbangtc: response[2].map((item) =>
item.reduce(
(newData, item1) => ({ ...newData, [item1.Key]: item1.Value }),
{}
)
),
tailieu: [],
diachi_vn: diachi_vn,
diachi_en: diachi_en,
};
const updateData = await fetch(
"http://103.237.147.12:8090/KhoiTaoToaNha/Post_taotoanha",
{
headers: {
accept: "application/json, text/javascript, */*; q=0.01",
"accept-language": "en-US,en;q=0.9,es;q=0.8,ja;q=0.7",
"content-type": "application/json; charset=UTF-8",
"x-requested-with": "XMLHttpRequest",
},
referrerPolicy: "strict-origin-when-cross-origin",
body: JSON.stringify(newBody),
method: "POST",
mode: "cors",
credentials: "include",
}
);
if (!updateData.ok) {
throw new Error("Failed to update data", id);
} else {
console.log("Data updated successfully", id);
}
};
const id = 1794;
const diachi_vn = "52 Đồng Văn Cống, Phường Bình Trung, Quận 2 demo";
const diachi_en = "52 Dong Van Cong, Binh Trung Ward, District 2 demo";
updateDistrict(id, diachi_vn, diachi_en);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment