Resume Logic
This commit is contained in:
+103
-2
@@ -11,6 +11,8 @@ import {
|
||||
type Application
|
||||
} from '$lib/types';
|
||||
import { sendEmployerNotificationEmail } from '$lib/emailer.server';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
export async function createUser(user: User): Promise<number> {
|
||||
const password_hash: string = await bcrypt.hash(user.password!, 12);
|
||||
@@ -340,6 +342,7 @@ export async function getCompanyFullData(
|
||||
),
|
||||
user_data AS (
|
||||
SELECT
|
||||
id,
|
||||
username,
|
||||
email,
|
||||
phone,
|
||||
@@ -491,7 +494,7 @@ export async function getCompanyEmployers(
|
||||
last_signin AT TIME ZONE 'UTC' AS "lastSignIn",
|
||||
company_id as "companyId"
|
||||
FROM users
|
||||
WHERE "company_code" = (SELECT company_code FROM companies WHERE id = ${id}))
|
||||
WHERE "company_id" = ${id})
|
||||
SELECT
|
||||
(
|
||||
SELECT row_to_json(company_data)
|
||||
@@ -530,6 +533,101 @@ export async function getCompanyEmployers(
|
||||
};
|
||||
}
|
||||
|
||||
export async function getCompanyEmployersAndRequests(
|
||||
id: number
|
||||
): Promise<{ company: Company; employers: User[]; requests: User[] }> {
|
||||
const data = await sql`
|
||||
WITH company_data AS (
|
||||
SELECT
|
||||
id,
|
||||
name,
|
||||
description,
|
||||
website,
|
||||
created_at AT TIME ZONE 'UTC' AS "createdAt",
|
||||
company_code AS "companyCode"
|
||||
FROM companies
|
||||
WHERE id = ${id}
|
||||
),
|
||||
employer_data AS (SELECT id,
|
||||
username,
|
||||
email,
|
||||
phone,
|
||||
full_name AS "fullName",
|
||||
created_at AT TIME ZONE 'UTC' AS "createdAt",
|
||||
last_signin AT TIME ZONE 'UTC' AS "lastSignIn",
|
||||
company_id as "companyId"
|
||||
FROM users
|
||||
WHERE "company_id" = ${id}),
|
||||
request_data AS (SELECT id,
|
||||
username,
|
||||
email,
|
||||
phone,
|
||||
full_name AS "fullName",
|
||||
created_at AT TIME ZONE 'UTC' AS "createdAt",
|
||||
last_signin AT TIME ZONE 'UTC' AS "lastSignIn",
|
||||
company_id as "companyId"
|
||||
FROM users
|
||||
WHERE "company_code" = (SELECT company_code FROM companies WHERE id = ${id}))
|
||||
SELECT
|
||||
(
|
||||
SELECT row_to_json(company_data)
|
||||
FROM company_data
|
||||
) AS company,
|
||||
(
|
||||
SELECT json_agg(row_to_json(employer_data))
|
||||
FROM employer_data
|
||||
) AS employers,
|
||||
(
|
||||
SELECT json_agg(row_to_json(request_data))
|
||||
FROM request_data
|
||||
) AS requests;
|
||||
`;
|
||||
|
||||
if (!data) {
|
||||
error(404, 'Company not found');
|
||||
}
|
||||
if (data[0].employers) {
|
||||
data[0].employers.forEach(
|
||||
(user: {
|
||||
company: { id: any };
|
||||
companyId: any;
|
||||
createdAt: string | number | Date;
|
||||
lastSignIn: string | number | Date;
|
||||
}) => {
|
||||
user.company = {
|
||||
id: user.companyId
|
||||
};
|
||||
user.createdAt = new Date(user.createdAt);
|
||||
user.lastSignIn = new Date(user.lastSignIn);
|
||||
delete user.companyId;
|
||||
}
|
||||
);
|
||||
}
|
||||
if (data[0].requests) {
|
||||
data[0].requests.forEach(
|
||||
(user: {
|
||||
company: { id: any };
|
||||
companyId: any;
|
||||
createdAt: string | number | Date;
|
||||
lastSignIn: string | number | Date;
|
||||
}) => {
|
||||
user.company = {
|
||||
id: user.companyId
|
||||
};
|
||||
user.createdAt = new Date(user.createdAt);
|
||||
user.lastSignIn = new Date(user.lastSignIn);
|
||||
delete user.companyId;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
company: <Company>data[0].company,
|
||||
employers: <User[]>data[0].employers,
|
||||
requests: <User[]>data[0].requests
|
||||
};
|
||||
}
|
||||
|
||||
export async function removeEmployerFromCompany(companyId: number, userId: number): Promise<void> {
|
||||
await sql`
|
||||
UPDATE users
|
||||
@@ -748,7 +846,10 @@ export async function getApplications(postingId: number): Promise<Application[]>
|
||||
username: application.username,
|
||||
email: application.email,
|
||||
phone: application.phone,
|
||||
fullName: application.fullName
|
||||
fullName: application.fullName,
|
||||
resume: fs.existsSync(
|
||||
path.join(process.cwd(), 'static', 'uploads', 'resumes', `${application.userId}.pdf`)
|
||||
)
|
||||
};
|
||||
delete application.userId;
|
||||
delete application.username;
|
||||
|
||||
Reference in New Issue
Block a user