Compare commits
No commits in common. "VDU-2" and "main" have entirely different histories.
34 changed files with 95 additions and 367 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
import { LoginForm } from '@/packages/administrativo/components/User/UserLoginForm';
|
import { LoginForm } from '@/packages/administrativo/components/GUsuario/GUsuarioLoginForm';
|
||||||
|
|
||||||
export default function LoginPage() {
|
export default function LoginPage() {
|
||||||
return (
|
return (
|
||||||
|
|
|
||||||
|
|
@ -18,14 +18,14 @@ import {
|
||||||
useSidebar,
|
useSidebar,
|
||||||
} from '@/components/ui/sidebar';
|
} from '@/components/ui/sidebar';
|
||||||
|
|
||||||
import UserAuthenticatedInterface from '@/shared/interfaces/UserAuthenticatedInterface';
|
import GUsuarioAuthenticatedInterface from '@/shared/interfaces/GUsuarioAuthenticatedInterface';
|
||||||
import ConfirmDialog from '@/shared/components/confirmDialog/ConfirmDialog';
|
import ConfirmDialog from '@/shared/components/confirmDialog/ConfirmDialog';
|
||||||
import { useUserLogoutHook } from '@/packages/administrativo/hooks/User/useUserLogoutHook';
|
import { useGUsuarioLogoutHook } from '@/packages/administrativo/hooks/GUsuario/useGUsuarioLogoutHook';
|
||||||
import { use, useCallback, useState } from 'react';
|
import { use, useCallback, useState } from 'react';
|
||||||
|
|
||||||
export function NavUser({ user }: { user: UserAuthenticatedInterface }) {
|
export function NavUser({ user }: { user: GUsuarioAuthenticatedInterface }) {
|
||||||
// Hook para encerrar sessão
|
// Hook para encerrar sessão
|
||||||
const { logoutUsuario } = useUserLogoutHook();
|
const { logoutUsuario } = useGUsuarioLogoutHook();
|
||||||
|
|
||||||
// Controle de exibição do formulário de confirmação
|
// Controle de exibição do formulário de confirmação
|
||||||
const [isConfirmOpen, setIsConfirmOpen] = useState(false);
|
const [isConfirmOpen, setIsConfirmOpen] = useState(false);
|
||||||
|
|
|
||||||
|
|
@ -6,24 +6,24 @@ import { Card, CardContent } from '@/components/ui/card';
|
||||||
import { Input } from '@/components/ui/input';
|
import { Input } from '@/components/ui/input';
|
||||||
import z from 'zod';
|
import z from 'zod';
|
||||||
import { zodResolver } from '@hookform/resolvers/zod';
|
import { zodResolver } from '@hookform/resolvers/zod';
|
||||||
import { UserLoginService } from '@/packages/administrativo/services/User/UserLoginService';
|
import GUsuarioLoginService from '@/packages/administrativo/services/GUsuario/GUsuarioLoginService';
|
||||||
import { useForm } from 'react-hook-form';
|
import { useForm } from 'react-hook-form';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from '../../../../components/ui/form';
|
import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from '../../../../components/ui/form';
|
||||||
import LoadingButton from '@/shared/components/loadingButton/LoadingButton';
|
import LoadingButton from '@/shared/components/loadingButton/LoadingButton';
|
||||||
import { Button } from '../../../../components/ui/button';
|
import { Button } from '../../../../components/ui/button';
|
||||||
import { UserLoginSchema } from '@/packages/administrativo/schemas/User/UserLoginSchema';
|
import { GUsuarioLoginSchema } from '@/packages/administrativo/schemas/GUsuario/GUsuarioLoginSchema';
|
||||||
|
|
||||||
type FormValues = z.infer<typeof UserLoginSchema>;
|
type FormValues = z.infer<typeof GUsuarioLoginSchema>;
|
||||||
|
|
||||||
export function LoginForm({ className, ...props }: React.ComponentProps<'div'>) {
|
export function LoginForm({ className, ...props }: React.ComponentProps<'div'>) {
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
const form = useForm<FormValues>({
|
const form = useForm<FormValues>({
|
||||||
resolver: zodResolver(UserLoginSchema),
|
resolver: zodResolver(GUsuarioLoginSchema),
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
email: '',
|
login: '',
|
||||||
password: '',
|
senha_api: '',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -33,7 +33,7 @@ export function LoginForm({ className, ...props }: React.ComponentProps<'div'>)
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
|
||||||
// Realiza o login
|
// Realiza o login
|
||||||
await UserLoginService(values);
|
await GUsuarioLoginService(values);
|
||||||
|
|
||||||
// Removo o estado de loading do botão
|
// Removo o estado de loading do botão
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
|
|
@ -53,7 +53,7 @@ export function LoginForm({ className, ...props }: React.ComponentProps<'div'>)
|
||||||
</div>
|
</div>
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="email"
|
name="login"
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel>Login</FormLabel>
|
<FormLabel>Login</FormLabel>
|
||||||
|
|
@ -66,7 +66,7 @@ export function LoginForm({ className, ...props }: React.ComponentProps<'div'>)
|
||||||
/>
|
/>
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="password"
|
name="senha_api"
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel>Senha</FormLabel>
|
<FormLabel>Senha</FormLabel>
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
'use server';
|
||||||
|
|
||||||
|
import { Methods } from '@/shared/services/api/enums/ApiMethodEnum';
|
||||||
|
import API from '@/shared/services/api/Api';
|
||||||
|
|
||||||
|
export default async function GUsuarioLoginData(form: any) {
|
||||||
|
const api = new API();
|
||||||
|
// Realiza o envio dos dados
|
||||||
|
const response = await api.send({
|
||||||
|
method: Methods.POST,
|
||||||
|
endpoint: `administrativo/g_usuario/authenticate`,
|
||||||
|
body: form,
|
||||||
|
});
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
'use server'
|
|
||||||
|
|
||||||
import { Methods } from '@/shared/services/api/enums/ApiMethodEnum';
|
|
||||||
import API from '@/shared/services/api/Api';
|
|
||||||
import { withClientErrorHandler } from '@/withClientErrorHandler/withClientErrorHandler';
|
|
||||||
|
|
||||||
async function executeUserDeleteData(usuarioId: number) {
|
|
||||||
|
|
||||||
const api = new API();
|
|
||||||
|
|
||||||
const response = await api.send({
|
|
||||||
'method': Methods.DELETE,
|
|
||||||
'endpoint': `administrativo/user/${usuarioId}`
|
|
||||||
});
|
|
||||||
|
|
||||||
return response;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
export const UserDeleteData = withClientErrorHandler(executeUserDeleteData)
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
'use server'
|
|
||||||
import { Methods } from '@/shared/services/api/enums/ApiMethodEnum';
|
|
||||||
import API from '@/shared/services/api/Api';
|
|
||||||
import { withClientErrorHandler } from '@/withClientErrorHandler/withClientErrorHandler';
|
|
||||||
|
|
||||||
async function executeUserIndexByEmailData(email: string) {
|
|
||||||
|
|
||||||
const api = new API();
|
|
||||||
|
|
||||||
const response = await api.send({
|
|
||||||
'method': Methods.GET,
|
|
||||||
'endpoint': `administrativo/user/email?email=${email}`
|
|
||||||
});
|
|
||||||
|
|
||||||
return response;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
export const UserIndexByEmailData = withClientErrorHandler(executeUserIndexByEmailData)
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
'use server'
|
|
||||||
import { Methods } from '@/shared/services/api/enums/ApiMethodEnum';
|
|
||||||
import API from '@/shared/services/api/Api';
|
|
||||||
import { withClientErrorHandler } from '@/withClientErrorHandler/withClientErrorHandler';
|
|
||||||
|
|
||||||
async function executeUserIndexByIDData(user_id: number) {
|
|
||||||
|
|
||||||
const api = new API();
|
|
||||||
|
|
||||||
const response = await api.send({
|
|
||||||
'method': Methods.GET,
|
|
||||||
'endpoint': `administrativo/user/${user_id}`
|
|
||||||
});
|
|
||||||
|
|
||||||
return response;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
export const UserIndexByIDData = withClientErrorHandler(executeUserIndexByIDData)
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
'use server'
|
|
||||||
import { Methods } from '@/shared/services/api/enums/ApiMethodEnum';
|
|
||||||
import API from '@/shared/services/api/Api';
|
|
||||||
import { withClientErrorHandler } from '@/withClientErrorHandler/withClientErrorHandler';
|
|
||||||
|
|
||||||
async function executeUserIndexData() {
|
|
||||||
|
|
||||||
const api = new API();
|
|
||||||
|
|
||||||
const response = await api.send({
|
|
||||||
'method': Methods.GET,
|
|
||||||
'endpoint': `administrativo/user`
|
|
||||||
});
|
|
||||||
|
|
||||||
return response;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
export const UserIndexData = withClientErrorHandler(executeUserIndexData)
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
'use server'
|
|
||||||
import { Methods } from '@/shared/services/api/enums/ApiMethodEnum';
|
|
||||||
import API from '@/shared/services/api/Api';
|
|
||||||
import { withClientErrorHandler } from '@/withClientErrorHandler/withClientErrorHandler';
|
|
||||||
|
|
||||||
async function executeUserLoggedIndexData() {
|
|
||||||
|
|
||||||
const api = new API();
|
|
||||||
|
|
||||||
const response = await api.send({
|
|
||||||
'method': Methods.GET,
|
|
||||||
'endpoint': `administrativo/user/me`
|
|
||||||
});
|
|
||||||
|
|
||||||
return response;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
export const UserLoggedIndexData = withClientErrorHandler(executeUserLoggedIndexData)
|
|
||||||
|
|
@ -1,21 +0,0 @@
|
||||||
'use server';
|
|
||||||
|
|
||||||
import { Methods } from '@/shared/services/api/enums/ApiMethodEnum';
|
|
||||||
import API from '@/shared/services/api/Api';
|
|
||||||
import { AuthenticateUserInterface } from '@/shared/interfaces/AuthenticateUserInterface';
|
|
||||||
import { withClientErrorHandler } from '@/withClientErrorHandler/withClientErrorHandler';
|
|
||||||
|
|
||||||
async function executeUserLoginData(form: AuthenticateUserInterface) {
|
|
||||||
const api = new API();
|
|
||||||
|
|
||||||
const response = await api.send({
|
|
||||||
method: Methods.POST,
|
|
||||||
endpoint: `administrativo/user/authenticate`,
|
|
||||||
body: form,
|
|
||||||
});
|
|
||||||
|
|
||||||
return response;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
export const UserLoginData = withClientErrorHandler(executeUserLoginData)
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
'use server'
|
|
||||||
|
|
||||||
import { Methods } from '@/shared/services/api/enums/ApiMethodEnum';
|
|
||||||
import API from '@/shared/services/api/Api';
|
|
||||||
import { withClientErrorHandler } from '@/withClientErrorHandler/withClientErrorHandler';
|
|
||||||
|
|
||||||
async function executeUserReadData(usuarioId: number) {
|
|
||||||
|
|
||||||
const api = new API();
|
|
||||||
|
|
||||||
const response = await api.send({
|
|
||||||
'method': Methods.GET,
|
|
||||||
'endpoint': `administrativo/user/${usuarioId}`
|
|
||||||
});
|
|
||||||
|
|
||||||
return response
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
export const UserReadData = withClientErrorHandler(executeUserReadData)
|
|
||||||
|
|
@ -1,22 +0,0 @@
|
||||||
'use server'
|
|
||||||
|
|
||||||
import { Methods } from '@/shared/services/api/enums/ApiMethodEnum';
|
|
||||||
import API from '@/shared/services/api/Api';
|
|
||||||
import { withClientErrorHandler } from '@/withClientErrorHandler/withClientErrorHandler';
|
|
||||||
import { UserInterface } from '../../interfaces/User/UserInterface';
|
|
||||||
|
|
||||||
async function executeUserSaveData(data: UserInterface) {
|
|
||||||
|
|
||||||
const api = new API();
|
|
||||||
|
|
||||||
const response = await api.send({
|
|
||||||
'method': data.user_id ? Methods.PUT : Methods.POST,
|
|
||||||
'endpoint': `administrativo/user/${data.user_id ? data.user_id : ''}`,
|
|
||||||
'body': data
|
|
||||||
});
|
|
||||||
|
|
||||||
return response;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
export const UserSaveData = withClientErrorHandler(executeUserSaveData)
|
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
'use client';
|
||||||
|
|
||||||
|
import GUsuarioLogoutService from '../../services/GUsuario/GUsuarioLogoutService';
|
||||||
|
|
||||||
|
export const useGUsuarioLogoutHook = () => {
|
||||||
|
const logoutUsuario = async () => {
|
||||||
|
await GUsuarioLogoutService('access_token');
|
||||||
|
};
|
||||||
|
|
||||||
|
return { logoutUsuario };
|
||||||
|
};
|
||||||
|
|
@ -1,11 +0,0 @@
|
||||||
'use client';
|
|
||||||
|
|
||||||
import { UserLogoutService } from '../../services/User/UserLogoutService';
|
|
||||||
|
|
||||||
export const useUserLogoutHook = () => {
|
|
||||||
const logoutUsuario = async () => {
|
|
||||||
await UserLogoutService('access_token');
|
|
||||||
};
|
|
||||||
|
|
||||||
return { logoutUsuario };
|
|
||||||
};
|
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
export default interface GUsuario {
|
||||||
|
usuario_id: number;
|
||||||
|
trocarsenha: string;
|
||||||
|
login: string;
|
||||||
|
senha: string;
|
||||||
|
situacao: string;
|
||||||
|
nome_completo: string;
|
||||||
|
funcao: string;
|
||||||
|
assina: string;
|
||||||
|
sigla: string;
|
||||||
|
usuario_tab: string;
|
||||||
|
ultimo_login: string;
|
||||||
|
ultimo_login_regs: string;
|
||||||
|
data_expiracao: string;
|
||||||
|
senha_anterior: string;
|
||||||
|
andamento_padrao: string;
|
||||||
|
lembrete_pergunta: string;
|
||||||
|
lembrete_resposta: string;
|
||||||
|
andamento_padrao2: string;
|
||||||
|
receber_mensagem_arrolamento: string;
|
||||||
|
email: string;
|
||||||
|
assina_certidao: string;
|
||||||
|
receber_email_penhora: string;
|
||||||
|
foto: string;
|
||||||
|
nao_receber_chat_todos: string;
|
||||||
|
pode_alterar_caixa: string;
|
||||||
|
receber_chat_certidao_online: string;
|
||||||
|
receber_chat_cancelamento: string;
|
||||||
|
cpf: string;
|
||||||
|
somente_leitura: string;
|
||||||
|
receber_chat_envio_onr: string;
|
||||||
|
tipo_usuario: string;
|
||||||
|
senha_api: string;
|
||||||
|
}
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
import { SituacoesEnum } from "@/shared/enums/SituacoesEnum";
|
|
||||||
|
|
||||||
export interface UserInterface {
|
|
||||||
user_id: number;
|
|
||||||
name: string;
|
|
||||||
email: string;
|
|
||||||
password: string; // Presumo que seja uma string com hash
|
|
||||||
password_temp: string | null; // Pode ser "N" ou outro valor, ou null
|
|
||||||
password_temp_confirm: string; // Pode ser "N"
|
|
||||||
position: string | null; // Pode ser uma string ou null
|
|
||||||
team: string; // Equipe onde o usuário pertence
|
|
||||||
status: SituacoesEnum; // A ou I
|
|
||||||
date_register: string; // Data de registro no formato ISO 8601
|
|
||||||
date_update: string | null; // Data de atualização ou null
|
|
||||||
user_id_create: number | null; // ID do usuário que criou (se aplicável)
|
|
||||||
user_id_update: number | null; // ID do usuário que fez a última atualização (se aplicável)
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
import { z } from 'zod';
|
||||||
|
|
||||||
|
export const GUsuarioLoginSchema = z.object({
|
||||||
|
login: z.string().min(1, 'O campo deve ser preenchido'),
|
||||||
|
senha_api: z.string().min(1, 'O campo deve ser preenchido'),
|
||||||
|
});
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
import { z } from 'zod';
|
|
||||||
|
|
||||||
export const UserLoginSchema = z.object({
|
|
||||||
email: z.string().min(1, 'O campo deve ser preenchido'),
|
|
||||||
password: z.string().min(1, 'O campo deve ser preenchido'),
|
|
||||||
});
|
|
||||||
|
|
@ -2,15 +2,14 @@
|
||||||
|
|
||||||
import { cookies } from 'next/headers';
|
import { cookies } from 'next/headers';
|
||||||
|
|
||||||
import { UserLoginData } from '../../data/User/UserLoginData';
|
import GUsuarioLoginData from '../../data/GUsuario/GUsuarioLoginData';
|
||||||
import { redirect } from 'next/navigation';
|
import { redirect } from 'next/navigation';
|
||||||
import { withClientErrorHandler } from '@/withClientErrorHandler/withClientErrorHandler';
|
|
||||||
|
|
||||||
async function executeUserLoginService(form: any) {
|
export default async function GUsuarioLoginService(form: any) {
|
||||||
// Obtem a resposta da requisição
|
// Obtem a resposta da requisição
|
||||||
const response = await UserLoginData(form);
|
const response = await GUsuarioLoginData(form);
|
||||||
// Verifica se localizou o usuário
|
// Verifica se localizou o usuário
|
||||||
if (response.data.user_id <= 0) {
|
if (response.data.usuario_id <= 0) {
|
||||||
return {
|
return {
|
||||||
code: 404,
|
code: 404,
|
||||||
message: 'Não foi localizado o usuário',
|
message: 'Não foi localizado o usuário',
|
||||||
|
|
@ -30,7 +29,5 @@ async function executeUserLoginService(form: any) {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Redireciona para a págian desejada
|
// Redireciona para a págian desejada
|
||||||
redirect('/user');
|
redirect('/servicos');
|
||||||
}
|
}
|
||||||
|
|
||||||
export const UserLoginService = withClientErrorHandler(executeUserLoginService)
|
|
||||||
|
|
@ -1,11 +1,10 @@
|
||||||
'use server';
|
'use server';
|
||||||
|
|
||||||
import { withClientErrorHandler } from '@/withClientErrorHandler/withClientErrorHandler';
|
|
||||||
import { cookies } from 'next/headers';
|
import { cookies } from 'next/headers';
|
||||||
|
|
||||||
import { redirect } from 'next/navigation';
|
import { redirect } from 'next/navigation';
|
||||||
|
|
||||||
async function executeUserLogoutService(token: string) {
|
export default async function GUsuarioLogoutService(token: string) {
|
||||||
const cookieStore = await cookies();
|
const cookieStore = await cookies();
|
||||||
cookieStore.set(token, '', {
|
cookieStore.set(token, '', {
|
||||||
expires: new Date(0),
|
expires: new Date(0),
|
||||||
|
|
@ -14,5 +13,3 @@ async function executeUserLogoutService(token: string) {
|
||||||
|
|
||||||
redirect('/login');
|
redirect('/login');
|
||||||
}
|
}
|
||||||
|
|
||||||
export const UserLogoutService = withClientErrorHandler(executeUserLogoutService)
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
'use server'
|
|
||||||
|
|
||||||
import { withClientErrorHandler } from "@/withClientErrorHandler/withClientErrorHandler"
|
|
||||||
import { UserDeleteData } from "../../data/User/UserDeleteData"
|
|
||||||
|
|
||||||
async function executeUserDeleteService(usuarioId: number) {
|
|
||||||
|
|
||||||
if (usuarioId <= 0) {
|
|
||||||
return {
|
|
||||||
'code': 400,
|
|
||||||
'message': 'Usuário informado inválido',
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const response = await UserDeleteData(usuarioId)
|
|
||||||
return response
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
export const UserDeleteService = withClientErrorHandler(executeUserDeleteService)
|
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
'use server'
|
|
||||||
|
|
||||||
import { withClientErrorHandler } from "@/withClientErrorHandler/withClientErrorHandler";
|
|
||||||
import { UserIndexByEmailData } from "../../data/User/UserIndexByEmailData";
|
|
||||||
|
|
||||||
async function executeUserIndexByEmailService(email: string) {
|
|
||||||
|
|
||||||
const response = await UserIndexByEmailData(email);
|
|
||||||
|
|
||||||
return response;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
export const UserIndexByEmailService = withClientErrorHandler(executeUserIndexByEmailService)
|
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
'use server'
|
|
||||||
|
|
||||||
import { withClientErrorHandler } from "@/withClientErrorHandler/withClientErrorHandler";
|
|
||||||
import { UserIndexByIDData } from "../../data/User/UserIndexByIDData";
|
|
||||||
|
|
||||||
async function executeUserIndexByIDService(user_id: number) {
|
|
||||||
|
|
||||||
const response = await UserIndexByIDData(user_id);
|
|
||||||
|
|
||||||
return response;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
export const UserIndexByIDService = withClientErrorHandler(executeUserIndexByIDService)
|
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
'use server'
|
|
||||||
|
|
||||||
import { withClientErrorHandler } from "@/withClientErrorHandler/withClientErrorHandler";
|
|
||||||
import { UserIndexData } from "../../data/User/UserIndexData";
|
|
||||||
|
|
||||||
async function executeUserIndexService() {
|
|
||||||
|
|
||||||
const response = await UserIndexData();
|
|
||||||
|
|
||||||
return response;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
export const UserIndexService = withClientErrorHandler(executeUserIndexService)
|
|
||||||
|
|
@ -1,22 +0,0 @@
|
||||||
'use server'
|
|
||||||
|
|
||||||
import { withClientErrorHandler } from "@/withClientErrorHandler/withClientErrorHandler";
|
|
||||||
import { UserReadData } from "../../data/User/UserReadData";
|
|
||||||
|
|
||||||
async function executeUserReadService(usuarioId: number) {
|
|
||||||
|
|
||||||
// Verifica se o id informado é válido
|
|
||||||
if (usuarioId <= 0) {
|
|
||||||
return {
|
|
||||||
'code': 400,
|
|
||||||
'message': 'Usuário informado inválido',
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const response = await UserReadData(usuarioId);
|
|
||||||
return response
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
export const UserReadService = withClientErrorHandler(executeUserReadService)
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
'use server'
|
|
||||||
|
|
||||||
import { withClientErrorHandler } from "@/withClientErrorHandler/withClientErrorHandler";
|
|
||||||
import { UserSaveData } from "../../data/User/UserSaveData";
|
|
||||||
|
|
||||||
async function executeUserSave(form: any) {
|
|
||||||
|
|
||||||
return await UserSaveData(form);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
export const UserSave = withClientErrorHandler(executeUserSave)
|
|
||||||
|
|
@ -4,7 +4,7 @@ import { useEffect, useState } from 'react';
|
||||||
import { jwtDecode } from 'jwt-decode';
|
import { jwtDecode } from 'jwt-decode';
|
||||||
import CookiesGet from '../../actions/cookies/CookiesGet';
|
import CookiesGet from '../../actions/cookies/CookiesGet';
|
||||||
import GetSigla from '@/shared/actions/text/GetSigla';
|
import GetSigla from '@/shared/actions/text/GetSigla';
|
||||||
import GUsuarioAuthenticatedInterface from '@/shared/interfaces/UserAuthenticatedInterface';
|
import GUsuarioAuthenticatedInterface from '@/shared/interfaces/GUsuarioAuthenticatedInterface';
|
||||||
|
|
||||||
interface JwtPayload {
|
interface JwtPayload {
|
||||||
id: string;
|
id: string;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +0,0 @@
|
||||||
export interface AuthenticateUserInterface {
|
|
||||||
email: string;
|
|
||||||
password: string
|
|
||||||
}
|
|
||||||
7
src/shared/interfaces/GUsuarioAuthenticatedInterface.ts
Normal file
7
src/shared/interfaces/GUsuarioAuthenticatedInterface.ts
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
export default interface GUsuarioAuthenticatedInterface {
|
||||||
|
usuario_id?: number;
|
||||||
|
login?: string;
|
||||||
|
nome?: string;
|
||||||
|
email?: string;
|
||||||
|
sigla?: string;
|
||||||
|
}
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
export default interface UserAuthenticatedInterface {
|
|
||||||
user_id?: number;
|
|
||||||
login?: string;
|
|
||||||
nome?: string;
|
|
||||||
email?: string;
|
|
||||||
sigla?: string;
|
|
||||||
}
|
|
||||||
|
|
@ -39,7 +39,6 @@ export default class API {
|
||||||
? Object.fromEntries(Object.entries(_data.body).filter(([_, v]) => v != null && v !== ''))
|
? Object.fromEntries(Object.entries(_data.body).filter(([_, v]) => v != null && v !== ''))
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
console.log(`${this.ApiSchema.url}${this.ApiSchema.prefix}${this.ApiSchema.endpoint}`)
|
|
||||||
// Realiza a requisição
|
// Realiza a requisição
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
`${this.ApiSchema.url}${this.ApiSchema.prefix}${this.ApiSchema.endpoint}`,
|
`${this.ApiSchema.url}${this.ApiSchema.prefix}${this.ApiSchema.endpoint}`,
|
||||||
|
|
|
||||||
|
|
@ -1,32 +0,0 @@
|
||||||
import withClientErrorHandlerInterface from "./withClientErrorHandlerInterface";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Códigos de erro que começam com 6, são do front entd, na ordem do alfabeto o F de frontend é a sexta letra
|
|
||||||
*/
|
|
||||||
export function withClientErrorHandler<T extends (...args: any[]) => Promise<any>>(
|
|
||||||
action: T
|
|
||||||
) {
|
|
||||||
return async (...args: Parameters<T>): Promise<withClientErrorHandlerInterface> => {
|
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
// Executa a função definida
|
|
||||||
const data = await action(...args);
|
|
||||||
|
|
||||||
// Retorna exatamente a mesma resposta retornada pela função
|
|
||||||
return data;
|
|
||||||
|
|
||||||
} catch (error: any) {
|
|
||||||
|
|
||||||
// Retorna o erro de execuçãformatado
|
|
||||||
return {
|
|
||||||
status: 600,
|
|
||||||
message: error?.message || "Erro interno do servidor",
|
|
||||||
data: error
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
export default interface withClientErrorHandlerInterface<T = any> {
|
|
||||||
|
|
||||||
status: number;
|
|
||||||
data?: T;
|
|
||||||
message?: string;
|
|
||||||
|
|
||||||
}
|
|
||||||
Loading…
Add table
Reference in a new issue