Переглянути джерело

feat(api): update endpoints for cities, countries, states, and financial plan accounts; add new select methods for improved data retrieval

ebagabee 1 тиждень тому
батько
коміт
ca55c00b6b

+ 3 - 3
src/api/city.js

@@ -8,16 +8,16 @@ export const getCity = async (id) => {
 };
 
 export const getCities = async () => {
-  const { data } = await api.get("/city");
+  const { data } = await api.get("/selects/cities");
   return data.payload;
 };
 
 export const getCityByState = async (stateId) => {
-  const { data } = await api.get(`/city/state/${stateId}`);
+  const { data } = await api.get("/selects/cities", { params: { state_id: stateId } });
   return data.payload;
 };
 
 export const getCityByCountry = async (countryId) => {
-  const { data } = await api.get(`/city/country/${countryId}`);
+  const { data } = await api.get("/selects/cities", { params: { country_id: countryId } });
   return data.payload;
 };

+ 1 - 1
src/api/country.js

@@ -8,6 +8,6 @@ export const getCountry = async (id) => {
 };
 
 export const getCountries = async () => {
-  const { data } = await api.get("/country");
+  const { data } = await api.get("/selects/countries");
   return data.payload;
 };

+ 5 - 0
src/api/financial_plan_account.js

@@ -5,6 +5,11 @@ export const getFinancialPlanAccounts = async (params = {}) => {
   return data.payload;
 };
 
+export const getFinancialPlanAccountsForSelect = async () => {
+  const { data } = await api.get("/selects/financial-plan-accounts");
+  return data.payload;
+};
+
 export const createFinancialPlanAccount = async (payload) => {
   const { data } = await api.post("/financial-plan-account", payload);
   return data.payload;

+ 1 - 1
src/api/group.js

@@ -6,7 +6,7 @@ export const getGroups = async () => {
 };
 
 export const getGroupsForSelect = async () => {
-  const { data } = await api.get("/group/all/select");
+  const { data } = await api.get("/selects/groups");
   return data.payload;
 };
 

+ 1 - 1
src/api/inhabitant_classification.js

@@ -1,7 +1,7 @@
 import api from "src/api";
 
 export const getInhabitantClassificationsForSelect = async () => {
-  const { data } = await api.get("/inhabitant-classification/all/select");
+  const { data } = await api.get("/selects/inhabitant-classifications");
   return data.payload;
 };
 

+ 1 - 1
src/api/product.js

@@ -6,7 +6,7 @@ export const getProducts = async (params) => {
 };
 
 export const getProductsForSelect = async () => {
-  const { data } = await api.get("/product/all/select");
+  const { data } = await api.get("/selects/products");
   return data.payload;
 };
 

+ 2 - 2
src/api/state.js

@@ -8,11 +8,11 @@ export const getState = async (id) => {
 }
 
 export const getStates = async () => {
-  const { data } = await api.get("/state");
+  const { data } = await api.get("/selects/states");
   return data.payload;
 }
 
 export const getStateByCountry = async (countryId) => {
-  const { data } = await api.get(`/state/country/${countryId}`);
+  const { data } = await api.get("/selects/states", { params: { country_id: countryId } });
   return data.payload;
 }

+ 1 - 1
src/api/tbr_calculation.js

@@ -26,6 +26,6 @@ export const generateBatchReceivables = async (payload) => {
 };
 
 export const getMunicipalitySizes = async () => {
-  const { data } = await api.get("/municipality-size");
+  const { data } = await api.get("/selects/municipality-sizes");
   return data.payload;
 };

+ 1 - 1
src/api/unit.js

@@ -32,6 +32,6 @@ export const deleteUnit = async (id) => {
 };
 
 export const getUnitsForSelect = async () => {
-  const { data } = await api.get("/unit/all/select");
+  const { data } = await api.get("/selects/units");
   return data.payload;
 };

+ 3 - 2
src/api/user.js

@@ -35,11 +35,12 @@ export const deleteUser = async (id) => {
 };
 
 export const userTypes = async (accessScope = null, unitId = null) => {
-  const { data } = await api.get("/user/all/types", {
+  const { data } = await api.get("/selects/user-types", {
     params: {
       ...(accessScope ? { access_scope: accessScope } : {}),
       ...(unitId ? { unit_id: unitId } : {}),
+      include_system_admin: accessScope === "unit",
     },
   });
-  return data.payload;
+  return Object.fromEntries(data.payload.map((type) => [type.value, type.label]));
 };

+ 2 - 2
src/components/financial/AddTreasuryLaunchDialog.vue

@@ -63,7 +63,7 @@ import { useDialogPluginComponent } from "quasar";
 import { useInputRules } from "src/composables/useInputRules";
 import { useSubmitHandler } from "src/composables/useSubmitHandler";
 import { createTreasuryLaunch } from "src/api/treasury_launch";
-import { getFinancialPlanAccounts } from "src/api/financial_plan_account";
+import { getFinancialPlanAccountsForSelect } from "src/api/financial_plan_account";
 
 import DefaultDialogHeader from "src/components/defaults/DefaultDialogHeader.vue";
 import DefaultInput from "src/components/defaults/DefaultInput.vue";
@@ -114,7 +114,7 @@ const filterPlanAccounts = (needle, update) => {
 onMounted(async () => {
   loadingPlanAccounts.value = true;
   try {
-    const accounts = await getFinancialPlanAccounts();
+    const accounts = await getFinancialPlanAccountsForSelect();
     allPlanAccounts.value = accounts.map((a) => ({
       label: `${a.code} - ${a.description}`,
       value: a.id,

+ 2 - 2
src/components/selects/GroupSelect.vue

@@ -23,7 +23,7 @@
 
 <script setup>
 import { onMounted, ref } from "vue";
-import { getGroups } from "src/api/group";
+import { getGroupsForSelect } from "src/api/group";
 import DefaultSelect from "src/components/defaults/DefaultSelect.vue";
 
 const { label } = defineProps({
@@ -52,7 +52,7 @@ const filterFn = (val, update) => {
 
 onMounted(async () => {
   try {
-    const response = await getGroups();
+    const response = await getGroupsForSelect();
     groupOptions.value = response.map((g) => ({
       label: g.name,
       value: g.id,

+ 2 - 2
src/pages/financial/AccountsPayablePage.vue

@@ -227,7 +227,7 @@ import {
   settleCompanyPayable,
   reopenCompanyPayable,
 } from "src/api/company_payable";
-import { getFinancialPlanAccounts } from "src/api/financial_plan_account";
+import { getFinancialPlanAccountsForSelect } from "src/api/financial_plan_account";
 
 import DefaultHeaderPage from "src/components/layout/DefaultHeaderPage.vue";
 import DefaultTable from "src/components/defaults/DefaultTable.vue";
@@ -342,7 +342,7 @@ async function loadAux() {
   if (planAccountOptions.value.length) return;
   loadingAux.value = true;
   try {
-    const planAccounts = await getFinancialPlanAccounts();
+    const planAccounts = await getFinancialPlanAccountsForSelect();
     planAccountOptions.value = (planAccounts ?? []).map((a) => ({
       label: `${a.code} — ${a.description}`,
       value: a.id,