import { SessionWithTokens, authOptions } from "@/config/authConfig" import { getServerSession } from "next-auth" export interface WildCard { [key: string]: any; } export const dateInRange = (currentDate: string, startDate: string, endDate: string) => { if (currentDate === undefined) { return false // can be changed to true if necessary } const currentDateTime = new Date(currentDate).getTime() const startDateTime = startDate === undefined || startDate.length === 0 ? undefined : new Date(startDate).getTime() const endDateTime = endDate === undefined || startDate.length === 0 ? undefined : new Date(endDate).getTime() // console.log(currentDateTime, startDateTime, endDateTime) if (startDateTime === undefined && endDateTime !== undefined) { return currentDateTime <= endDateTime } else if (startDateTime !== undefined && endDateTime === undefined) { return currentDateTime >= startDateTime } else { if (startDateTime !== undefined && endDateTime !== undefined) { return currentDateTime >= startDateTime && currentDateTime <= endDateTime } else { return true } } } export const downloadFile = (blobData: Uint8Array, filename: string) => { const url = URL.createObjectURL(new Blob([blobData])); const link = document.createElement("a"); link.href = url; link.setAttribute("download", filename); link.click(); } export function readIntFromString(input: string): [string, number | null] | string { // Split the input string by the "-" character if (!input.includes("-")) { return [input, null] } const parts = input.split("-"); // Extract the string part and the integer part (if available) const stringPart = parts.slice(0, parts.length - 1).join("-"); const intPartStr = parts[parts.length - 1]; const intPart = intPartStr ? parseInt(intPartStr, 10) : null; return [stringPart, intPart]; } export const getUserAbilities = async () => { const session = await getServerSession(authOptions) as SessionWithTokens; return session?.abilities ?? [] }