Consult mobility working
This commit is contained in:
@@ -5,11 +5,16 @@ interface Promotion {
|
|||||||
name: string;
|
name: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface Student {
|
||||||
|
id: string;
|
||||||
|
firstName: string;
|
||||||
|
lastName: string;
|
||||||
|
promotionId: number;
|
||||||
|
}
|
||||||
|
|
||||||
interface Mobility {
|
interface Mobility {
|
||||||
id: number;
|
id: number;
|
||||||
studentId: string;
|
studentId: string;
|
||||||
firstName: string;
|
|
||||||
lastName: string;
|
|
||||||
startDate: string | null;
|
startDate: string | null;
|
||||||
endDate: string | null;
|
endDate: string | null;
|
||||||
weeksCount: number | null;
|
weeksCount: number | null;
|
||||||
@@ -19,7 +24,7 @@ interface Mobility {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function ConsultMobility() {
|
export default function ConsultMobility() {
|
||||||
const [data, setData] = useState<{ promotions?: Promotion[]; 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(() => {
|
||||||
@@ -74,21 +79,24 @@ export default function ConsultMobility() {
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{data.mobilities
|
{data.students
|
||||||
.filter((mobility) => mobility.studentId.startsWith(String(promo.id)))
|
?.filter((student) => student.promotionId === promo.id)
|
||||||
.map((mobility) => (
|
.map((student) => {
|
||||||
<tr key={mobility.id}>
|
const mobility = data.mobilities?.find((mob) => mob.studentId === student.id);
|
||||||
<td>{mobility.id}</td>
|
return (
|
||||||
<td>{mobility.firstName}</td>
|
<tr key={student.id}>
|
||||||
<td>{mobility.lastName}</td>
|
<td>{student.id}</td>
|
||||||
<td>{mobility.startDate || "N/A"}</td>
|
<td>{student.firstName}</td>
|
||||||
<td>{mobility.endDate || "N/A"}</td>
|
<td>{student.lastName}</td>
|
||||||
<td>{mobility.weeksCount ?? "N/A"}</td>
|
<td>{mobility?.startDate || "N/A"}</td>
|
||||||
<td>{mobility.destinationCountry || "N/A"}</td>
|
<td>{mobility?.endDate || "N/A"}</td>
|
||||||
<td>{mobility.destinationName || "N/A"}</td>
|
<td>{mobility?.weeksCount ?? "N/A"}</td>
|
||||||
<td>{mobility.mobilityStatus}</td>
|
<td>{mobility?.destinationCountry || "N/A"}</td>
|
||||||
|
<td>{mobility?.destinationName || "N/A"}</td>
|
||||||
|
<td>{mobility?.mobilityStatus || "N/A"}</td>
|
||||||
</tr>
|
</tr>
|
||||||
))}
|
);
|
||||||
|
})}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -9,24 +9,30 @@ export const handler: Handlers = {
|
|||||||
connection.run("ATTACH DATABASE 'databases/data/students.db' AS students");
|
connection.run("ATTACH DATABASE 'databases/data/students.db' AS students");
|
||||||
console.log("Connected to databases.");
|
console.log("Connected to databases.");
|
||||||
|
|
||||||
// Récupération des mobilités
|
const students = connection.prepare(
|
||||||
|
`SELECT
|
||||||
|
students.userId AS id,
|
||||||
|
students.firstName,
|
||||||
|
students.lastName,
|
||||||
|
students.promotionId AS promotionId,
|
||||||
|
promotions.name AS promotionName
|
||||||
|
FROM students.students
|
||||||
|
LEFT JOIN students.promotions ON students.promotionId = promotions.id`
|
||||||
|
).all();
|
||||||
|
|
||||||
const mobilities = connection.prepare(
|
const mobilities = connection.prepare(
|
||||||
`SELECT
|
`SELECT
|
||||||
mobility.id,
|
mobility.id,
|
||||||
mobility.studentId,
|
mobility.studentId,
|
||||||
students.firstName,
|
|
||||||
students.lastName,
|
|
||||||
mobility.startDate,
|
mobility.startDate,
|
||||||
mobility.endDate,
|
mobility.endDate,
|
||||||
mobility.weeksCount,
|
mobility.weeksCount,
|
||||||
mobility.destinationCountry,
|
mobility.destinationCountry,
|
||||||
mobility.destinationName,
|
mobility.destinationName,
|
||||||
mobility.mobilityStatus
|
mobility.mobilityStatus
|
||||||
FROM mobility
|
FROM mobility`
|
||||||
LEFT JOIN students.students ON mobility.studentId = students.userId`
|
|
||||||
).all();
|
).all();
|
||||||
|
|
||||||
// Récupération des promotions
|
|
||||||
const promotions = connection.prepare(
|
const promotions = connection.prepare(
|
||||||
`SELECT id, name FROM students.promotions`
|
`SELECT id, name FROM students.promotions`
|
||||||
).all();
|
).all();
|
||||||
@@ -34,7 +40,7 @@ export const handler: Handlers = {
|
|||||||
connection.close();
|
connection.close();
|
||||||
|
|
||||||
return new Response(
|
return new Response(
|
||||||
JSON.stringify({ mobilities, promotions }),
|
JSON.stringify({ mobilities, students, promotions }),
|
||||||
{
|
{
|
||||||
status: 200,
|
status: 200,
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
|
|||||||
Reference in New Issue
Block a user