From 2acc65823b18f8aa77fcc628d80babfaee0776b3 Mon Sep 17 00:00:00 2001 From: drake Date: Fri, 31 Jan 2025 18:51:20 -0600 Subject: [PATCH] dev --- src/lib/db/index.server.ts | 11 +- src/routes/account/+page.svelte | 4 +- src/routes/admin/users/create/+page.svelte | 2 +- src/routes/companies/+page.svelte | 14 +- .../companies/[company]/edit/+page.server.ts | 5 +- .../companies/[company]/edit/+page.svelte | 19 ++ src/routes/companies/create/+page.server.ts | 5 +- src/routes/info/+page.svelte | 8 +- src/routes/postings/+page.svelte | 193 +++++++++--------- src/routes/postings/[posting]/+page.svelte | 2 +- .../manage/applications/+page.server.ts | 2 +- .../manage/applications/+page.svelte | 2 +- .../[posting]/manage/edit/+page.server.ts | 3 +- src/routes/register/+page.server.ts | 3 +- src/routes/register/+page.svelte | 2 +- 15 files changed, 162 insertions(+), 113 deletions(-) diff --git a/src/lib/db/index.server.ts b/src/lib/db/index.server.ts index 106d65b..598a07a 100644 --- a/src/lib/db/index.server.ts +++ b/src/lib/db/index.server.ts @@ -306,7 +306,7 @@ export async function deleteCompany(id: number): Promise { export async function getCompany(id: number): Promise { const [company] = await sql` - SELECT id, name, description, website, created_at AS "createdAt" + SELECT id, name, description, website, created_at AS "createdAt", company_code AS "companyCode" FROM companies WHERE id = ${id}; `; @@ -750,3 +750,12 @@ export async function getApplications(postingId: number): Promise return (data); } + +export async function setUserCompanyId(userId: number, companyId: number): Promise { + await sql` + UPDATE users + SET company_id = ${companyId}, + company_code = (SELECT company_code FROM companies WHERE id = ${companyId}) + WHERE id = ${userId}; + `; +} diff --git a/src/routes/account/+page.svelte b/src/routes/account/+page.svelte index 8dcbba4..ad5b465 100644 --- a/src/routes/account/+page.svelte +++ b/src/routes/account/+page.svelte @@ -119,7 +119,7 @@ {#if data.user.company?.id}
Employer company: -
+
-
+
{data.user.company.name}
{data.user.company.description}
diff --git a/src/routes/admin/users/create/+page.svelte b/src/routes/admin/users/create/+page.svelte index af90e8b..929a501 100644 --- a/src/routes/admin/users/create/+page.svelte +++ b/src/routes/admin/users/create/+page.svelte @@ -147,7 +147,7 @@ id="phone" placeholder="Phone" class="w-full rounded font-normal" - pattern="[0-9]{3}-[0-9]{3}-[0-9]{4}" + pattern="([0-9]\{3}) [0-9]\{3}-[0-9]\{3}" />
diff --git a/src/routes/companies/+page.svelte b/src/routes/companies/+page.svelte index de18187..208223f 100644 --- a/src/routes/companies/+page.svelte +++ b/src/routes/companies/+page.svelte @@ -1,6 +1,8 @@
+
+ User avatar +
+

{data.company.name}

+

Company code: {data.company.companyCode}

+
+
Edit Company {data.company.name}
diff --git a/src/routes/companies/create/+page.server.ts b/src/routes/companies/create/+page.server.ts index b55ade6..4fe7a9d 100644 --- a/src/routes/companies/create/+page.server.ts +++ b/src/routes/companies/create/+page.server.ts @@ -14,9 +14,8 @@ export const actions: Actions = { const requestPerms = getUserPerms(cookies); if ( !( - requestPerms >= 0 && - ((requestPerms & PERMISSIONS.MANAGE_COMPANIES) > 0 || - ((requestPerms & PERMISSIONS.SUBMIT_POSTINGS) > 0 && getUserCompanyId(cookies))) + (requestPerms >= 0 && (requestPerms & PERMISSIONS.MANAGE_COMPANIES) > 0) || + (requestPerms & PERMISSIONS.SUBMIT_POSTINGS) > 0 ) ) { return fail(403, { errorMessage: 'You cannot preform this action!' }); diff --git a/src/routes/info/+page.svelte b/src/routes/info/+page.svelte index f7f92b3..08aed8b 100644 --- a/src/routes/info/+page.svelte +++ b/src/routes/info/+page.svelte @@ -14,10 +14,10 @@ access to create job postings.

- If you are your company admin, first create your account (without inputting a code). Then, go - to the company page, and use the button in the top right to create a new company. Once created - and approved by a CareerConnect admin, you will be able to see the company code, which you can - then give to your employees. + If you are your company admin, first create your account (without inputting a code). Reach out + to a CareerConnect admin to elevate your account privaleges. Then, go to the company page, and + use the button in the top right to create a new company. Once created, you will be able to see + the company code, which you can then give to your employees.

diff --git a/src/routes/postings/+page.svelte b/src/routes/postings/+page.svelte index ea494b8..87d5c8c 100644 --- a/src/routes/postings/+page.svelte +++ b/src/routes/postings/+page.svelte @@ -36,105 +36,116 @@
-
-
- {#each data.postings as posting} - - {/each} + {/if}
- {#if details !== undefined} -
-
-
+
+
+ {#each data.postings as posting} +
- {#if userState.perms >= 0 && ((userState.perms & PERMISSIONS.MANAGE_POSTINGS) > 0 || ((userState.perms & PERMISSIONS.SUBMIT_POSTINGS) > 0 && userState.companyId === details.company.id))} - Manage posting - {:else if (userState.perms & PERMISSIONS.APPLY_FOR_JOBS) > 0} - Apply - {/if} -
-
-

Contact

-

{details.employer?.fullName} ({details.employer?.username})

- {details.employer?.email} - {details.employer?.phone} -

Details

- {#if details.employmentType} -

{employmentTypeDisplayName(details.employmentType)}

- {/if} - {#if details.address} - Address: {details.address} - {/if} - {#if details.wage} -

Wage: {details.wage}

- {/if} - {#if details.createdAt} -

Posted: {details.createdAt.toLocaleDateString('en-US', dateFormatOptions)}

- {/if} - {#if details.link} - More information: {details.link} - {/if} - {#if details.flyerLink} - Flyer: {details.flyerLink} - {/if} -

Job Description

-

{details.description}

-
+ + {/each}
- {/if} + {#if details !== undefined} +
+
+
+ Company Logo logoFallback(e, details)} + /> +
+

{details.title}

+

Company: {details.company.name}

+
+
+ {#if userState.perms >= 0 && ((userState.perms & PERMISSIONS.MANAGE_POSTINGS) > 0 || ((userState.perms & PERMISSIONS.SUBMIT_POSTINGS) > 0 && userState.companyId === details.company.id))} + Manage posting + {:else if (userState.perms & PERMISSIONS.APPLY_FOR_JOBS) > 0} + Apply + {/if} +
+
+

Contact

+

{details.employer?.fullName} ({details.employer?.username})

+ {details.employer?.email} + {details.employer?.phone} +

Details

+ {#if details.employmentType} +

{employmentTypeDisplayName(details.employmentType)}

+ {/if} + {#if details.address} + Address: {details.address} + {/if} + {#if details.wage} +

Wage: {details.wage}

+ {/if} + {#if details.createdAt} +

Posted: {details.createdAt.toLocaleDateString('en-US', dateFormatOptions)}

+ {/if} + {#if details.link} + More information: {details.link} + {/if} + {#if details.flyerLink} + Flyer: {details.flyerLink} + {/if} +

Job Description

+

{details.description}

+
+
+ {/if} +
diff --git a/src/routes/postings/[posting]/+page.svelte b/src/routes/postings/[posting]/+page.svelte index b6c7274..da5a70d 100644 --- a/src/routes/postings/[posting]/+page.svelte +++ b/src/routes/postings/[posting]/+page.svelte @@ -36,7 +36,7 @@

Company: {data.posting.company.name}

- {#if userState.perms >= 0 && ((userState.perms & PERMISSIONS.MANAGE_POSTINGS) > 0 || ((userState.perms & PERMISSIONS.SUBMIT_POSTINGS) > 0 && userState.companyId === details.company.id))} + {#if userState.perms >= 0 && ((userState.perms & PERMISSIONS.MANAGE_POSTINGS) > 0 || ((userState.perms & PERMISSIONS.SUBMIT_POSTINGS) > 0 && userState.companyId === data.posting.company.id))} Manage posting { if ( perms >= 0 && ((perms & PERMISSIONS.MANAGE_POSTINGS) > 0 || - ((perms & PERMISSIONS.SUBMIT_POSTINGS) > 0 && getUserCompanyId(cookies) === id)) + ((perms & PERMISSIONS.SUBMIT_POSTINGS) > 0 && getUserCompanyId(cookies))) ) { return { applications: await getApplications(id) diff --git a/src/routes/postings/[posting]/manage/applications/+page.svelte b/src/routes/postings/[posting]/manage/applications/+page.svelte index b44e432..643d15f 100644 --- a/src/routes/postings/[posting]/manage/applications/+page.svelte +++ b/src/routes/postings/[posting]/manage/applications/+page.svelte @@ -78,7 +78,7 @@

Email: {application.user.email}

{/if} {#if application.user?.phone} -

Phone: {application.user.email}

+

Phone: {application.user.phone}

{/if} {#if application.createdAt}

diff --git a/src/routes/postings/[posting]/manage/edit/+page.server.ts b/src/routes/postings/[posting]/manage/edit/+page.server.ts index a6a750b..66f05be 100644 --- a/src/routes/postings/[posting]/manage/edit/+page.server.ts +++ b/src/routes/postings/[posting]/manage/edit/+page.server.ts @@ -9,10 +9,11 @@ export const load: PageServerLoad = async ({ cookies, params }) => { const id = parseInt(params.posting); const perms = getUserPerms(cookies); + // TODO check if user is allowed to edit this posting if ( perms >= 0 && ((perms & PERMISSIONS.MANAGE_POSTINGS) > 0 || - ((perms & PERMISSIONS.SUBMIT_POSTINGS) > 0 && getUserCompanyId(cookies) === id)) + ((perms & PERMISSIONS.SUBMIT_POSTINGS) > 0 && getUserCompanyId(cookies))) ) { return { posting: await getPosting(id) diff --git a/src/routes/register/+page.server.ts b/src/routes/register/+page.server.ts index 7b51068..89d2655 100644 --- a/src/routes/register/+page.server.ts +++ b/src/routes/register/+page.server.ts @@ -47,7 +47,8 @@ export const actions: Actions = { active: true, email: email, phone: phone, - fullName: fullName + fullName: fullName, + companyCode: companyCode }; if (password === confirmPassword) { try { diff --git a/src/routes/register/+page.svelte b/src/routes/register/+page.svelte index 2658d8f..006301a 100644 --- a/src/routes/register/+page.svelte +++ b/src/routes/register/+page.svelte @@ -83,7 +83,7 @@ id="phone" placeholder="Phone" class="w-full rounded font-normal" - pattern="[0-9]{3}-[0-9]{3}-[0-9]{4}" + pattern="([0-9]\{3}) [0-9]\{3}-[0-9]\{3}" />