formatting
Some checks failed
ci / deploy (push) Has been cancelled
ci / docker_image (push) Has been cancelled

This commit is contained in:
Drake Marino 2025-03-30 22:57:05 +00:00
parent 77655c779d
commit 368cb53528

View File

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