FBLA25/src/routes/postings/[posting]/manage/applications/+page.server.ts
drake 77655c779d
All checks were successful
ci / docker_image (push) Successful in 1m37s
ci / deploy (push) Successful in 16s
import cleanup
2025-03-29 18:13:02 -05:00

36 lines
1.1 KiB
TypeScript

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');
}
};