Fixed linting and formatting errors
This commit is contained in:
@@ -24,7 +24,14 @@ interface Mobility {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function ConsultMobility() {
|
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);
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -82,7 +89,9 @@ export default function ConsultMobility() {
|
|||||||
{data.students
|
{data.students
|
||||||
?.filter((student) => student.promotionId === promo.id)
|
?.filter((student) => student.promotionId === promo.id)
|
||||||
.map((student) => {
|
.map((student) => {
|
||||||
const mobility = data.mobilities?.find((mob) => mob.studentId === student.id);
|
const mobility = data.mobilities?.find((mob) =>
|
||||||
|
mob.studentId === student.id
|
||||||
|
);
|
||||||
return (
|
return (
|
||||||
<tr key={student.id}>
|
<tr key={student.id}>
|
||||||
<td>{student.id}</td>
|
<td>{student.id}</td>
|
||||||
|
|||||||
@@ -15,7 +15,9 @@ interface Student {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function ConsultStudents_test() {
|
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);
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@@ -24,7 +24,14 @@ interface Mobility {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function EditMobility() {
|
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 [error, setError] = useState<string | null>(null);
|
||||||
const [isSaving, setIsSaving] = useState(false);
|
const [isSaving, setIsSaving] = useState(false);
|
||||||
|
|
||||||
@@ -69,7 +76,10 @@ export default function EditMobility() {
|
|||||||
const startDate = new Date(updatedMobility.startDate || "");
|
const startDate = new Date(updatedMobility.startDate || "");
|
||||||
const endDate = new Date(updatedMobility.endDate || "");
|
const endDate = new Date(updatedMobility.endDate || "");
|
||||||
if (startDate && endDate && startDate <= 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;
|
updatedMobility.weeksCount = weeks;
|
||||||
} else {
|
} else {
|
||||||
updatedMobility.weeksCount = null;
|
updatedMobility.weeksCount = null;
|
||||||
@@ -99,7 +109,7 @@ export default function EditMobility() {
|
|||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
alert("Data saved successfully!");
|
alert("Data saved successfully!");
|
||||||
window.location.reload();
|
globalThis.location.reload();
|
||||||
} else {
|
} else {
|
||||||
throw new Error(`Failed to save data: ${response.statusText}`);
|
throw new Error(`Failed to save data: ${response.statusText}`);
|
||||||
}
|
}
|
||||||
@@ -143,7 +153,9 @@ export default function EditMobility() {
|
|||||||
{data.students
|
{data.students
|
||||||
?.filter((student) => student.promotionId === promo.id)
|
?.filter((student) => student.promotionId === promo.id)
|
||||||
.map((student) => {
|
.map((student) => {
|
||||||
const mobility = data.mobilities?.find((mob) => mob.studentId === student.id) || {
|
const mobility = data.mobilities?.find((mob) =>
|
||||||
|
mob.studentId === student.id
|
||||||
|
) || {
|
||||||
id: null,
|
id: null,
|
||||||
studentId: student.id,
|
studentId: student.id,
|
||||||
startDate: null,
|
startDate: null,
|
||||||
@@ -163,14 +175,20 @@ export default function EditMobility() {
|
|||||||
<input
|
<input
|
||||||
type="date"
|
type="date"
|
||||||
value={mobility.startDate || ""}
|
value={mobility.startDate || ""}
|
||||||
onChange={(e) => handleChange(student.id, "startDate", e.target.value)}
|
onChange={(e) =>
|
||||||
|
handleChange(
|
||||||
|
student.id,
|
||||||
|
"startDate",
|
||||||
|
e.target.value,
|
||||||
|
)}
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<input
|
<input
|
||||||
type="date"
|
type="date"
|
||||||
value={mobility.endDate || ""}
|
value={mobility.endDate || ""}
|
||||||
onChange={(e) => handleChange(student.id, "endDate", e.target.value)}
|
onChange={(e) =>
|
||||||
|
handleChange(student.id, "endDate", e.target.value)}
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
<td>{mobility.weeksCount ?? "N/A"}</td>
|
<td>{mobility.weeksCount ?? "N/A"}</td>
|
||||||
@@ -178,20 +196,35 @@ export default function EditMobility() {
|
|||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
value={mobility.destinationCountry || ""}
|
value={mobility.destinationCountry || ""}
|
||||||
onChange={(e) => handleChange(student.id, "destinationCountry", e.target.value)}
|
onChange={(e) =>
|
||||||
|
handleChange(
|
||||||
|
student.id,
|
||||||
|
"destinationCountry",
|
||||||
|
e.target.value,
|
||||||
|
)}
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
value={mobility.destinationName || ""}
|
value={mobility.destinationName || ""}
|
||||||
onChange={(e) => handleChange(student.id, "destinationName", e.target.value)}
|
onChange={(e) =>
|
||||||
|
handleChange(
|
||||||
|
student.id,
|
||||||
|
"destinationName",
|
||||||
|
e.target.value,
|
||||||
|
)}
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<select
|
<select
|
||||||
value={mobility.mobilityStatus}
|
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="N/A">N/A</option>
|
||||||
<option value="Planned">Planned</option>
|
<option value="Planned">Planned</option>
|
||||||
|
|||||||
@@ -2,11 +2,16 @@ import { Handlers } from "$fresh/server.ts";
|
|||||||
import { Database } from "@db/sqlite";
|
import { Database } from "@db/sqlite";
|
||||||
|
|
||||||
export const handler: Handlers = {
|
export const handler: Handlers = {
|
||||||
|
// deno-lint-ignore require-await
|
||||||
async GET() {
|
async GET() {
|
||||||
try {
|
try {
|
||||||
console.log("Connecting to mobility database...");
|
console.log("Connecting to mobility database...");
|
||||||
const connection = new Database("databases/data/mobility.db", { create: false });
|
const connection = new Database("databases/data/mobility.db", {
|
||||||
connection.run("ATTACH DATABASE 'databases/data/students.db' AS students");
|
create: false,
|
||||||
|
});
|
||||||
|
connection.run(
|
||||||
|
"ATTACH DATABASE 'databases/data/students.db' AS students",
|
||||||
|
);
|
||||||
console.log("Connected to databases.");
|
console.log("Connected to databases.");
|
||||||
|
|
||||||
const students = connection.prepare(
|
const students = connection.prepare(
|
||||||
@@ -17,7 +22,7 @@ export const handler: Handlers = {
|
|||||||
students.promotionId AS promotionId,
|
students.promotionId AS promotionId,
|
||||||
promotions.name AS promotionName
|
promotions.name AS promotionName
|
||||||
FROM students.students
|
FROM students.students
|
||||||
LEFT JOIN students.promotions ON students.promotionId = promotions.id`
|
LEFT JOIN students.promotions ON students.promotionId = promotions.id`,
|
||||||
).all();
|
).all();
|
||||||
|
|
||||||
const mobilities = connection.prepare(
|
const mobilities = connection.prepare(
|
||||||
@@ -30,11 +35,11 @@ export const handler: Handlers = {
|
|||||||
mobility.destinationCountry,
|
mobility.destinationCountry,
|
||||||
mobility.destinationName,
|
mobility.destinationName,
|
||||||
mobility.mobilityStatus
|
mobility.mobilityStatus
|
||||||
FROM mobility`
|
FROM mobility`,
|
||||||
).all();
|
).all();
|
||||||
|
|
||||||
const promotions = connection.prepare(
|
const promotions = connection.prepare(
|
||||||
`SELECT id, name FROM students.promotions`
|
`SELECT id, name FROM students.promotions`,
|
||||||
).all();
|
).all();
|
||||||
|
|
||||||
connection.close();
|
connection.close();
|
||||||
@@ -63,10 +68,14 @@ export const handler: Handlers = {
|
|||||||
throw new Error("Invalid request body");
|
throw new Error("Invalid request body");
|
||||||
}
|
}
|
||||||
console.log("Connecting to mobility database...");
|
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...");
|
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.");
|
console.log("Students database attached successfully.");
|
||||||
|
|
||||||
const insertQuery = connection.prepare(
|
const insertQuery = connection.prepare(
|
||||||
@@ -80,7 +89,7 @@ export const handler: Handlers = {
|
|||||||
weeksCount = excluded.weeksCount,
|
weeksCount = excluded.weeksCount,
|
||||||
destinationCountry = excluded.destinationCountry,
|
destinationCountry = excluded.destinationCountry,
|
||||||
destinationName = excluded.destinationName,
|
destinationName = excluded.destinationName,
|
||||||
mobilityStatus = excluded.mobilityStatus`
|
mobilityStatus = excluded.mobilityStatus`,
|
||||||
);
|
);
|
||||||
|
|
||||||
for (const mobility of data) {
|
for (const mobility of data) {
|
||||||
@@ -98,7 +107,9 @@ export const handler: Handlers = {
|
|||||||
console.log("Processing mobility data:", mobility);
|
console.log("Processing mobility data:", mobility);
|
||||||
|
|
||||||
const studentExists = connection
|
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);
|
.get(studentId);
|
||||||
|
|
||||||
console.log(`Student ${studentId} exists:`, studentExists.count > 0);
|
console.log(`Student ${studentId} exists:`, studentExists.count > 0);
|
||||||
@@ -113,7 +124,9 @@ export const handler: Handlers = {
|
|||||||
const start = new Date(startDate);
|
const start = new Date(startDate);
|
||||||
const end = new Date(endDate);
|
const end = new Date(endDate);
|
||||||
if (start <= end) {
|
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 {
|
} else {
|
||||||
calculatedWeeksCount = null;
|
calculatedWeeksCount = null;
|
||||||
}
|
}
|
||||||
@@ -138,13 +151,15 @@ export const handler: Handlers = {
|
|||||||
calculatedWeeksCount,
|
calculatedWeeksCount,
|
||||||
destinationCountry,
|
destinationCountry,
|
||||||
destinationName,
|
destinationName,
|
||||||
mobilityStatus
|
mobilityStatus,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
connection.close();
|
connection.close();
|
||||||
console.log("Mobility data inserted/updated successfully.");
|
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) {
|
} catch (error) {
|
||||||
console.error("Error inserting mobility data:", error);
|
console.error("Error inserting mobility data:", error);
|
||||||
return new Response("Failed to insert/update data", { status: 500 });
|
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 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 { FreshContext } from "$fresh/server.ts";
|
||||||
import { State } from "$root/routes/_middleware.ts";
|
import { State } from "$root/routes/_middleware.ts";
|
||||||
//import EditStudents from "../(_islands)/EditStudents.tsx";
|
//import EditStudents from "../(_islands)/EditStudents.tsx";
|
||||||
|
|
||||||
|
// deno-lint-ignore require-await
|
||||||
async function Mobility(_request: Request, _context: FreshContext<State>) {
|
async function Mobility(_request: Request, _context: FreshContext<State>) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
import EditMobility from "$root/routes/(apps)/mobility/(_islands)/EditMobility.tsx";
|
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 { FreshContext } from "$fresh/server.ts";
|
||||||
import { State } from "$root/routes/_middleware.ts";
|
import { State } from "$root/routes/_middleware.ts";
|
||||||
|
|
||||||
|
// deno-lint-ignore require-await
|
||||||
async function Mobility(_request: Request, _context: FreshContext<State>) {
|
async function Mobility(_request: Request, _context: FreshContext<State>) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
import ConsultMobility from "$root/routes/(apps)/mobility/(_islands)/ConsultMobility.tsx";
|
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 { FreshContext } from "$fresh/server.ts";
|
||||||
import { State } from "$root/routes/_middleware.ts";
|
import { State } from "$root/routes/_middleware.ts";
|
||||||
|
|
||||||
|
// deno-lint-ignore require-await
|
||||||
async function Mobility(_request: Request, _context: FreshContext<State>) {
|
async function Mobility(_request: Request, _context: FreshContext<State>) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@@ -14,7 +14,9 @@ interface Student {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function ConsultStudents() {
|
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);
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ export default function UploadStudents() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const confirmUpload = async () => {
|
const confirmUpload = () => {
|
||||||
if (!fileData.value) {
|
if (!fileData.value) {
|
||||||
statusMessage.value = "Please select a file before confirming upload.";
|
statusMessage.value = "Please select a file before confirming upload.";
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ const properties: AppProperties = {
|
|||||||
index: "Homepage",
|
index: "Homepage",
|
||||||
overview: "Students overview",
|
overview: "Students overview",
|
||||||
upload: "Upload students",
|
upload: "Upload students",
|
||||||
consult: "Consult students"
|
consult: "Consult students",
|
||||||
},
|
},
|
||||||
adminOnly: ["upload", "consult"],
|
adminOnly: ["upload", "consult"],
|
||||||
hint: "Create students promotion and see informations",
|
hint: "Create students promotion and see informations",
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import { Handlers } from "$fresh/server.ts";
|
import { Handlers } from "$fresh/server.ts";
|
||||||
import { Database } from "@db/sqlite";
|
// import { Database } from "@db/sqlite";
|
||||||
import connect from "$root/databases/connect.ts";
|
import connect from "$root/databases/connect.ts";
|
||||||
|
|
||||||
export const handler: Handlers = {
|
export const handler: Handlers = {
|
||||||
|
// deno-lint-ignore require-await
|
||||||
async GET() {
|
async GET() {
|
||||||
try {
|
try {
|
||||||
using connection = connect("students");
|
using connection = connect("students");
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
import ConsultStudents from "$root/routes/(apps)/students/(_islands)/ConsultStudents.tsx";
|
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 { FreshContext } from "$fresh/server.ts";
|
||||||
import { State } from "$root/routes/_middleware.ts";
|
import { State } from "$root/routes/_middleware.ts";
|
||||||
//import EditStudents from "../(_islands)/EditStudents.tsx";
|
//import EditStudents from "../(_islands)/EditStudents.tsx";
|
||||||
|
|
||||||
|
// deno-lint-ignore require-await
|
||||||
async function Students(_request: Request, _context: FreshContext<State>) {
|
async function Students(_request: Request, _context: FreshContext<State>) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
import UploadStudents from "$root/routes/(apps)/students/(_islands)/UploadStudents.tsx";
|
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 { FreshContext } from "$fresh/server.ts";
|
||||||
import { State } from "$root/routes/_middleware.ts";
|
import { State } from "$root/routes/_middleware.ts";
|
||||||
//import EditStudents from "../(_islands)/EditStudents.tsx";
|
//import EditStudents from "../(_islands)/EditStudents.tsx";
|
||||||
|
|
||||||
|
// deno-lint-ignore require-await
|
||||||
async function Students(_request: Request, _context: FreshContext<State>) {
|
async function Students(_request: Request, _context: FreshContext<State>) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|||||||
Reference in New Issue
Block a user