[VDU-2] feat(implementando): endpoint para obter dados do usuário logado
This commit is contained in:
parent
3ff500b515
commit
a8eb911832
10 changed files with 98 additions and 12 deletions
|
|
@ -18,14 +18,14 @@ import {
|
|||
useSidebar,
|
||||
} from '@/components/ui/sidebar';
|
||||
|
||||
import GUsuarioAuthenticatedInterface from '@/shared/interfaces/GUsuarioAuthenticatedInterface';
|
||||
import UserAuthenticatedInterface from '@/shared/interfaces/UserAuthenticatedInterface';
|
||||
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';
|
||||
|
||||
export function NavUser({ user }: { user: GUsuarioAuthenticatedInterface }) {
|
||||
export function NavUser({ user }: { user: UserAuthenticatedInterface }) {
|
||||
// Hook para encerrar sessão
|
||||
const { logoutUsuario } = useGUsuarioLogoutHook();
|
||||
const { logoutUsuario } = useUserLogoutHook();
|
||||
|
||||
// Controle de exibição do formulário de confirmação
|
||||
const [isConfirmOpen, setIsConfirmOpen] = useState(false);
|
||||
|
|
|
|||
|
|
@ -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/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)
|
||||
|
|
@ -3,15 +3,16 @@
|
|||
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(form: any) {
|
||||
async function executeUserSaveData(data: UserInterface) {
|
||||
|
||||
const api = new API();
|
||||
|
||||
const response = await api.send({
|
||||
'method': Methods.POST,
|
||||
'endpoint': `administrativo/user/`,
|
||||
'body': form
|
||||
'method': data.user_id ? Methods.PUT : Methods.POST,
|
||||
'endpoint': `administrativo/user/${data.user_id ? data.user_id : ''}`,
|
||||
'body': data
|
||||
});
|
||||
|
||||
return response;
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
'use client';
|
||||
|
||||
import UserLogoutService from '../../services/User/UserLogoutService';
|
||||
import { UserLogoutService } from '../../services/User/UserLogoutService';
|
||||
|
||||
export const useGUsuarioLogoutHook = () => {
|
||||
export const useUserLogoutHook = () => {
|
||||
const logoutUsuario = async () => {
|
||||
await UserLogoutService('access_token');
|
||||
};
|
||||
|
|
@ -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)
|
||||
|
|
@ -4,7 +4,7 @@ import { useEffect, useState } from 'react';
|
|||
import { jwtDecode } from 'jwt-decode';
|
||||
import CookiesGet from '../../actions/cookies/CookiesGet';
|
||||
import GetSigla from '@/shared/actions/text/GetSigla';
|
||||
import GUsuarioAuthenticatedInterface from '@/shared/interfaces/GUsuarioAuthenticatedInterface';
|
||||
import GUsuarioAuthenticatedInterface from '@/shared/interfaces/UserAuthenticatedInterface';
|
||||
|
||||
interface JwtPayload {
|
||||
id: string;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
export default interface GUsuarioAuthenticatedInterface {
|
||||
export default interface UserAuthenticatedInterface {
|
||||
user_id?: number;
|
||||
login?: string;
|
||||
nome?: string;
|
||||
Loading…
Add table
Reference in a new issue