Fixed linting and formatting errors
This commit is contained in:
@@ -2,11 +2,16 @@ import { Handlers } from "$fresh/server.ts";
|
||||
import { Database } from "@db/sqlite";
|
||||
|
||||
export const handler: Handlers = {
|
||||
// deno-lint-ignore require-await
|
||||
async GET() {
|
||||
try {
|
||||
console.log("Connecting to mobility database...");
|
||||
const connection = new Database("databases/data/mobility.db", { create: false });
|
||||
connection.run("ATTACH DATABASE 'databases/data/students.db' AS students");
|
||||
const connection = new Database("databases/data/mobility.db", {
|
||||
create: false,
|
||||
});
|
||||
connection.run(
|
||||
"ATTACH DATABASE 'databases/data/students.db' AS students",
|
||||
);
|
||||
console.log("Connected to databases.");
|
||||
|
||||
const students = connection.prepare(
|
||||
@@ -17,7 +22,7 @@ export const handler: Handlers = {
|
||||
students.promotionId AS promotionId,
|
||||
promotions.name AS promotionName
|
||||
FROM students.students
|
||||
LEFT JOIN students.promotions ON students.promotionId = promotions.id`
|
||||
LEFT JOIN students.promotions ON students.promotionId = promotions.id`,
|
||||
).all();
|
||||
|
||||
const mobilities = connection.prepare(
|
||||
@@ -30,11 +35,11 @@ export const handler: Handlers = {
|
||||
mobility.destinationCountry,
|
||||
mobility.destinationName,
|
||||
mobility.mobilityStatus
|
||||
FROM mobility`
|
||||
FROM mobility`,
|
||||
).all();
|
||||
|
||||
const promotions = connection.prepare(
|
||||
`SELECT id, name FROM students.promotions`
|
||||
`SELECT id, name FROM students.promotions`,
|
||||
).all();
|
||||
|
||||
connection.close();
|
||||
@@ -63,10 +68,14 @@ export const handler: Handlers = {
|
||||
throw new Error("Invalid request body");
|
||||
}
|
||||
console.log("Connecting to mobility database...");
|
||||
const connection = new Database("databases/data/mobility.db", { create: false });
|
||||
const connection = new Database("databases/data/mobility.db", {
|
||||
create: false,
|
||||
});
|
||||
|
||||
console.log("Attaching students database...");
|
||||
connection.run("ATTACH DATABASE 'databases/data/students.db' AS students");
|
||||
connection.run(
|
||||
"ATTACH DATABASE 'databases/data/students.db' AS students",
|
||||
);
|
||||
console.log("Students database attached successfully.");
|
||||
|
||||
const insertQuery = connection.prepare(
|
||||
@@ -80,7 +89,7 @@ export const handler: Handlers = {
|
||||
weeksCount = excluded.weeksCount,
|
||||
destinationCountry = excluded.destinationCountry,
|
||||
destinationName = excluded.destinationName,
|
||||
mobilityStatus = excluded.mobilityStatus`
|
||||
mobilityStatus = excluded.mobilityStatus`,
|
||||
);
|
||||
|
||||
for (const mobility of data) {
|
||||
@@ -98,7 +107,9 @@ export const handler: Handlers = {
|
||||
console.log("Processing mobility data:", mobility);
|
||||
|
||||
const studentExists = connection
|
||||
.prepare(`SELECT COUNT(*) AS count FROM students.students WHERE userId = ?`)
|
||||
.prepare(
|
||||
`SELECT COUNT(*) AS count FROM students.students WHERE userId = ?`,
|
||||
)
|
||||
.get(studentId);
|
||||
|
||||
console.log(`Student ${studentId} exists:`, studentExists.count > 0);
|
||||
@@ -113,7 +124,9 @@ export const handler: Handlers = {
|
||||
const start = new Date(startDate);
|
||||
const end = new Date(endDate);
|
||||
if (start <= end) {
|
||||
calculatedWeeksCount = Math.ceil((end.getTime() - start.getTime()) / (7 * 24 * 60 * 60 * 1000));
|
||||
calculatedWeeksCount = Math.ceil(
|
||||
(end.getTime() - start.getTime()) / (7 * 24 * 60 * 60 * 1000),
|
||||
);
|
||||
} else {
|
||||
calculatedWeeksCount = null;
|
||||
}
|
||||
@@ -138,16 +151,18 @@ export const handler: Handlers = {
|
||||
calculatedWeeksCount,
|
||||
destinationCountry,
|
||||
destinationName,
|
||||
mobilityStatus
|
||||
mobilityStatus,
|
||||
);
|
||||
}
|
||||
|
||||
connection.close();
|
||||
console.log("Mobility data inserted/updated successfully.");
|
||||
return new Response("Data inserted/updated successfully", { status: 200 });
|
||||
return new Response("Data inserted/updated successfully", {
|
||||
status: 200,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Error inserting mobility data:", error);
|
||||
return new Response("Failed to insert/update data", { status: 500 });
|
||||
}
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user