Remove console log
This commit is contained in:
@@ -6,7 +6,7 @@ interface Promotion {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface MobilityData {
|
interface MobilityData {
|
||||||
id: number | null; // null pour les nouvelles entrées
|
id: number | null;
|
||||||
studentId: string;
|
studentId: string;
|
||||||
firstName: string;
|
firstName: string;
|
||||||
lastName: string;
|
lastName: string;
|
||||||
@@ -27,7 +27,6 @@ export default function EditMobility() {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function fetchMobilityData() {
|
async function fetchMobilityData() {
|
||||||
console.log("EditMobility: Fetching data from API...");
|
|
||||||
const response = await fetch("/mobility/api/insert_mobility");
|
const response = await fetch("/mobility/api/insert_mobility");
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
console.log("EditMobility: Data fetched successfully:", data);
|
console.log("EditMobility: Data fetched successfully:", data);
|
||||||
@@ -39,7 +38,7 @@ export default function EditMobility() {
|
|||||||
(mobility: any) => mobility.studentId === student.id
|
(mobility: any) => mobility.studentId === student.id
|
||||||
);
|
);
|
||||||
return {
|
return {
|
||||||
id: existingMobility ? existingMobility.id : null, // null si aucune mobilité existante
|
id: existingMobility ? existingMobility.id : null,
|
||||||
studentId: student.id,
|
studentId: student.id,
|
||||||
firstName: student.firstName,
|
firstName: student.firstName,
|
||||||
lastName: student.lastName,
|
lastName: student.lastName,
|
||||||
@@ -73,9 +72,7 @@ export default function EditMobility() {
|
|||||||
|
|
||||||
const handleSave = async () => {
|
const handleSave = async () => {
|
||||||
setIsSaving(true);
|
setIsSaving(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
console.log("EditMobility: Sending data to API...");
|
|
||||||
const response = await fetch("/mobility/api/insert_mobility", {
|
const response = await fetch("/mobility/api/insert_mobility", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
@@ -97,7 +94,6 @@ export default function EditMobility() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Grouper les données par promotion
|
|
||||||
const groupedData = promotions.map((promo) => ({
|
const groupedData = promotions.map((promo) => ({
|
||||||
promotion: promo.name,
|
promotion: promo.name,
|
||||||
students: mobilityData.filter(
|
students: mobilityData.filter(
|
||||||
|
|||||||
@@ -4,12 +4,8 @@ import connect from "$root/databases/connect.ts";
|
|||||||
export const handler: Handlers = {
|
export const handler: Handlers = {
|
||||||
// deno-lint-ignore require-await
|
// deno-lint-ignore require-await
|
||||||
async GET() {
|
async GET() {
|
||||||
console.log("API /mobility/api/insert_mobility GET called");
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
console.log("Connecting to mobility database...");
|
|
||||||
using connection = connect("mobility");
|
using connection = connect("mobility");
|
||||||
console.log("Connected to databases.");
|
|
||||||
|
|
||||||
const mobilities = connection.database.prepare(
|
const mobilities = connection.database.prepare(
|
||||||
`SELECT
|
`SELECT
|
||||||
@@ -53,8 +49,6 @@ export const handler: Handlers = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
async POST(request) {
|
async POST(request) {
|
||||||
console.log("API /mobility/api/insert_mobility POST called");
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const body = await request.json();
|
const body = await request.json();
|
||||||
const { data } = body;
|
const { data } = body;
|
||||||
@@ -63,30 +57,7 @@ export const handler: Handlers = {
|
|||||||
throw new Error("Invalid request body");
|
throw new Error("Invalid request body");
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("Connecting to mobility database...");
|
|
||||||
using connection = connect("mobility");
|
using connection = connect("mobility");
|
||||||
console.log("Connected to databases.");
|
|
||||||
|
|
||||||
const attachedDatabases = connection.database
|
|
||||||
.prepare("PRAGMA database_list")
|
|
||||||
.all();
|
|
||||||
console.log("Attached databases:", attachedDatabases);
|
|
||||||
|
|
||||||
const tablesInMain = connection.database
|
|
||||||
.prepare("SELECT name FROM sqlite_master WHERE type='table'")
|
|
||||||
.all();
|
|
||||||
console.log("Tables in main:", tablesInMain);
|
|
||||||
|
|
||||||
const tablesInStudents = connection.database
|
|
||||||
.prepare("SELECT name FROM students.sqlite_master WHERE type='table'")
|
|
||||||
.all();
|
|
||||||
console.log("Tables in students:", tablesInStudents);
|
|
||||||
|
|
||||||
const testQuery = connection.database
|
|
||||||
.prepare("SELECT COUNT(*) AS count FROM students.students")
|
|
||||||
.get();
|
|
||||||
console.log(`Test query result: Students table has ${testQuery.count} rows.`);
|
|
||||||
|
|
||||||
const insertQuery = connection.database.prepare(
|
const insertQuery = connection.database.prepare(
|
||||||
`INSERT INTO mobility (
|
`INSERT INTO mobility (
|
||||||
id, studentId, startDate, endDate, weeksCount, destinationCountry, destinationName, mobilityStatus
|
id, studentId, startDate, endDate, weeksCount, destinationCountry, destinationName, mobilityStatus
|
||||||
@@ -113,16 +84,6 @@ export const handler: Handlers = {
|
|||||||
mobilityStatus = "N/A",
|
mobilityStatus = "N/A",
|
||||||
} = mobility;
|
} = mobility;
|
||||||
|
|
||||||
console.log(`Checking if studentId ${studentId} exists in students.students`);
|
|
||||||
const studentExists = connection.database
|
|
||||||
.prepare("SELECT COUNT(*) AS count FROM students.students WHERE userId = ?")
|
|
||||||
.get(studentId);
|
|
||||||
|
|
||||||
if (studentExists.count === 0) {
|
|
||||||
console.warn(`Student with ID ${studentId} does not exist. Skipping.`);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
let calculatedWeeksCount = weeksCount;
|
let calculatedWeeksCount = weeksCount;
|
||||||
if (startDate && endDate) {
|
if (startDate && endDate) {
|
||||||
const start = new Date(startDate);
|
const start = new Date(startDate);
|
||||||
@@ -134,7 +95,6 @@ export const handler: Handlers = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`Inserting/Updating mobility for studentId: ${studentId}`);
|
|
||||||
insertQuery.run(
|
insertQuery.run(
|
||||||
id,
|
id,
|
||||||
studentId,
|
studentId,
|
||||||
|
|||||||
Reference in New Issue
Block a user