Fixed linting and formatting errors
This commit is contained in:
@@ -24,7 +24,14 @@ interface Mobility {
|
||||
}
|
||||
|
||||
export default function ConsultMobility() {
|
||||
const [data, setData] = useState<{ promotions?: Promotion[]; students?: Student[]; mobilities?: Mobility[] } | null>(null);
|
||||
const [data, setData] = useState<
|
||||
| {
|
||||
promotions?: Promotion[];
|
||||
students?: Student[];
|
||||
mobilities?: Mobility[];
|
||||
}
|
||||
| null
|
||||
>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -82,7 +89,9 @@ export default function ConsultMobility() {
|
||||
{data.students
|
||||
?.filter((student) => student.promotionId === promo.id)
|
||||
.map((student) => {
|
||||
const mobility = data.mobilities?.find((mob) => mob.studentId === student.id);
|
||||
const mobility = data.mobilities?.find((mob) =>
|
||||
mob.studentId === student.id
|
||||
);
|
||||
return (
|
||||
<tr key={student.id}>
|
||||
<td>{student.id}</td>
|
||||
|
||||
@@ -15,7 +15,9 @@ interface Student {
|
||||
}
|
||||
|
||||
export default function ConsultStudents_test() {
|
||||
const [data, setData] = useState<{ promotions: Promotion[]; students: Student[] } | null>(null);
|
||||
const [data, setData] = useState<
|
||||
{ promotions: Promotion[]; students: Student[] } | null
|
||||
>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -43,7 +45,7 @@ export default function ConsultStudents_test() {
|
||||
{error && <p className="error">{error}</p>}
|
||||
{data?.promotions.map((promo) => (
|
||||
<div key={promo.id}>
|
||||
<h3>Promotion: {promo.id}</h3>
|
||||
<h3>Promotion: {promo.id}</h3>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
|
||||
@@ -24,7 +24,14 @@ interface Mobility {
|
||||
}
|
||||
|
||||
export default function EditMobility() {
|
||||
const [data, setData] = useState<{ promotions?: Promotion[]; students?: Student[]; mobilities?: Mobility[] } | null>(null);
|
||||
const [data, setData] = useState<
|
||||
| {
|
||||
promotions?: Promotion[];
|
||||
students?: Student[];
|
||||
mobilities?: Mobility[];
|
||||
}
|
||||
| null
|
||||
>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [isSaving, setIsSaving] = useState(false);
|
||||
|
||||
@@ -69,7 +76,10 @@ export default function EditMobility() {
|
||||
const startDate = new Date(updatedMobility.startDate || "");
|
||||
const endDate = new Date(updatedMobility.endDate || "");
|
||||
if (startDate && endDate && startDate <= endDate) {
|
||||
const weeks = Math.ceil((endDate.getTime() - startDate.getTime()) / (7 * 24 * 60 * 60 * 1000));
|
||||
const weeks = Math.ceil(
|
||||
(endDate.getTime() - startDate.getTime()) /
|
||||
(7 * 24 * 60 * 60 * 1000),
|
||||
);
|
||||
updatedMobility.weeksCount = weeks;
|
||||
} else {
|
||||
updatedMobility.weeksCount = null;
|
||||
@@ -99,7 +109,7 @@ export default function EditMobility() {
|
||||
|
||||
if (response.ok) {
|
||||
alert("Data saved successfully!");
|
||||
window.location.reload();
|
||||
globalThis.location.reload();
|
||||
} else {
|
||||
throw new Error(`Failed to save data: ${response.statusText}`);
|
||||
}
|
||||
@@ -143,7 +153,9 @@ export default function EditMobility() {
|
||||
{data.students
|
||||
?.filter((student) => student.promotionId === promo.id)
|
||||
.map((student) => {
|
||||
const mobility = data.mobilities?.find((mob) => mob.studentId === student.id) || {
|
||||
const mobility = data.mobilities?.find((mob) =>
|
||||
mob.studentId === student.id
|
||||
) || {
|
||||
id: null,
|
||||
studentId: student.id,
|
||||
startDate: null,
|
||||
@@ -163,14 +175,20 @@ export default function EditMobility() {
|
||||
<input
|
||||
type="date"
|
||||
value={mobility.startDate || ""}
|
||||
onChange={(e) => handleChange(student.id, "startDate", e.target.value)}
|
||||
onChange={(e) =>
|
||||
handleChange(
|
||||
student.id,
|
||||
"startDate",
|
||||
e.target.value,
|
||||
)}
|
||||
/>
|
||||
</td>
|
||||
<td>
|
||||
<input
|
||||
type="date"
|
||||
value={mobility.endDate || ""}
|
||||
onChange={(e) => handleChange(student.id, "endDate", e.target.value)}
|
||||
onChange={(e) =>
|
||||
handleChange(student.id, "endDate", e.target.value)}
|
||||
/>
|
||||
</td>
|
||||
<td>{mobility.weeksCount ?? "N/A"}</td>
|
||||
@@ -178,20 +196,35 @@ export default function EditMobility() {
|
||||
<input
|
||||
type="text"
|
||||
value={mobility.destinationCountry || ""}
|
||||
onChange={(e) => handleChange(student.id, "destinationCountry", e.target.value)}
|
||||
onChange={(e) =>
|
||||
handleChange(
|
||||
student.id,
|
||||
"destinationCountry",
|
||||
e.target.value,
|
||||
)}
|
||||
/>
|
||||
</td>
|
||||
<td>
|
||||
<input
|
||||
type="text"
|
||||
value={mobility.destinationName || ""}
|
||||
onChange={(e) => handleChange(student.id, "destinationName", e.target.value)}
|
||||
onChange={(e) =>
|
||||
handleChange(
|
||||
student.id,
|
||||
"destinationName",
|
||||
e.target.value,
|
||||
)}
|
||||
/>
|
||||
</td>
|
||||
<td>
|
||||
<select
|
||||
value={mobility.mobilityStatus}
|
||||
onChange={(e) => handleChange(student.id, "mobilityStatus", e.target.value)}
|
||||
onChange={(e) =>
|
||||
handleChange(
|
||||
student.id,
|
||||
"mobilityStatus",
|
||||
e.target.value,
|
||||
)}
|
||||
>
|
||||
<option value="N/A">N/A</option>
|
||||
<option value="Planned">Planned</option>
|
||||
|
||||
@@ -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 });
|
||||
}
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
import ConsultStudents_test from "$root/routes/(apps)/mobility/(_islands)/ConsultStudents_test.tsx";
|
||||
import { getPartialsConfig, makePartials } from "$root/defaults/makePartials.tsx";
|
||||
import {
|
||||
getPartialsConfig,
|
||||
makePartials,
|
||||
} from "$root/defaults/makePartials.tsx";
|
||||
import { FreshContext } from "$fresh/server.ts";
|
||||
import { State } from "$root/routes/_middleware.ts";
|
||||
//import EditStudents from "../(_islands)/EditStudents.tsx";
|
||||
|
||||
// deno-lint-ignore require-await
|
||||
async function Mobility(_request: Request, _context: FreshContext<State>) {
|
||||
return (
|
||||
<>
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
import EditMobility from "$root/routes/(apps)/mobility/(_islands)/EditMobility.tsx";
|
||||
import { getPartialsConfig, makePartials } from "$root/defaults/makePartials.tsx";
|
||||
import {
|
||||
getPartialsConfig,
|
||||
makePartials,
|
||||
} from "$root/defaults/makePartials.tsx";
|
||||
import { FreshContext } from "$fresh/server.ts";
|
||||
import { State } from "$root/routes/_middleware.ts";
|
||||
|
||||
// deno-lint-ignore require-await
|
||||
async function Mobility(_request: Request, _context: FreshContext<State>) {
|
||||
return (
|
||||
<>
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
import ConsultMobility from "$root/routes/(apps)/mobility/(_islands)/ConsultMobility.tsx";
|
||||
import { getPartialsConfig, makePartials } from "$root/defaults/makePartials.tsx";
|
||||
import {
|
||||
getPartialsConfig,
|
||||
makePartials,
|
||||
} from "$root/defaults/makePartials.tsx";
|
||||
import { FreshContext } from "$fresh/server.ts";
|
||||
import { State } from "$root/routes/_middleware.ts";
|
||||
|
||||
// deno-lint-ignore require-await
|
||||
async function Mobility(_request: Request, _context: FreshContext<State>) {
|
||||
return (
|
||||
<>
|
||||
@@ -13,4 +17,4 @@ async function Mobility(_request: Request, _context: FreshContext<State>) {
|
||||
}
|
||||
|
||||
export const config = getPartialsConfig();
|
||||
export default makePartials(Mobility);
|
||||
export default makePartials(Mobility);
|
||||
|
||||
@@ -14,7 +14,9 @@ interface Student {
|
||||
}
|
||||
|
||||
export default function ConsultStudents() {
|
||||
const [data, setData] = useState<{ promotions: Promotion[]; students: Student[] } | null>(null);
|
||||
const [data, setData] = useState<
|
||||
{ promotions: Promotion[]; students: Student[] } | null
|
||||
>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
@@ -17,7 +17,7 @@ export default function UploadStudents() {
|
||||
}
|
||||
};
|
||||
|
||||
const confirmUpload = async () => {
|
||||
const confirmUpload = () => {
|
||||
if (!fileData.value) {
|
||||
statusMessage.value = "Please select a file before confirming upload.";
|
||||
return;
|
||||
|
||||
@@ -7,7 +7,7 @@ const properties: AppProperties = {
|
||||
index: "Homepage",
|
||||
overview: "Students overview",
|
||||
upload: "Upload students",
|
||||
consult: "Consult students"
|
||||
consult: "Consult students",
|
||||
},
|
||||
adminOnly: ["upload", "consult"],
|
||||
hint: "Create students promotion and see informations",
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { Handlers } from "$fresh/server.ts";
|
||||
import { Database } from "@db/sqlite";
|
||||
// import { Database } from "@db/sqlite";
|
||||
import connect from "$root/databases/connect.ts";
|
||||
|
||||
export const handler: Handlers = {
|
||||
// deno-lint-ignore require-await
|
||||
async GET() {
|
||||
try {
|
||||
using connection = connect("students");
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
import ConsultStudents from "$root/routes/(apps)/students/(_islands)/ConsultStudents.tsx";
|
||||
import { getPartialsConfig, makePartials } from "$root/defaults/makePartials.tsx";
|
||||
import {
|
||||
getPartialsConfig,
|
||||
makePartials,
|
||||
} from "$root/defaults/makePartials.tsx";
|
||||
import { FreshContext } from "$fresh/server.ts";
|
||||
import { State } from "$root/routes/_middleware.ts";
|
||||
//import EditStudents from "../(_islands)/EditStudents.tsx";
|
||||
|
||||
// deno-lint-ignore require-await
|
||||
async function Students(_request: Request, _context: FreshContext<State>) {
|
||||
return (
|
||||
<>
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
import UploadStudents from "$root/routes/(apps)/students/(_islands)/UploadStudents.tsx";
|
||||
import { getPartialsConfig, makePartials } from "$root/defaults/makePartials.tsx";
|
||||
import {
|
||||
getPartialsConfig,
|
||||
makePartials,
|
||||
} from "$root/defaults/makePartials.tsx";
|
||||
import { FreshContext } from "$fresh/server.ts";
|
||||
import { State } from "$root/routes/_middleware.ts";
|
||||
//import EditStudents from "../(_islands)/EditStudents.tsx";
|
||||
|
||||
// deno-lint-ignore require-await
|
||||
async function Students(_request: Request, _context: FreshContext<State>) {
|
||||
return (
|
||||
<>
|
||||
|
||||
Reference in New Issue
Block a user