Renommer le gestionnaire de stockage et mettre à jour les références dans les fichiers concernés. Supprimer les fichiers obsolètes et ajouter un nouveau fichier de gestion de stockage.
This commit is contained in:
@@ -117,7 +117,7 @@ async function init_function() {
|
||||
console.error('Error initializing database:', err);
|
||||
throw err;
|
||||
}
|
||||
} finally {
|
||||
} finally {
|
||||
console.log('Database initialization process completed.');
|
||||
}
|
||||
}
|
||||
@@ -126,19 +126,126 @@ init_function()
|
||||
.then(() => console.log('Database initialization completed.'))
|
||||
.catch(err => console.error('Error during database initialization:', err));
|
||||
|
||||
|
||||
const database_manager = {
|
||||
createVideoProject: async (project_id, measurement_ids, name, resolution, duration) => {
|
||||
const query = `INSERT INTO public.videos (project_id, measurement_ids, name, resolution, duration) VALUES ($1, $2, $3, $4, $5) RETURNING id`;
|
||||
const values = [project_id, measurement_ids, name, resolution, duration];
|
||||
// Fonctions pour les projets
|
||||
function handleDatabaseOperation(operation) {
|
||||
return async (...args) => {
|
||||
try {
|
||||
const result = await db.query(query, values);
|
||||
return result.rows[0].id;
|
||||
return await operation(...args);
|
||||
} catch (err) {
|
||||
console.error('Error creating video project:', err);
|
||||
console.error(`Error during database operation: ${operation.name}`, err);
|
||||
throw err;
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const project = {
|
||||
get_all_projects: handleDatabaseOperation(async () => {
|
||||
const query = `SELECT * FROM projects;`;
|
||||
return (await db.query(query)).rows;
|
||||
}),
|
||||
get_project_by_id: handleDatabaseOperation(async (id) => {
|
||||
const query = `SELECT * FROM projects WHERE id = $1;`;
|
||||
return (await db.query(query, [id])).rows[0];
|
||||
}),
|
||||
create_project: handleDatabaseOperation(async (name, description, start_date, status) => {
|
||||
const query = `INSERT INTO projects (name, description, start_date, status) VALUES ($1, $2, $3, $4) RETURNING *;`;
|
||||
return (await db.query(query, [name, description, start_date, status])).rows[0];
|
||||
}),
|
||||
edit_project_by_id: handleDatabaseOperation(async (id, updates) => {
|
||||
const fields = Object.keys(updates).map((key, index) => `${key} = $${index + 2}`).join(', ');
|
||||
const values = [id, ...Object.values(updates)];
|
||||
const query = `UPDATE projects SET ${fields} WHERE id = $1 RETURNING *;`;
|
||||
return (await db.query(query, values)).rows[0];
|
||||
}),
|
||||
delete_project_by_id: handleDatabaseOperation(async (id) => {
|
||||
const query = `DELETE FROM projects WHERE id = $1;`;
|
||||
await db.query(query, [id]);
|
||||
})
|
||||
};
|
||||
|
||||
module.exports = database_manager;
|
||||
const measurement = {
|
||||
get_all_measurements: handleDatabaseOperation(async () => {
|
||||
const query = `SELECT * FROM measurements;`;
|
||||
return (await db.query(query)).rows;
|
||||
}),
|
||||
get_measurement_by_id: handleDatabaseOperation(async (id) => {
|
||||
const query = `SELECT * FROM measurements WHERE id = $1;`;
|
||||
return (await db.query(query, [id])).rows[0];
|
||||
}),
|
||||
get_measurement_by_project_and_order_id: handleDatabaseOperation(async (project_id, order_id) => {
|
||||
const query = `SELECT * FROM measurements WHERE project_id = $1 AND order_id = $2;`;
|
||||
return (await db.query(query, [project_id, order_id])).rows[0];
|
||||
}),
|
||||
get_measurements_by_project_id: handleDatabaseOperation(async (project_id) => {
|
||||
const query = `SELECT * FROM measurements WHERE project_id = $1;`;
|
||||
return (await db.query(query, [project_id])).rows;
|
||||
}),
|
||||
create_measurement: handleDatabaseOperation(async (project_id, timestamp, path, temperature, humidity, order_id) => {
|
||||
const query = `INSERT INTO measurements (project_id, timestamp, path, temperature, humidity, order_id) VALUES ($1, $2, $3, $4, $5, $6) RETURNING *;`;
|
||||
return (await db.query(query, [project_id, timestamp, path, temperature, humidity, order_id])).rows[0];
|
||||
}),
|
||||
edit_measurement_by_id: handleDatabaseOperation(async (id, updates) => {
|
||||
const fields = Object.keys(updates).map((key, index) => `${key} = $${index + 2}`).join(', ');
|
||||
const values = [id, ...Object.values(updates)];
|
||||
const query = `UPDATE measurements SET ${fields} WHERE id = $1 RETURNING *;`;
|
||||
return (await db.query(query, values)).rows[0];
|
||||
}),
|
||||
delete_measurement_by_id: handleDatabaseOperation(async (id) => {
|
||||
const query = `DELETE FROM measurements WHERE id = $1;`;
|
||||
await db.query(query, [id]);
|
||||
})
|
||||
};
|
||||
|
||||
const video = {
|
||||
get_all_videos: handleDatabaseOperation(async () => {
|
||||
const query = `SELECT * FROM videos;`;
|
||||
return (await db.query(query)).rows;
|
||||
}),
|
||||
get_video_by_id: handleDatabaseOperation(async (id) => {
|
||||
const query = `SELECT * FROM videos WHERE id = $1;`;
|
||||
return (await db.query(query, [id])).rows[0];
|
||||
}),
|
||||
get_videos_by_project_id: handleDatabaseOperation(async (project_id) => {
|
||||
const query = `SELECT * FROM videos WHERE project_id = $1;`;
|
||||
return (await db.query(query, [project_id])).rows;
|
||||
}),
|
||||
create_video: handleDatabaseOperation(async (project_id, measurement_ids, video_file, resolution, duration, status, name, progress, started_at, updated_at, eta) => {
|
||||
const query = `INSERT INTO videos (project_id, measurement_ids, video_file, resolution, duration, status, name, progress, started_at, updated_at, eta) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11) RETURNING *;`;
|
||||
return (await db.query(query, [project_id, measurement_ids, video_file, resolution, duration, status, name, progress, started_at, updated_at, eta])).rows[0];
|
||||
}),
|
||||
edit_video_by_id: handleDatabaseOperation(async (id, updates) => {
|
||||
const fields = Object.keys(updates).map((key, index) => `${key} = $${index + 2}`).join(', ');
|
||||
const values = [id, ...Object.values(updates)];
|
||||
const query = `UPDATE videos SET ${fields} WHERE id = $1 RETURNING *;`;
|
||||
return (await db.query(query, values)).rows[0];
|
||||
}),
|
||||
delete_video_by_id: handleDatabaseOperation(async (id) => {
|
||||
const query = `DELETE FROM videos WHERE id = $1;`;
|
||||
await db.query(query, [id]);
|
||||
})
|
||||
};
|
||||
|
||||
const camera = {
|
||||
get_camera: handleDatabaseOperation(async () => {
|
||||
const query = `SELECT * FROM camera;`;
|
||||
return (await db.query(query)).rows;
|
||||
}),
|
||||
edit_camera: handleDatabaseOperation(async (id, updates) => {
|
||||
const fields = Object.keys(updates).map((key, index) => `${key} = $${index + 2}`).join(', ');
|
||||
const values = [id, ...Object.values(updates)];
|
||||
const query = `UPDATE camera SET ${fields} WHERE id = $1 RETURNING *;`;
|
||||
return (await db.query(query, values)).rows[0];
|
||||
}),
|
||||
delete_camera: handleDatabaseOperation(async (id) => {
|
||||
const query = `DELETE FROM camera WHERE id = $1;`;
|
||||
await db.query(query, [id]);
|
||||
})
|
||||
};
|
||||
|
||||
// Export des modules
|
||||
module.exports = {
|
||||
project,
|
||||
measurement,
|
||||
video,
|
||||
camera
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user