From 295b9b4d69c834d88b6e616ace19fb18b57cda78 Mon Sep 17 00:00:00 2001 From: = <=> Date: Thu, 25 Sep 2025 11:29:09 -0300 Subject: [PATCH] [MVPTN-77] refactor(geral): implementando gerenciador de erro nos datas --- .../_data/GMedidoTipo/GMedidaTipoIndexData.ts | 14 +++++--------- .../_data/GMedidoTipo/GMedidaTipoRemoveData.ts | 7 +++++-- .../_data/GMedidoTipo/GMedidaTipoSaveData.ts | 7 +++++-- .../_hooks/g_medidatipo/useGMedidaTipoReadHook.ts | 2 +- .../g_medidatipo/useGMedidaTipoRemoveHook.ts | 2 +- .../_hooks/g_medidatipo/useGMedidaTipoSaveHook.ts | 2 +- .../g_medidatipo/GMedidaTipoIndexService.ts | 2 +- .../g_medidatipo/GMedidaTipoRemoveService.ts | 2 +- .../g_medidatipo/GMedidaTipoSaveService.ts | 2 +- 9 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/GMedidoTipo/GMedidaTipoIndexData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/GMedidoTipo/GMedidaTipoIndexData.ts index d1bcbaf..1e289f8 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_data/GMedidoTipo/GMedidaTipoIndexData.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_data/GMedidoTipo/GMedidaTipoIndexData.ts @@ -1,17 +1,13 @@ +import { withClientErrorHandler } from "@/actions/withClientErrorHandler/withClientErrorHandler"; import API from "@/services/api/Api"; import { Methods } from "@/services/api/enums/ApiMethodEnum"; -export default async function GMedidaTipoIndexData() { +async function executeGMedidaTipoIndexData() { const api = new API(); - try { - const dados = await api.send({ + return await api.send({ method: Methods.GET, endpoint: `administrativo/g_medida_tipo/` }); - return dados - } catch (error) { - console.log(error) - return error - } +} -} \ No newline at end of file +export const GMedidaTipoIndexData = withClientErrorHandler(executeGMedidaTipoIndexData) \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/GMedidoTipo/GMedidaTipoRemoveData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/GMedidoTipo/GMedidaTipoRemoveData.ts index 7e7f4d3..eccb06c 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_data/GMedidoTipo/GMedidaTipoRemoveData.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_data/GMedidoTipo/GMedidaTipoRemoveData.ts @@ -1,8 +1,9 @@ import API from "@/services/api/Api"; import { GMedidaTipoInterface } from "../../_interfaces/GMedidaTipoInterface"; import { Methods } from "@/services/api/enums/ApiMethodEnum"; +import { withClientErrorHandler } from "@/actions/withClientErrorHandler/withClientErrorHandler"; -export default async function GMedidaTipoRemoveData(data: GMedidaTipoInterface) { +async function executeGMedidaTipoRemoveData(data: GMedidaTipoInterface) { const api = new API(); @@ -11,4 +12,6 @@ export default async function GMedidaTipoRemoveData(data: GMedidaTipoInterface) endpoint: `administrativo/g_medida_tipo/${data.medida_tipo_id}` }); -} \ No newline at end of file +} + +export const GMedidaTipoRemoveData = withClientErrorHandler(executeGMedidaTipoRemoveData) \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/GMedidoTipo/GMedidaTipoSaveData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/GMedidoTipo/GMedidaTipoSaveData.ts index deff26e..17636e3 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_data/GMedidoTipo/GMedidaTipoSaveData.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_data/GMedidoTipo/GMedidaTipoSaveData.ts @@ -1,8 +1,9 @@ import API from "@/services/api/Api"; import { GMedidaTipoInterface } from "../../_interfaces/GMedidaTipoInterface"; import { Methods } from "@/services/api/enums/ApiMethodEnum"; +import { withClientErrorHandler } from "@/actions/withClientErrorHandler/withClientErrorHandler"; -export default async function GMedidaTipoSaveData(data: GMedidaTipoInterface) { +async function executeGMedidaTipoSaveData(data: GMedidaTipoInterface) { const isUpdate = Boolean(data.medida_tipo_id); @@ -14,4 +15,6 @@ export default async function GMedidaTipoSaveData(data: GMedidaTipoInterface) { body: data }); -} \ No newline at end of file +} + +export const GMedidaTipoSaveData = withClientErrorHandler(executeGMedidaTipoSaveData) \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/g_medidatipo/useGMedidaTipoReadHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_medidatipo/useGMedidaTipoReadHook.ts index 9ac7b2c..a1e1267 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_hooks/g_medidatipo/useGMedidaTipoReadHook.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_medidatipo/useGMedidaTipoReadHook.ts @@ -1,7 +1,7 @@ import { useResponse } from "@/app/_response/ResponseContext" import { useState } from "react"; import { GMedidaTipoInterface } from "../../_interfaces/GMedidaTipoInterface"; -import GMedidaTipoIndexService from "../../_services/g_medidatipo/GMedidaTipoIndexService"; +import { GMedidaTipoIndexService } from "../../_services/g_medidatipo/GMedidaTipoIndexService"; export const useGMedidaTipoReadHook = () => { diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/g_medidatipo/useGMedidaTipoRemoveHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_medidatipo/useGMedidaTipoRemoveHook.ts index d19018a..f6d141b 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_hooks/g_medidatipo/useGMedidaTipoRemoveHook.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_medidatipo/useGMedidaTipoRemoveHook.ts @@ -1,6 +1,6 @@ import { useResponse } from "@/app/_response/ResponseContext" import { GMedidaTipoInterface } from "../../_interfaces/GMedidaTipoInterface"; -import GMedidaTipoRemoveService from "../../_services/g_medidatipo/GMedidaTipoRemoveService"; +import { GMedidaTipoRemoveService } from "../../_services/g_medidatipo/GMedidaTipoRemoveService"; export const useGMedidaTipoRemoveHook = () => { diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/g_medidatipo/useGMedidaTipoSaveHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_medidatipo/useGMedidaTipoSaveHook.ts index 8f70843..45871ca 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_hooks/g_medidatipo/useGMedidaTipoSaveHook.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_medidatipo/useGMedidaTipoSaveHook.ts @@ -1,7 +1,7 @@ import { useResponse } from "@/app/_response/ResponseContext" import { useState } from "react"; import { GMedidaTipoInterface } from "../../_interfaces/GMedidaTipoInterface"; -import GMedidaTipoSaveService from "../../_services/g_medidatipo/GMedidaTipoSaveService"; +import { GMedidaTipoSaveService } from "../../_services/g_medidatipo/GMedidaTipoSaveService"; export const useGMedidaTipoSaveHook = () => { diff --git a/src/app/(protected)/(cadastros)/cadastros/_services/g_medidatipo/GMedidaTipoIndexService.ts b/src/app/(protected)/(cadastros)/cadastros/_services/g_medidatipo/GMedidaTipoIndexService.ts index cda56c6..7599d71 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_services/g_medidatipo/GMedidaTipoIndexService.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_services/g_medidatipo/GMedidaTipoIndexService.ts @@ -1,5 +1,5 @@ import { withClientErrorHandler } from "@/actions/withClientErrorHandler/withClientErrorHandler"; -import GMedidaTipoIndexData from "../../_data/GMedidoTipo/GMedidaTipoIndexData"; +import { GMedidaTipoIndexData } from "../../_data/GMedidoTipo/GMedidaTipoIndexData"; async function executeGMedidaTipoIndexService() { const response = await GMedidaTipoIndexData(); diff --git a/src/app/(protected)/(cadastros)/cadastros/_services/g_medidatipo/GMedidaTipoRemoveService.ts b/src/app/(protected)/(cadastros)/cadastros/_services/g_medidatipo/GMedidaTipoRemoveService.ts index 299b23f..273d244 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_services/g_medidatipo/GMedidaTipoRemoveService.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_services/g_medidatipo/GMedidaTipoRemoveService.ts @@ -1,5 +1,5 @@ import { withClientErrorHandler } from "@/actions/withClientErrorHandler/withClientErrorHandler"; -import GMedidaTipoRemoveData from "../../_data/GMedidoTipo/GMedidaTipoRemoveData"; +import { GMedidaTipoRemoveData } from "../../_data/GMedidoTipo/GMedidaTipoRemoveData"; import { GMedidaTipoInterface } from "../../_interfaces/GMedidaTipoInterface"; async function executeGMedidaTipoRemoveService(data: GMedidaTipoInterface) { diff --git a/src/app/(protected)/(cadastros)/cadastros/_services/g_medidatipo/GMedidaTipoSaveService.ts b/src/app/(protected)/(cadastros)/cadastros/_services/g_medidatipo/GMedidaTipoSaveService.ts index 31b5d02..f92c548 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_services/g_medidatipo/GMedidaTipoSaveService.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_services/g_medidatipo/GMedidaTipoSaveService.ts @@ -1,5 +1,5 @@ import { withClientErrorHandler } from "@/actions/withClientErrorHandler/withClientErrorHandler"; -import GMedidaTipoSaveData from "../../_data/GMedidoTipo/GMedidaTipoSaveData"; +import { GMedidaTipoSaveData } from "../../_data/GMedidoTipo/GMedidaTipoSaveData"; import { GMedidaTipoInterface } from "../../_interfaces/GMedidaTipoInterface"; async function executeGMedidaTipoSaveService(data: GMedidaTipoInterface) {