add UsersAdmin

This commit is contained in:
Fran
2026-02-12 17:25:53 -03:00
parent 1c4140e0a1
commit 4ca434da9e
3 changed files with 35 additions and 20 deletions

BIN
bun.lockb Normal file

Binary file not shown.

View File

@@ -0,0 +1,25 @@
import { apiBase } from "@/stores/url";
import { sesionStore } from "@/stores/usuario";
import { redirect } from "@sveltejs/kit";
import { get } from "svelte/store";
import type { UserResponseDto } from "../../types";
export async function fetchUsuariosAdmin(page: number, limit: number) {
let response = await fetch(get(apiBase) + `/api/admin/users?page=${page}&pageSize=${limit}`,{
method: 'GET',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${get(sesionStore)?.accessToken}`
}
});
if (response.status === 401) {
throw redirect(302, '/');
}
if (!response.ok) {
return { error: true };
}
const usuarios: UserResponseDto[] = await response.json();
return { usuarios, error: false };
}

View File

@@ -1,28 +1,18 @@
import { apiBase } from '@/stores/url.js';
import { sesionStore } from '@/stores/usuario';
import { redirect } from '@sveltejs/kit';
import { get } from 'svelte/store';
import type { UserResponseDto } from '../../../types.js';
import type { PageLoad } from './$types.js';
import { fetchUsuariosAdmin } from '@/hooks/UsuariosAdmin.js';
export const ssr = false;
export async function load({ depends, fetch }) {
export const load: PageLoad = async ({ depends}) => {
depends('admin:load');
const response = await fetch(get(apiBase) + '/api/admin/users', {
method: 'GET',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${get(sesionStore)?.accessToken}`
}
});
if (response.status === 401) {
throw redirect(302, '/');
}
if (!response.ok) {
const result = await fetchUsuariosAdmin(1, 10);
if (result.error) {
return { error: true };
}
const usuarios: UserResponseDto[] = await response.json();
return { usuarios, error: false };
return {
usuarios: result.usuarios,
error: false
};
}