[MVPTN-87] feat(CRUD): Adiciona os endpoints funcionais do backend

This commit is contained in:
Keven Willian Pereira de Souza 2025-10-07 11:59:32 -03:00
parent 847a1f0758
commit 3e68efe7ec
16 changed files with 73 additions and 52 deletions

View file

@ -2,7 +2,7 @@ import * as React from 'react';
import { cn } from '@/lib/utils';
function Input({ className, type, ...props }: React.ComponentProps<'input'>) {
function Input({ className, value, type, ...props }: React.ComponentProps<'input'>) {
return (
<input
type={type}
@ -13,6 +13,7 @@ function Input({ className, type, ...props }: React.ComponentProps<'input'>) {
'aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive',
className,
)}
value={value ?? ''}
{...props}
/>
);

View file

@ -381,7 +381,7 @@ export default function TImovelUnidadeUrbanoForm({ isOpen, data, onClose, onSave
)}
/>
</div>
{/* UnidadeUrbano */}
{/* Unidade Urbano */}
<div className="col-span-12 sm:col-span-6 md:col-span-2">
<FormField
control={form.control}

View file

@ -152,7 +152,7 @@ export default function TImovelUnidadeUrbanoPage({imovel_id}: TImovelUnidadePage
isOpen={isConfirmOpen}
title="Confirmar exclusão"
description="Atenção"
message={`Deseja realmente excluir a unidade "${itemToDelete?.cidade}"?`}
message={`Deseja realmente excluir a unidade "Lote ${itemToDelete?.lote}, Quadra ${itemToDelete?.quadra}, Logradouro ${itemToDelete?.logradouro}"?`}
confirmText="Sim, excluir"
cancelText="Cancelar"
onConfirm={handleDelete}

View file

@ -1,12 +1,16 @@
import { withClientErrorHandler } from "@/shared/actions/withClientErrorHandler/withClientErrorHandler";
import TImovelInterface from "../../interfaces/TImovel/TImovelInterface";
import ApiResponseInterface from "@/shared/services/api/interfaces/ApiResponseInterface";
import API from "@/shared/services/api/Api";
import { Methods } from "@/shared/services/api/enums/ApiMethodEnum";
import TImovelInterface from "../../interfaces/TImovel/TImovelInterface";
async function executeTImovelDeleteData(data: TImovelInterface): Promise<ApiResponseInterface> {
return Promise.resolve({
status: 200,
message: 'Dados Removidos'
const api = new API();
return await api.send({
method: Methods.DELETE,
endpoint: `administrativo/t_imovel/${data.imovel_id}`
});
}

View file

@ -1,11 +1,15 @@
import { withClientErrorHandler } from "@/shared/actions/withClientErrorHandler/withClientErrorHandler";
import { TImovelUnidadeUrbanoInterface } from "@/packages/administrativo/interfaces/TImovelUnidade/TImovelUnidadeUrbano/TImovelUnidadeUrbanoInterface";
import API from "@/shared/services/api/Api";
import { Methods } from "@/shared/services/api/enums/ApiMethodEnum";
async function executeTImovelUnidadeUrbanoDeleteData(data: TImovelUnidadeUrbanoInterface) {
return Promise.resolve({
status: 200,
message: 'Dados Removidos'
const api = new API();
return api.send({
method: Methods.DELETE,
endpoint: `administrativo/t_imovel_unidade/${data.imovel_unidade_id}`
});
}

View file

@ -1,11 +1,21 @@
import { withClientErrorHandler } from "@/shared/actions/withClientErrorHandler/withClientErrorHandler";
import { TImovelUnidadeUrbanoInterface } from "@/packages/administrativo/interfaces/TImovelUnidade/TImovelUnidadeUrbano/TImovelUnidadeUrbanoInterface";
import API from "@/shared/services/api/Api";
import { Methods } from "@/shared/services/api/enums/ApiMethodEnum";
async function executeTImovelUnidadeUrbanoSaveData(data: TImovelUnidadeUrbanoInterface) {
return Promise.resolve({
status: 200,
message: 'Dados salvos',
// Verifica se existe ID da cidade para decidir se é atualização (PUT) ou criação (POST)
const isUpdate = Boolean(data.imovel_unidade_id);
// Instancia o cliente da API para enviar a requisição
const api = new API();
// Executa a requisição para a API com o método apropriado e envia os dados no corpo
return await api.send({
method: isUpdate ? Methods.PUT : Methods.POST, // PUT se atualizar, POST se criar
endpoint: `administrativo/t_imovel_unidade/${data.imovel_unidade_id || ''}`, // endpoint dinâmico
body: data, // payload enviado para a API
});
}

View file

@ -8,7 +8,7 @@ import { TImovelIndexData } from '../../data/TImovel/TImovelIndexData';
export const useTImovelIndexHook = () => {
const { setResponse } = useResponse();
const [tImovel, setTImovel] = useState<TImovelInterface[]>();
const [tImovel, setTImovel] = useState<TImovelInterface[]>([]);
const indexTImovel = async () => {
const response = await TImovelIndexData();

View file

@ -10,9 +10,7 @@ export const useTImovelUnidadeUrbanoDeleteHook = () => {
const deleteTImovelUnidadeUrbano = async (data: TImovelUnidadeUrbanoInterface) => {
const response = await TImovelUnidadeUrbanoDeleteService(data);
setTImovelUnidadeUrbano(data);
setResponse(response);
};

View file

@ -9,8 +9,7 @@ import TImovelUnidadePageInterface from '@/packages/administrativo/interfaces/TI
export const useTImovelUnidadeUrbanoIndexHook = () => {
const { setResponse } = useResponse();
const [tImovelUnidadeUrbano, setTImovelUnidadeUrbano] = useState<
TImovelUnidadeUrbanoInterface[]>();
const [tImovelUnidadeUrbano, setTImovelUnidadeUrbano] = useState<TImovelUnidadeUrbanoInterface[]>([]);
const indexTImovelUnidadeUrbano = async (data: TImovelUnidadePageInterface) => {

View file

@ -14,6 +14,9 @@ export const useTImovelUnidadeUrbanoSaveHook = () => {
const [isOpen, setIsOpen] = useState(false);
const saveTImovelUnidadeUrbano = async (data: TImovelUnidadeUrbanoInterface) => {
console.log(data);
const response = await TImovelUnidadeUrbanoSaveService(data);
// Armazena os dados da repsota

View file

@ -1,3 +1,3 @@
export default interface TImovelUnidadePageInterface {
imovel_id : number;
imovel_id? : number;
}

View file

@ -6,4 +6,4 @@ export interface TImovelUnidadeUrbanoFormInterface {
onClose: (item: null, isFormStatus: boolean) => void;
onSave: (data: TImovelUnidadeUrbanoFormValues) => void;
buttonIsLoading: boolean;
}
}

View file

@ -1,21 +1,21 @@
import TImovelUnidadeInterface from "../TImovelUnidadeInterface";
export interface TImovelUnidadeUrbanoInterface extends TImovelUnidadeInterface {
quadra?: string;
lote?: string;
inscricao_municipal?: string;
tb_tipologradouro_id?: number;
quadra?: string | null;
lote?: string | null;
inscricao_municipal?: string | null;
tb_tipologradouro_id?: number | null;
logradouro: string;
tipo_imovel?: number;
tipo_construcao?: number;
iptu?: string;
numero_unidade?: string;
torre?: string;
nomecondominio?: string;
nomeloteamento?: string;
numero?: number;
complemento?: string;
numero_edificacao?: string;
cnm_numero?: string;
cib?: string;
tipo_imovel?: number | null;
tipo_construcao?: number | null;
iptu?: string | null;
numero_unidade?: string | null;
torre?: string | null;
nomecondominio?: string | null;
nomeloteamento?: string | null;
numero?: number | null;
complemento?: string | null;
numero_edificacao?: string | null;
cnm_numero?: string | null;
cib?: string | null;
}

View file

@ -2,21 +2,21 @@ import { z } from "zod";
import { TImovelUnidadeSchema } from "../TImovelUnidadeSchema";
export const TImovelUnidadeUrbanoSchema = TImovelUnidadeSchema.extend({
quadra: z.string().optional(),
lote: z.string().optional(),
inscricao_municipal: z.string().optional(),
tb_tipologradouro_id: z.number().optional(),
quadra: z.string().nullable().optional(),
lote: z.string().nullable().optional(),
inscricao_municipal: z.string().nullable().optional(),
tb_tipologradouro_id: z.number().nullable().optional(),
logradouro: z.string().min(1, "O logradouro é obrigatório"),
iptu: z.string().optional(),
numero_unidade: z.string().optional(),
torre: z.string().optional(),
nomecondominio: z.string().optional(),
nomeloteamento: z.string().optional(),
numero: z.number().optional(),
complemento: z.string().optional(),
numero_edificacao: z.string().optional(),
cnm_numero: z.string().optional(),
cib: z.string().optional(),
iptu: z.string().nullable().optional(),
numero_unidade: z.string().nullable().optional(),
torre: z.string().nullable().optional(),
nomecondominio: z.string().nullable().optional(),
nomeloteamento: z.string().nullable().optional(),
numero: z.number().nullable().optional(),
complemento: z.string().nullable().optional(),
numero_edificacao: z.string().nullable().optional(),
cnm_numero: z.string().nullable().optional(),
cib: z.string().nullable().optional(),
});
export type TImovelUnidadeUrbanoFormValues = z.infer<typeof TImovelUnidadeUrbanoSchema>;

View file

@ -1,8 +1,10 @@
import { withClientErrorHandler } from '@/shared/actions/withClientErrorHandler/withClientErrorHandler';
import { TImovelUnidadeUrbanoInterface } from '@/packages/administrativo/interfaces/TImovelUnidade/TImovelUnidadeUrbano/TImovelUnidadeUrbanoInterface';
import { TImovelUnidadeUrbanoDeleteData } from '@/packages/administrativo/data/TImovelUnidade/TImovelUnidadeUrbano/TImovelUnidadeUrbanoDeleteData';
async function executeTImovelUnidadeUrbanoDeleteService(data: TImovelUnidadeUrbanoInterface) {
const response = await (data);
const response = await TImovelUnidadeUrbanoDeleteData(data);
return response;
}

View file

@ -4,7 +4,7 @@
* @param text - Texto que será capitalizado
* @returns String com a primeira letra em maiúscula
*/
export default function GetCapitalize(text: string): string {
export default function GetCapitalize(text?: string): string {
if (!text) return '';
return text.charAt(0).toUpperCase() + text.slice(1).toLowerCase();