import type { PageServerLoad } from './$types'; import { getUserCompanyId, getUserPerms } from '$lib/index.server'; import { PERMISSIONS } from '$lib/consts'; import { deleteApplication, getApplications } from '$lib/db/index.server'; import { type Actions, error } from '@sveltejs/kit'; export const load: PageServerLoad = async ({ params, cookies }) => { const id = parseInt(params.posting); const perms = getUserPerms(cookies); if ( perms >= 0 && ((perms & PERMISSIONS.MANAGE_POSTINGS) > 0 || ((perms & PERMISSIONS.SUBMIT_POSTINGS) > 0 && getUserCompanyId(cookies))) ) { return { applications: await getApplications(id) }; } error(403, 'Unauthorized'); }; export const actions: Actions = { delete: async ({ url, cookies }) => { const id = parseInt(url.searchParams.get('id')!); const perms = getUserPerms(cookies); if ( perms >= 0 && ((perms & PERMISSIONS.MANAGE_POSTINGS) > 0 || ((perms & PERMISSIONS.SUBMIT_POSTINGS) > 0 && getUserCompanyId(cookies) === id)) ) { return await deleteApplication(id); } error(403, 'Unauthorized'); } };