API integration stuff
This commit is contained in:
29
api/index.js
29
api/index.js
@@ -50,7 +50,11 @@ app.get('/application/me', async (req, res) => {
|
|||||||
const applicationId = 1;
|
const applicationId = 1;
|
||||||
|
|
||||||
const rows = await pool.query(
|
const rows = await pool.query(
|
||||||
'SELECT * FROM applications WHERE id = ?',
|
`SELECT app.*,
|
||||||
|
member.name AS member_name
|
||||||
|
FROM applications AS app
|
||||||
|
INNER JOIN members AS member ON member.id = app.member_id
|
||||||
|
WHERE app.member_id = ?;`,
|
||||||
[applicationId]
|
[applicationId]
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -65,6 +69,29 @@ app.get('/application/me', async (req, res) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.get('/application/:id', async (req, res) => {
|
||||||
|
const appID = req.params.id;
|
||||||
|
try {
|
||||||
|
const rows = await pool.query(
|
||||||
|
`SELECT app.*,
|
||||||
|
member.name AS member_name
|
||||||
|
FROM applications AS app
|
||||||
|
INNER JOIN members AS member ON member.id = app.member_id
|
||||||
|
WHERE app.id = 1;`,
|
||||||
|
[appID]
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!Array.isArray(rows) || rows.length === 0) {
|
||||||
|
return res.send(404).json("Application Not Found");
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.status(200).json(rows[0]);
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
console.error('Query failed:', err);
|
||||||
|
return res.status(500).json({ error: 'Failed to load application' });
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
app.get('/application/all', async (req, res) => {
|
app.get('/application/all', async (req, res) => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -15,10 +15,44 @@ export type ApplicationDto = Partial<{
|
|||||||
aknowledgeRules: boolean
|
aknowledgeRules: boolean
|
||||||
}>
|
}>
|
||||||
|
|
||||||
type ApplicationFull = Partial<{
|
export interface ApplicationData {
|
||||||
app: ApplicationDto,
|
dob: string;
|
||||||
messages: object[]
|
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 type ApplicationFull = ApplicationRow & {
|
||||||
|
messages?: object[];
|
||||||
|
};
|
||||||
|
|
||||||
export enum Status {
|
export enum Status {
|
||||||
Pending = "Pending",
|
Pending = "Pending",
|
||||||
@@ -68,7 +102,7 @@ export async function getAllApplications() {
|
|||||||
const res = await fetch(`http://${addr}/application/all`)
|
const res = await fetch(`http://${addr}/application/all`)
|
||||||
|
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
return await res.json();
|
return res.json()
|
||||||
} else {
|
} else {
|
||||||
console.error("Something went wrong approving the application")
|
console.error("Something went wrong approving the application")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import { Form } from 'vee-validate';
|
|||||||
import { onMounted, ref } from 'vue';
|
import { onMounted, ref } from 'vue';
|
||||||
import * as z from 'zod';
|
import * as z from 'zod';
|
||||||
import DateInput from '../form/DateInput.vue';
|
import DateInput from '../form/DateInput.vue';
|
||||||
|
import { ApplicationData } from '@/api/application';
|
||||||
|
|
||||||
const formSchema = toTypedSchema(z.object({
|
const formSchema = toTypedSchema(z.object({
|
||||||
dob: z.string().refine(v => v, { message: "A date of birth is required." }),
|
dob: z.string().refine(v => v, { message: "A date of birth is required." }),
|
||||||
@@ -45,7 +46,7 @@ const fallbackInitials = {
|
|||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
readOnly: boolean,
|
readOnly: boolean,
|
||||||
data: object,
|
data: ApplicationData,
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const emit = defineEmits(['submit']);
|
const emit = defineEmits(['submit']);
|
||||||
@@ -57,8 +58,8 @@ async function onSubmit(val: any) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
if (props.data) {
|
if (props.data !== null) {
|
||||||
initialValues.value = { ...props.data, ...fallbackInitials }
|
initialValues.value = { ...props.data }
|
||||||
} else {
|
} else {
|
||||||
initialValues.value = { ...fallbackInitials }
|
initialValues.value = { ...fallbackInitials }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,43 +2,58 @@
|
|||||||
import ApplicationChat from '@/components/application/ApplicationChat.vue';
|
import ApplicationChat from '@/components/application/ApplicationChat.vue';
|
||||||
import ApplicationForm from '@/components/application/ApplicationForm.vue';
|
import ApplicationForm from '@/components/application/ApplicationForm.vue';
|
||||||
import { onMounted, ref } from 'vue';
|
import { onMounted, ref } from 'vue';
|
||||||
import { loadApplication, postApplication, postChatMessage, Status } from '@/api/application';
|
import { ApplicationData, loadApplication, postApplication, postChatMessage, Status } from '@/api/application';
|
||||||
|
|
||||||
const appData = ref<Record<string, unknown> | null>(null);
|
const appData = ref<ApplicationData>(null);
|
||||||
const chatData = ref<object[]>([])
|
const chatData = ref<object[]>([])
|
||||||
const readOnly = ref<boolean>(false);
|
const readOnly = ref<boolean>(false);
|
||||||
const newApp = ref<boolean>(true);
|
const newApp = ref<boolean>(true);
|
||||||
const status = ref<Status>(Status.Pending);
|
const status = ref<Status>(null);
|
||||||
|
const decisionDate = ref<Date | null>(null);
|
||||||
|
const submitDate = ref<Date | null>(null);
|
||||||
|
const loading = ref<boolean>(true);
|
||||||
|
const member_name = ref<string>();
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
try {
|
try {
|
||||||
const data = await loadApplication()
|
const data = await loadApplication()
|
||||||
|
console.log(data);
|
||||||
if (data) {
|
if (data) {
|
||||||
appData.value = data.app;
|
appData.value = data.app_data;
|
||||||
chatData.value = data.messages;
|
chatData.value = data.messages;
|
||||||
|
status.value = data.app_status;
|
||||||
|
decisionDate.value = new Date(data.decision_at);
|
||||||
|
submitDate.value = data.decision_at ? new Date(data.submitted_at) : null;
|
||||||
|
member_name.value = data.member_name;
|
||||||
readOnly.value = true;
|
readOnly.value = true;
|
||||||
} else {
|
} else {
|
||||||
appData.value = {}
|
appData.value = null
|
||||||
newApp.value = false;
|
newApp.value = false;
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
}
|
}
|
||||||
|
loading.value = false;
|
||||||
})
|
})
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="max-w-3xl mx-auto my-20">
|
<div v-if="!loading" class="max-w-3xl mx-auto my-20">
|
||||||
<div v-if="newApp" class="flex flex-row justify-between items-center py-2 mb-8">
|
<div v-if="newApp" class="flex flex-row justify-between items-center py-2 mb-8">
|
||||||
<!-- Application header -->
|
<!-- Application header -->
|
||||||
<h3 class="scroll-m-20 text-2xl font-semibold tracking-tight">Application Name</h3>
|
<div>
|
||||||
<h3 :class="[
|
<h3 class="scroll-m-20 text-2xl font-semibold tracking-tight">{{ member_name }}</h3>
|
||||||
|
<p class="text-muted-foreground">Submitted: {{ submitDate.toLocaleString("en-US") }}</p>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<h3 class="text-right" :class="[
|
||||||
'font-semibold',
|
'font-semibold',
|
||||||
status === Status.Pending && 'text-yellow-500',
|
status === Status.Pending && 'text-yellow-500',
|
||||||
status === Status.Approved && 'text-green-500',
|
status === Status.Approved && 'text-green-500',
|
||||||
status === Status.Denied && 'text-red-500'
|
status === Status.Denied && 'text-red-500'
|
||||||
]">{{ status }}</h3>
|
]">{{ status }}</h3>
|
||||||
|
<p class="text-muted-foreground">{{ status }}: {{ decisionDate.toLocaleString("en-US") }}</p>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-else class="flex flex-row justify-between items-center py-2 mb-8">
|
<div v-else class="flex flex-row justify-between items-center py-2 mb-8">
|
||||||
<h3 class="scroll-m-20 text-2xl font-semibold tracking-tight">Apply to join the 17th Rangers</h3>
|
<h3 class="scroll-m-20 text-2xl font-semibold tracking-tight">Apply to join the 17th Rangers</h3>
|
||||||
|
|||||||
Reference in New Issue
Block a user