Files
milsim-site-v4/ui/src/api/application.ts

66 lines
1.4 KiB
TypeScript

export type ApplicationDto = Partial<{
age: number | string
name: string
playtime: number | string
hobbies: string
military: boolean
communities: string
joinReason: string
milsimAttraction: string
referral: string
steamProfile: string
timezone: string
canAttendSaturday: boolean
interests: string
aknowledgeRules: boolean
}>
type ApplicationFull = Partial<{
app: ApplicationDto,
messages: object[]
}>
export enum Status {
Pending = "Pending",
Approved = "Approved",
Denied = "Denied",
}
const addr = "localhost:3000"
export async function loadApplication(): Promise<ApplicationFull | null> {
const res = await fetch(`http://${addr}/application/me`)
if (res.status === 204) return null
if (!res.ok) throw new Error('Failed to load application')
const json = await res.json()
// Accept either the object at root or under `application`
return json;
}
export async function postApplication(val: any) {
let out = {
"App": val,
"Status": Status.Pending
}
await fetch(`http://${addr}/application`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(out),
})
}
export async function postChatMessage(val: any) {
let output = {
message: val,
sender: 1,
timestamp: Date.now(),
}
await fetch(`http://${addr}/application/message`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(output),
})
}