[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,
|
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);
|
||||||
|
|
|
||||||
|
|
@ -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 { Methods } from '@/shared/services/api/enums/ApiMethodEnum';
|
||||||
import API from '@/shared/services/api/Api';
|
import API from '@/shared/services/api/Api';
|
||||||
import { withClientErrorHandler } from '@/withClientErrorHandler/withClientErrorHandler';
|
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 api = new API();
|
||||||
|
|
||||||
const response = await api.send({
|
const response = await api.send({
|
||||||
'method': Methods.POST,
|
'method': data.user_id ? Methods.PUT : Methods.POST,
|
||||||
'endpoint': `administrativo/user/`,
|
'endpoint': `administrativo/user/${data.user_id ? data.user_id : ''}`,
|
||||||
'body': form
|
'body': data
|
||||||
});
|
});
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import UserLogoutService from '../../services/User/UserLogoutService';
|
import { UserLogoutService } from '../../services/User/UserLogoutService';
|
||||||
|
|
||||||
export const useGUsuarioLogoutHook = () => {
|
export const useUserLogoutHook = () => {
|
||||||
const logoutUsuario = async () => {
|
const logoutUsuario = async () => {
|
||||||
await UserLogoutService('access_token');
|
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 { 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;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
export default interface GUsuarioAuthenticatedInterface {
|
export default interface UserAuthenticatedInterface {
|
||||||
user_id?: number;
|
user_id?: number;
|
||||||
login?: string;
|
login?: string;
|
||||||
nome?: string;
|
nome?: string;
|
||||||
Loading…
Add table
Reference in a new issue