diff --git a/src/routes/postings/[posting]/apply/+page.server.ts b/src/routes/postings/[posting]/apply/+page.server.ts index de07aed..7d9fe92 100644 --- a/src/routes/postings/[posting]/apply/+page.server.ts +++ b/src/routes/postings/[posting]/apply/+page.server.ts @@ -6,6 +6,8 @@ import { PERMISSIONS } from '$lib/consts'; import type { Application } from '$lib/types'; export const load: PageServerLoad = async ({ params, cookies }) => { + + // Permission check (apply perm) const id = parseInt(params.posting); const perms = getUserPerms(cookies); if (perms >= 0 && (perms & PERMISSIONS.APPLY_FOR_JOBS) > 0) { @@ -17,7 +19,9 @@ export const load: PageServerLoad = async ({ params, cookies }) => { }; export const actions: Actions = { + // Application submission submit: async ({ request, cookies, params }) => { + // Permission check (apply perm) if (!((getUserPerms(cookies) & PERMISSIONS.APPLY_FOR_JOBS) > 0)) { return fail(403, { errorMessage: 'Unauthorized' }); } @@ -28,9 +32,12 @@ export const actions: Actions = { const postingId = parseInt(params.posting!); const userId = getUserId(cookies); + // Statement data validation if (!candidateStatement || candidateStatement === '') { return fail(400, { errorMessage: 'Candidate statement is required' }); } + + // Push to DB and redirect await createApplication({ userId, postingId, candidateStatement }); redirect(301, `/postings`); }