mirror of
https://github.com/i701/sarlink-portal.git
synced 2025-07-15 11:05:50 +00:00
32 lines
999 B
TypeScript
32 lines
999 B
TypeScript
'use server'
|
|
import { getServerSession } from "next-auth";
|
|
import { authOptions } from "@/app/auth";
|
|
import type { ApiResponse } from "@/lib/backend-types";
|
|
import type { UserProfile } from "@/lib/types/user";
|
|
import { handleApiResponse } from "@/utils/tryCatch";
|
|
|
|
|
|
type ParamProps = {
|
|
[key: string]: string | number | undefined;
|
|
};
|
|
export async function getUsers(params: ParamProps) {
|
|
const session = await getServerSession(authOptions);
|
|
|
|
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/auth/users/?${query}`,
|
|
{
|
|
method: "GET",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
Authorization: `Token ${session?.apiToken}`,
|
|
},
|
|
},
|
|
);
|
|
|
|
return handleApiResponse<ApiResponse<UserProfile>>(response, "getUsers");
|
|
}
|