This commit is contained in:
Giovanni Rezcjikov
2026-03-09 18:09:02 +03:00
parent be36c6f0c4
commit f188150c9f
25 changed files with 694 additions and 53 deletions
+1 -1
View File
@@ -92,7 +92,7 @@ export async function SessionLogin(
if (data.redirect_url) return { success: true, redirectURL: data.redirect_url };
return { success: true };
} catch {
} catch (error) {
return { success: false, message: t("serverError") };
}
}
+1 -1
View File
@@ -19,7 +19,7 @@ export async function getConsents() {
if (!response.ok) return []
const consents = await response.json() as Consent[]
consents.forEach((consent: Consent) => {
consents?.forEach((consent: Consent) => {
consent.isRevokable = consent.client_id !== process.env.CLIENT_ID
})
+68
View File
@@ -0,0 +1,68 @@
"use server"
import type { Position } from "@/types"
import { cookies } from "next/headers"
export async function getMyPositions(): Promise<Position[]> {
const store = await cookies()
const accessToken = store.get("access_token")?.value
if (!accessToken) return []
const response = await fetch(
`${process.env.KOTOSOFT_ID_API_URL}/api/v1/me/positions`,
{
headers: {
Authorization: `Bearer ${accessToken}`,
},
cache: "no-store",
}
)
if (!response.ok) return []
return (await response.json()) as Position[]
}
export async function listAllPositions(): Promise<Position[] | null> {
const store = await cookies()
const accessToken = store.get("access_token")?.value
if (!accessToken) return null
const response = await fetch(
`${process.env.KOTOSOFT_ID_API_URL}/api/v1/admin/positions`,
{
headers: {
Authorization: `Bearer ${accessToken}`,
},
cache: "no-store",
}
)
if (response.status === 403) return null
if (!response.ok) return null
return (await response.json()) as Position[]
}
export async function upsertPosition(code: string, name: string, description?: string | null): Promise<{ success: boolean }> {
const store = await cookies()
const accessToken = store.get("access_token")?.value
if (!accessToken) return { success: false }
const response = await fetch(
`${process.env.KOTOSOFT_ID_API_URL}/api/v1/admin/positions`,
{
method: "POST",
headers: {
Authorization: `Bearer ${accessToken}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ code, name, ...(description ? { description } : {}) }),
}
)
if (!response.ok) {
return { success: false }
}
return { success: true }
}