final touches
ci / docker_image (push) Successful in 1m37s
ci / deploy (push) Successful in 16s

This commit is contained in:
2025-01-30 22:12:08 -06:00
parent fa14fe0496
commit 5eca1635f5
11 changed files with 206 additions and 26 deletions
+31 -8
View File
@@ -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);
}
+9 -1
View File
@@ -3,7 +3,7 @@ import path from 'path';
import fetch from 'node-fetch';
import { type Cookies, error } from '@sveltejs/kit';
import jwt from 'jsonwebtoken';
import type { User } from '$lib/types';
import type { Company, User } from '$lib/types';
// TODO: Handle saving custom avatar uploads
export async function saveAvatar(user: User): Promise<void> {
@@ -14,6 +14,14 @@ export async function saveAvatar(user: User): Promise<void> {
fs.writeFileSync(filePath, avatar);
}
export async function saveLogo(company: Company): Promise<void> {
const url = `https://ui-avatars.com/api/?background=random&format=svg&name=${encodeURIComponent(company.name!)}`;
const response = await fetch(url, { headers: { accept: 'image/svg+xml' } });
const avatar = await response.text();
const filePath = path.join('static', 'uploads', 'logos', `${company.id}.svg`);
fs.writeFileSync(filePath, avatar);
}
// TODO: change to return null instead of -1
export function getUserPerms(cookies: Cookies): number {
if (process.env.JWT_SECRET === undefined) {
+1
View File
@@ -65,4 +65,5 @@ export interface Application {
postingTitle: string | null;
candidateStatement: string;
createdAt: Date;
user: User | null;
}