mirror of
https://github.com/i701/sarlink-portal.git
synced 2025-07-02 03:38:22 +00:00
feat(devices): add proper filter handling and update shadcn 🔨
This commit is contained in:
@ -9,17 +9,25 @@ import { getServerSession } from "next-auth";
|
||||
import { revalidatePath } from "next/cache";
|
||||
|
||||
type GetDevicesProps = {
|
||||
query?: string;
|
||||
name?: string;
|
||||
offset?: number;
|
||||
limit?: number;
|
||||
page?: number;
|
||||
sortBy?: string;
|
||||
status?: string;
|
||||
[key: string]: string | number | undefined; // Allow additional properties for flexibility
|
||||
};
|
||||
export async function getDevices({ query, offset, limit }: GetDevicesProps) {
|
||||
export async function getDevices(params: GetDevicesProps) {
|
||||
const session = await checkSession();
|
||||
|
||||
// Build query string from all defined params
|
||||
const query = Object.entries(params)
|
||||
.filter(([_, value]) => value !== undefined && value !== "")
|
||||
.map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`)
|
||||
.join("&");
|
||||
|
||||
const response = await fetch(
|
||||
`${process.env.SARLINK_API_BASE_URL}/api/devices/?name=${query}&offset=${offset}&limit=${limit}`,
|
||||
`${process.env.SARLINK_API_BASE_URL}/api/devices/?${query}`,
|
||||
{
|
||||
method: "GET",
|
||||
headers: {
|
||||
|
Reference in New Issue
Block a user