final touches
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import bcrypt from 'bcrypt';
|
||||
import sql from '$lib/db/db.server';
|
||||
import { error } from '@sveltejs/kit';
|
||||
import { saveAvatar } from '$lib/index.server';
|
||||
import { saveAvatar, saveLogo } from '$lib/index.server';
|
||||
import {
|
||||
EmploymentType,
|
||||
type User,
|
||||
@@ -281,6 +281,8 @@ export async function createCompany(company: Company): Promise<number> {
|
||||
RETURNING id;
|
||||
`;
|
||||
|
||||
await saveLogo(company);
|
||||
|
||||
return response[0].id;
|
||||
}
|
||||
|
||||
@@ -616,7 +618,7 @@ export async function getPosting(id: number): Promise<Posting> {
|
||||
return posting;
|
||||
}
|
||||
|
||||
export async function getPostingFullData(id: number): Promise<Posting> {
|
||||
export async function getPostingWithCompanyUser(id: number): Promise<Posting> {
|
||||
const data = await sql`
|
||||
WITH company_data AS (
|
||||
SELECT
|
||||
@@ -715,15 +717,36 @@ export async function deleteApplicationWithUser(
|
||||
}
|
||||
|
||||
export async function getApplications(postingId: number): Promise<Application[]> {
|
||||
const applications = await sql<Application[]>`
|
||||
SELECT id, posting_id AS "postingId", user_id AS "userId", candidate_statement AS "candidateStatement", created_at AS "createdAt"
|
||||
FROM applications
|
||||
WHERE posting_id = ${postingId};
|
||||
const data = await sql`
|
||||
SELECT
|
||||
a.id,
|
||||
a.candidate_statement AS "candidateStatement",
|
||||
a.created_at AS "createdAt",
|
||||
u.id AS "userId",
|
||||
u.username,
|
||||
u.email,
|
||||
u.phone,
|
||||
u.full_name AS "fullName"
|
||||
FROM applications a
|
||||
JOIN users u ON a.user_id = u.id
|
||||
WHERE a.posting_id = ${postingId};
|
||||
`;
|
||||
|
||||
applications.forEach((application) => {
|
||||
data.forEach((application) => {
|
||||
application.createdAt = new Date(application.createdAt);
|
||||
application.user = {
|
||||
id: application.userId,
|
||||
username: application.username,
|
||||
email: application.email,
|
||||
phone: application.phone,
|
||||
fullName: application.fullName
|
||||
};
|
||||
delete application.userId;
|
||||
delete application.username;
|
||||
delete application.email;
|
||||
delete application.phone;
|
||||
delete application.fullName;
|
||||
});
|
||||
|
||||
return applications;
|
||||
return <Application[]>(<unknown>data);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user