Files
milsim-site-v4/ui/src/api/rank.ts
2025-11-19 21:32:12 -05:00

38 lines
867 B
TypeScript

export type Rank = {
id: number
name: string
short_name: string
sortOrder: number
}
// @ts-ignore
const addr = import.meta.env.VITE_APIHOST;
export async function getRanks(): Promise<Rank[]> {
const res = await fetch(`${addr}/ranks`)
if (res.ok) {
return res.json()
} else {
console.error("Something went wrong approving the application")
}
}
// Placeholder: submit a rank change
export async function submitRankChange(member_id: number, rank_id: number, date: string): Promise<{ ok: boolean }> {
const res = await fetch(`${addr}/memberRanks`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ change: { member_id, rank_id, date } }),
})
if (res.ok) {
return { ok: true }
} else {
console.error("Failed to submit rank change")
return { ok: false }
}
}