Linted and formatted

This commit is contained in:
Kevin FEDYNA
2025-01-21 16:13:50 +01:00
parent b1aa4064b1
commit 6b8966c5ca
3 changed files with 22 additions and 15 deletions
@@ -36,9 +36,7 @@ export default function ConsultStudents() {
<section> <section>
<h2>Consult Students</h2> <h2>Consult Students</h2>
{error && <p className="error">{error}</p>} {error && <p className="error">{error}</p>}
{students.length === 0 ? ( {students.length === 0 ? <p>No students found.</p> : (
<p>No students found.</p>
) : (
<table> <table>
<thead> <thead>
<tr> <tr>
@@ -18,7 +18,7 @@ export default function UploadStudents() {
} }
}; };
const confirmUpload = async () => { const confirmUpload = () => {
console.log("Confirm Upload"); console.log("Confirm Upload");
if (!fileData.value) { if (!fileData.value) {
statusMessage.value = "Please select a file before confirming upload."; statusMessage.value = "Please select a file before confirming upload.";
@@ -50,14 +50,17 @@ export default function UploadStudents() {
}); });
if (!response.ok) { if (!response.ok) {
throw new Error(`Failed to insert data for promotion ${sheetName}`); throw new Error(
`Failed to insert data for promotion ${sheetName}`,
);
} }
} }
statusMessage.value = "Data uploaded and inserted successfully!"; statusMessage.value = "Data uploaded and inserted successfully!";
} catch (error) { } catch (error) {
console.error("Error processing the file:", error); console.error("Error processing the file:", error);
statusMessage.value = "Error processing the file. Please check its format."; statusMessage.value =
"Error processing the file. Please check its format.";
} }
}; };
+12 -6
View File
@@ -2,7 +2,8 @@ import { Handlers } from "$fresh/server.ts";
import { Database } from "@db/sqlite"; import { Database } from "@db/sqlite";
export const handler: Handlers = { export const handler: Handlers = {
async GET(_request, context) { // deno-lint-ignore require-await
async GET(_request, _context) {
try { try {
const db = new Database("databases/data/mobility.db"); const db = new Database("databases/data/mobility.db");
@@ -15,11 +16,11 @@ export const handler: Handlers = {
email TEXT NOT NULL, email TEXT NOT NULL,
promotion TEXT NOT NULL promotion TEXT NOT NULL
); );
` `,
).run(); ).run();
const rows = db.prepare( const rows = db.prepare(
"SELECT id, firstName, lastName, email, promotion FROM students" "SELECT id, firstName, lastName, email, promotion FROM students",
).all(); ).all();
db.close(); db.close();
@@ -60,18 +61,23 @@ export const handler: Handlers = {
email TEXT NOT NULL, email TEXT NOT NULL,
promotion TEXT NOT NULL promotion TEXT NOT NULL
); );
` `,
).run(); ).run();
console.log("Table ensured successfully"); console.log("Table ensured successfully");
const insertQuery = db.prepare( const insertQuery = db.prepare(
"INSERT INTO students (firstName, lastName, email, promotion) VALUES (?, ?, ?, ?)" "INSERT INTO students (firstName, lastName, email, promotion) VALUES (?, ?, ?, ?)",
); );
for (const student of data) { for (const student of data) {
console.log("Inserting student:", student); console.log("Inserting student:", student);
insertQuery.run(student.Nom, student["Prénom"], student.Mail, promoName); insertQuery.run(
student.Nom,
student["Prénom"],
student.Mail,
promoName,
);
} }
console.log("All students inserted successfully"); console.log("All students inserted successfully");