136 lines
3.2 KiB
TypeScript
136 lines
3.2 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
|
|
}>
|
|
|
|
export interface ApplicationData {
|
|
dob: string;
|
|
name: string;
|
|
playtime: number;
|
|
hobbies: string;
|
|
military: boolean;
|
|
communities: string;
|
|
joinReason: string;
|
|
milsimAttraction: string;
|
|
referral: string;
|
|
steamProfile: string;
|
|
timezone: string;
|
|
canAttendSaturday: boolean;
|
|
interests: string;
|
|
aknowledgeRules: boolean;
|
|
}
|
|
|
|
export interface ApplicationRow {
|
|
id: number;
|
|
member_id: number;
|
|
app_version: number;
|
|
app_data: ApplicationData;
|
|
|
|
submitted_at: string; // ISO datetime from DB (e.g., "2025-08-25T18:04:29.000Z")
|
|
updated_at: string | null;
|
|
approved_at: string | null;
|
|
denied_at: string | null;
|
|
|
|
app_status: Status; // generated column
|
|
decision_at: string | null; // generated column
|
|
|
|
// present when you join members (e.g., SELECT a.*, m.name AS member_name)
|
|
member_name: string;
|
|
}
|
|
export interface CommentRow {
|
|
comment_id: number;
|
|
post_content: string;
|
|
poster_id: number;
|
|
post_time: string;
|
|
last_modified: string | null;
|
|
poster_name: string;
|
|
}
|
|
|
|
export interface ApplicationFull {
|
|
application: ApplicationRow;
|
|
comments: CommentRow[];
|
|
}
|
|
|
|
|
|
export enum Status {
|
|
Pending = "Pending",
|
|
Accepted = "Accepted",
|
|
Denied = "Denied",
|
|
}
|
|
// @ts-ignore
|
|
const addr = import.meta.env.VITE_APIHOST;
|
|
|
|
export async function loadApplication(id: number | string): Promise<ApplicationFull | null> {
|
|
const res = await fetch(`${addr}/application/${id}`)
|
|
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,
|
|
}
|
|
const res = await fetch(`${addr}/application`, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify(out),
|
|
})
|
|
return res;
|
|
}
|
|
|
|
export async function postChatMessage(message: any, post_id: number) {
|
|
|
|
const out = {
|
|
message: message
|
|
}
|
|
|
|
const response = await fetch(`${addr}/application/${post_id}/comment`, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify(out),
|
|
})
|
|
|
|
return await response.json();
|
|
}
|
|
|
|
export async function getAllApplications() {
|
|
const res = await fetch(`${addr}/application/all`)
|
|
|
|
if (res.ok) {
|
|
return res.json()
|
|
} else {
|
|
console.error("Something went wrong approving the application")
|
|
}
|
|
}
|
|
|
|
export async function approveApplication(id: Number) {
|
|
const res = await fetch(`${addr}/application/approve/${id}`, { method: 'POST' })
|
|
|
|
if (!res.ok) {
|
|
console.error("Something went wrong approving the application")
|
|
}
|
|
}
|
|
|
|
export async function denyApplication(id: Number) {
|
|
const res = await fetch(`${addr}/application/deny/${id}`, { method: 'POST' })
|
|
|
|
if (!res.ok) {
|
|
console.error("Something went wrong denying the application")
|
|
}
|
|
} |