ข้อมูลบุคคล: ปรับสไตล์/validate/ใส่catch

This commit is contained in:
oat_dev 2024-03-15 10:43:11 +07:00
parent f78d8547ce
commit 6553c8b972
9 changed files with 311 additions and 140 deletions

View file

@ -13,7 +13,7 @@ import config from "@/app.config";
const store = usePersonalDataStore();
const router = useRouter();
const mixin = useCounterMixin();
const { dialogRemove, messageError, showLoader, hideLoader } = mixin;
const { dialogRemove, messageError, showLoader, hideLoader, success } = mixin;
const columns = [
{
name: "bloodGroup",
@ -81,7 +81,6 @@ async function fetchData() {
await http
.get(config.API.orgBloodGroup)
.then(async (res) => {
console.log(res.data.result);
store.save(res.data.result);
})
.catch((err) => {
@ -93,22 +92,51 @@ async function fetchData() {
}
async function addData() {
await http.post(config.API.orgBloodGroup, {
name: bloodGroup.value,
});
fetchData();
await http
.post(config.API.orgBloodGroup, {
name: bloodGroup.value,
})
.then(() => {
fetchData();
success($q, "บันทึกข้อมูลสำเร็จ");
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
}
async function editData(id: string) {
await http.put(config.API.orgBloodGroupId(id), {
name: bloodGroup.value,
});
fetchData();
await http
.put(config.API.orgBloodGroupId(id), {
name: bloodGroup.value,
})
.then(() => {
fetchData();
success($q, "บันทึกข้อมูลสำเร็จ");
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
}
async function deleteData(id: string) {
await http.delete(config.API.orgBloodGroupId(id));
fetchData();
await http
.delete(config.API.orgBloodGroupId(id))
.then(() => {
fetchData();
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
}
onMounted(async () => {