From c3989768edd5c3c5493f09b379a24135d941183f Mon Sep 17 00:00:00 2001 From: Thanaphon Frappet Date: Fri, 11 Jul 2025 09:12:17 +0700 Subject: [PATCH] feat: add crud business type --- .../shared/select/SelectBusinessType.vue | 124 +++ .../AgenciesDialog.vue | 658 ++++++++++++++ .../16_ิbusiness-type-management/MainPage.vue | 858 ++++++++++++++++++ src/router/routes.ts | 6 + src/stores/business-type/index.ts | 85 ++ src/stores/business-type/types.ts | 15 + 6 files changed, 1746 insertions(+) create mode 100644 src/components/shared/select/SelectBusinessType.vue create mode 100644 src/pages/16_ิbusiness-type-management/AgenciesDialog.vue create mode 100644 src/pages/16_ิbusiness-type-management/MainPage.vue create mode 100644 src/stores/business-type/index.ts create mode 100644 src/stores/business-type/types.ts diff --git a/src/components/shared/select/SelectBusinessType.vue b/src/components/shared/select/SelectBusinessType.vue new file mode 100644 index 00000000..b4f4a5c4 --- /dev/null +++ b/src/components/shared/select/SelectBusinessType.vue @@ -0,0 +1,124 @@ + + diff --git a/src/pages/16_ิbusiness-type-management/AgenciesDialog.vue b/src/pages/16_ิbusiness-type-management/AgenciesDialog.vue new file mode 100644 index 00000000..e1597b03 --- /dev/null +++ b/src/pages/16_ิbusiness-type-management/AgenciesDialog.vue @@ -0,0 +1,658 @@ + + + diff --git a/src/pages/16_ิbusiness-type-management/MainPage.vue b/src/pages/16_ิbusiness-type-management/MainPage.vue new file mode 100644 index 00000000..6b97e47f --- /dev/null +++ b/src/pages/16_ิbusiness-type-management/MainPage.vue @@ -0,0 +1,858 @@ + + + diff --git a/src/router/routes.ts b/src/router/routes.ts index 4418fb71..126f2891 100644 --- a/src/router/routes.ts +++ b/src/router/routes.ts @@ -157,6 +157,12 @@ const routes: RouteRecordRaw[] = [ name: 'Notification', component: () => import('pages/00_notification/MainPage.vue'), }, + { + path: '/business-type', + name: 'businessType', + component: () => + import('pages/16_ิbusiness-type-management/MainPage.vue'), + }, { path: '/manual', name: 'Manual', diff --git a/src/stores/business-type/index.ts b/src/stores/business-type/index.ts new file mode 100644 index 00000000..a9ed029b --- /dev/null +++ b/src/stores/business-type/index.ts @@ -0,0 +1,85 @@ +import { ref } from 'vue'; +import { defineStore } from 'pinia'; +import { Pagination, Status } from '../types'; +import { api } from 'src/boot/axios'; + +import { BusinessType, BusinessTypePayLoad } from './types'; +import axios from 'axios'; + +const useBusinessTypeStore = defineStore('business-type-store', () => { + const data = ref>(); + + async function fetchList(opts?: { + page?: number; + pageSize?: number; + query?: string; + }) { + const res = await api.get>('/business-type', { + params: opts, + }); + + if (res && res.status === 200) { + return res.data; + } + return false; + } + + async function fetchById(id: string) { + const res = await api.get(`/business-type/${id}`); + + if (!res) return false; + if (res.status === 200) return res.data; + if (res.status === 204) return null; + + return false; + } + + async function create(data: BusinessTypePayLoad) { + const res = await api.post('/business-type', { + ...data, + }); + if (res.status < 400) { + return res.data; + } + return null; + } + + async function editById(data: BusinessTypePayLoad) { + const { id, ...payload } = data; + + const res = await api.put( + `/business-type/${id}`, + payload, + ); + + if (!res) return false; + + return res.data; + } + + async function deleteById(id: string) { + const res = await api.delete(`/business-type/${id}`); + + if (!res) return false; + if (res.status === 200) return res.data; + + return false; + } + + return { + data, + + fetchList, + fetchById, + + create, + + editById, + + deleteById, + }; +}); + +export * from './types'; + +export default useBusinessTypeStore; diff --git a/src/stores/business-type/types.ts b/src/stores/business-type/types.ts new file mode 100644 index 00000000..d8bf9471 --- /dev/null +++ b/src/stores/business-type/types.ts @@ -0,0 +1,15 @@ +export type BusinessType = { + updatedByUserId: string; + updatedAt: Date; + createdByUserId: string; + createdAt: Date; + nameEN: string; + name: string; + id: string; +}; + +export type BusinessTypePayLoad = { + nameEN: string; + name: string; + id?: string; +};