Compare commits
3 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e33bb452cf | ||
|
|
a8eb911832 | ||
|
|
3ff500b515 |
38 changed files with 459 additions and 95 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
import { LoginForm } from '@/packages/administrativo/components/GUsuario/GUsuarioLoginForm';
|
import { LoginForm } from '@/packages/administrativo/components/User/UserLoginForm';
|
||||||
|
|
||||||
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 GUsuarioAuthenticatedInterface from '@/shared/interfaces/GUsuarioAuthenticatedInterface';
|
import UserAuthenticatedInterface from '@/shared/interfaces/UserAuthenticatedInterface';
|
||||||
import ConfirmDialog from '@/shared/components/confirmDialog/ConfirmDialog';
|
import ConfirmDialog from '@/shared/components/confirmDialog/ConfirmDialog';
|
||||||
import { useGUsuarioLogoutHook } from '@/packages/administrativo/hooks/GUsuario/useGUsuarioLogoutHook';
|
import { useUserLogoutHook } from '@/packages/administrativo/hooks/User/useUserLogoutHook';
|
||||||
import { use, useCallback, useState } from 'react';
|
import { use, useCallback, useState } from 'react';
|
||||||
|
|
||||||
export function NavUser({ user }: { user: GUsuarioAuthenticatedInterface }) {
|
export function NavUser({ user }: { user: UserAuthenticatedInterface }) {
|
||||||
// Hook para encerrar sessão
|
// Hook para encerrar sessão
|
||||||
const { logoutUsuario } = useGUsuarioLogoutHook();
|
const { logoutUsuario } = useUserLogoutHook();
|
||||||
|
|
||||||
// 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 GUsuarioLoginService from '@/packages/administrativo/services/GUsuario/GUsuarioLoginService';
|
import { UserLoginService } from '@/packages/administrativo/services/User/UserLoginService';
|
||||||
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 { GUsuarioLoginSchema } from '@/packages/administrativo/schemas/GUsuario/GUsuarioLoginSchema';
|
import { UserLoginSchema } from '@/packages/administrativo/schemas/User/UserLoginSchema';
|
||||||
|
|
||||||
type FormValues = z.infer<typeof GUsuarioLoginSchema>;
|
type FormValues = z.infer<typeof UserLoginSchema>;
|
||||||
|
|
||||||
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(GUsuarioLoginSchema),
|
resolver: zodResolver(UserLoginSchema),
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
login: '',
|
email: '',
|
||||||
senha_api: '',
|
password: '',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -33,7 +33,7 @@ export function LoginForm({ className, ...props }: React.ComponentProps<'div'>)
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
|
||||||
// Realiza o login
|
// Realiza o login
|
||||||
await GUsuarioLoginService(values);
|
await UserLoginService(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="login"
|
name="email"
|
||||||
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="senha_api"
|
name="password"
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel>Senha</FormLabel>
|
<FormLabel>Senha</FormLabel>
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
'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;
|
|
||||||
}
|
|
||||||
20
src/packages/administrativo/data/User/UserDeleteData.ts
Normal file
20
src/packages/administrativo/data/User/UserDeleteData.ts
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
'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)
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
'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)
|
||||||
19
src/packages/administrativo/data/User/UserIndexByIDData.ts
Normal file
19
src/packages/administrativo/data/User/UserIndexByIDData.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
'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)
|
||||||
19
src/packages/administrativo/data/User/UserIndexData.ts
Normal file
19
src/packages/administrativo/data/User/UserIndexData.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
'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)
|
||||||
19
src/packages/administrativo/data/User/UserLoggedIndexData.ts
Normal file
19
src/packages/administrativo/data/User/UserLoggedIndexData.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
'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)
|
||||||
21
src/packages/administrativo/data/User/UserLoginData.ts
Normal file
21
src/packages/administrativo/data/User/UserLoginData.ts
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
'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)
|
||||||
20
src/packages/administrativo/data/User/UserReadData.ts
Normal file
20
src/packages/administrativo/data/User/UserReadData.ts
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
'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)
|
||||||
22
src/packages/administrativo/data/User/UserSaveData.ts
Normal file
22
src/packages/administrativo/data/User/UserSaveData.ts
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
'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)
|
||||||
|
|
@ -1,11 +0,0 @@
|
||||||
'use client';
|
|
||||||
|
|
||||||
import GUsuarioLogoutService from '../../services/GUsuario/GUsuarioLogoutService';
|
|
||||||
|
|
||||||
export const useGUsuarioLogoutHook = () => {
|
|
||||||
const logoutUsuario = async () => {
|
|
||||||
await GUsuarioLogoutService('access_token');
|
|
||||||
};
|
|
||||||
|
|
||||||
return { logoutUsuario };
|
|
||||||
};
|
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
'use client';
|
||||||
|
|
||||||
|
import { useState } from 'react';
|
||||||
|
import { UserInterface } from '../../interfaces/User/UserInterface';
|
||||||
|
import { UserReadService } from '../../services/User/UserReadService';
|
||||||
|
import { useResponse } from '@/shared/components/response/ResponseContext';
|
||||||
|
|
||||||
|
export const useGUserReadHooks = () => {
|
||||||
|
const { setResponse } = useResponse();
|
||||||
|
|
||||||
|
const [User, setUser] = useState<UserInterface>();
|
||||||
|
|
||||||
|
const fetchUser = async (User: UserInterface) => {
|
||||||
|
const response = await UserReadService(User.user_id);
|
||||||
|
|
||||||
|
setUser(response.data);
|
||||||
|
|
||||||
|
setResponse(response);
|
||||||
|
};
|
||||||
|
|
||||||
|
return { User, fetchUser };
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
'use client';
|
||||||
|
|
||||||
|
import { useState } from 'react';
|
||||||
|
import { UserInterface } from '../../interfaces/User/UserInterface';
|
||||||
|
import { UserSaveService } from '../../services/User/UserSaveService';
|
||||||
|
import { useResponse } from '@/shared/components/response/ResponseContext';
|
||||||
|
|
||||||
|
export const useGUserSaveHook = () => {
|
||||||
|
const { setResponse } = useResponse();
|
||||||
|
|
||||||
|
const [User, setUser] = useState<UserInterface>();
|
||||||
|
|
||||||
|
const saveUser = async (User: any) => {
|
||||||
|
const response = await UserSaveService(User);
|
||||||
|
|
||||||
|
setUser(response.data);
|
||||||
|
|
||||||
|
setResponse(response);
|
||||||
|
};
|
||||||
|
|
||||||
|
return { User, saveUser };
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
'use client';
|
||||||
|
|
||||||
|
import { useState } from 'react';
|
||||||
|
import { UserInterface } from '../../interfaces/User/UserInterface';
|
||||||
|
import { UserIndexByEmailService } from '../../services/User/UserIndexByEmailService';
|
||||||
|
import { useResponse } from '@/shared/components/response/ResponseContext';
|
||||||
|
|
||||||
|
export const useUserIndexByEmailHook = () => {
|
||||||
|
const { setResponse } = useResponse();
|
||||||
|
|
||||||
|
const [user, setUser] = useState<UserInterface | null>(null);
|
||||||
|
|
||||||
|
const fetchUserByEmail = async (email: string) => {
|
||||||
|
try {
|
||||||
|
const response = await UserIndexByEmailService(email);
|
||||||
|
|
||||||
|
setUser(response.data);
|
||||||
|
setResponse(response);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Erro ao buscar usuário por Email:", error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return { user, fetchUserByEmail };
|
||||||
|
};
|
||||||
23
src/packages/administrativo/hooks/User/useUserIndexHook.ts
Normal file
23
src/packages/administrativo/hooks/User/useUserIndexHook.ts
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
'use client';
|
||||||
|
|
||||||
|
import { useState } from 'react';
|
||||||
|
import { UserInterface } from '../../interfaces/User/UserInterface';
|
||||||
|
import { UserIndexService } from '../../services/User/UserIndexService';
|
||||||
|
import { useResponse } from '@/shared/components/response/ResponseContext';
|
||||||
|
|
||||||
|
export const useUserIndexHook = () => {
|
||||||
|
const { setResponse } = useResponse();
|
||||||
|
|
||||||
|
const [usuarios, setUsuarios] = useState<UserInterface[] | null>(null);
|
||||||
|
|
||||||
|
const fetchUsuarios = async () => {
|
||||||
|
const response = await UserIndexService();
|
||||||
|
|
||||||
|
setUsuarios(response.data);
|
||||||
|
|
||||||
|
// Define os dados do componente de resposta (toast, modal, etc)
|
||||||
|
setResponse(response);
|
||||||
|
};
|
||||||
|
|
||||||
|
return { usuarios, fetchUsuarios };
|
||||||
|
};
|
||||||
11
src/packages/administrativo/hooks/User/useUserLogoutHook.ts
Normal file
11
src/packages/administrativo/hooks/User/useUserLogoutHook.ts
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
'use client';
|
||||||
|
|
||||||
|
import { UserLogoutService } from '../../services/User/UserLogoutService';
|
||||||
|
|
||||||
|
export const useUserLogoutHook = () => {
|
||||||
|
const logoutUsuario = async () => {
|
||||||
|
await UserLogoutService('access_token');
|
||||||
|
};
|
||||||
|
|
||||||
|
return { logoutUsuario };
|
||||||
|
};
|
||||||
|
|
@ -1,34 +0,0 @@
|
||||||
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;
|
|
||||||
}
|
|
||||||
17
src/packages/administrativo/interfaces/User/UserInterface.ts
Normal file
17
src/packages/administrativo/interfaces/User/UserInterface.ts
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
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'),
|
|
||||||
});
|
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
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'),
|
||||||
|
});
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
'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)
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
'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)
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
'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)
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
'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)
|
||||||
|
|
@ -2,14 +2,15 @@
|
||||||
|
|
||||||
import { cookies } from 'next/headers';
|
import { cookies } from 'next/headers';
|
||||||
|
|
||||||
import GUsuarioLoginData from '../../data/GUsuario/GUsuarioLoginData';
|
import { UserLoginData } from '../../data/User/UserLoginData';
|
||||||
import { redirect } from 'next/navigation';
|
import { redirect } from 'next/navigation';
|
||||||
|
import { withClientErrorHandler } from '@/withClientErrorHandler/withClientErrorHandler';
|
||||||
|
|
||||||
export default async function GUsuarioLoginService(form: any) {
|
async function executeUserLoginService(form: any) {
|
||||||
// Obtem a resposta da requisição
|
// Obtem a resposta da requisição
|
||||||
const response = await GUsuarioLoginData(form);
|
const response = await UserLoginData(form);
|
||||||
// Verifica se localizou o usuário
|
// Verifica se localizou o usuário
|
||||||
if (response.data.usuario_id <= 0) {
|
if (response.data.user_id <= 0) {
|
||||||
return {
|
return {
|
||||||
code: 404,
|
code: 404,
|
||||||
message: 'Não foi localizado o usuário',
|
message: 'Não foi localizado o usuário',
|
||||||
|
|
@ -29,5 +30,7 @@ export default async function GUsuarioLoginService(form: any) {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Redireciona para a págian desejada
|
// Redireciona para a págian desejada
|
||||||
redirect('/servicos');
|
redirect('/user');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const UserLoginService = withClientErrorHandler(executeUserLoginService)
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
'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';
|
||||||
|
|
||||||
export default async function GUsuarioLogoutService(token: string) {
|
async function executeUserLogoutService(token: string) {
|
||||||
const cookieStore = await cookies();
|
const cookieStore = await cookies();
|
||||||
cookieStore.set(token, '', {
|
cookieStore.set(token, '', {
|
||||||
expires: new Date(0),
|
expires: new Date(0),
|
||||||
|
|
@ -13,3 +14,5 @@ export default async function GUsuarioLogoutService(token: string) {
|
||||||
|
|
||||||
redirect('/login');
|
redirect('/login');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const UserLogoutService = withClientErrorHandler(executeUserLogoutService)
|
||||||
22
src/packages/administrativo/services/User/UserReadService.ts
Normal file
22
src/packages/administrativo/services/User/UserReadService.ts
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
'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)
|
||||||
12
src/packages/administrativo/services/User/UserSaveService.ts
Normal file
12
src/packages/administrativo/services/User/UserSaveService.ts
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
'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/GUsuarioAuthenticatedInterface';
|
import GUsuarioAuthenticatedInterface from '@/shared/interfaces/UserAuthenticatedInterface';
|
||||||
|
|
||||||
interface JwtPayload {
|
interface JwtPayload {
|
||||||
id: string;
|
id: string;
|
||||||
|
|
|
||||||
4
src/shared/interfaces/AuthenticateUserInterface.ts
Normal file
4
src/shared/interfaces/AuthenticateUserInterface.ts
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
export interface AuthenticateUserInterface {
|
||||||
|
email: string;
|
||||||
|
password: string
|
||||||
|
}
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
export default interface GUsuarioAuthenticatedInterface {
|
|
||||||
usuario_id?: number;
|
|
||||||
login?: string;
|
|
||||||
nome?: string;
|
|
||||||
email?: string;
|
|
||||||
sigla?: string;
|
|
||||||
}
|
|
||||||
7
src/shared/interfaces/UserAuthenticatedInterface.ts
Normal file
7
src/shared/interfaces/UserAuthenticatedInterface.ts
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
export default interface UserAuthenticatedInterface {
|
||||||
|
user_id?: number;
|
||||||
|
login?: string;
|
||||||
|
nome?: string;
|
||||||
|
email?: string;
|
||||||
|
sigla?: string;
|
||||||
|
}
|
||||||
|
|
@ -39,6 +39,7 @@ 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}`,
|
||||||
|
|
|
||||||
32
src/withClientErrorHandler/withClientErrorHandler.ts
Normal file
32
src/withClientErrorHandler/withClientErrorHandler.ts
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
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
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
export default interface withClientErrorHandlerInterface<T = any> {
|
||||||
|
|
||||||
|
status: number;
|
||||||
|
data?: T;
|
||||||
|
message?: string;
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue