modif
This commit is contained in:
commit
b04045ca8e
3 changed files with 40 additions and 77 deletions
21
db_init.js
21
db_init.js
|
|
@ -22,4 +22,25 @@ function initDb(dbPath = './database.sqlite') {
|
|||
});
|
||||
}
|
||||
|
||||
function initDb (dbPath = './database.sqlite') {
|
||||
return new Promise((resolve, reject) => {
|
||||
const db = new sqlite3.Database(dbPath, (err) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
db.run(`
|
||||
CREATE TABLE IF NOT EXISTS restaurants (
|
||||
id INTEGER PRIMARY KEY,
|
||||
nom TEXT NOT NULL,
|
||||
description TEXT,
|
||||
adresse TEXT NOT NULL,
|
||||
menu TEXT
|
||||
);
|
||||
`);
|
||||
}
|
||||
db.close();
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
};
|
||||
module.exports = initDb;
|
||||
|
|
|
|||
18
routes.js
18
routes.js
|
|
@ -33,4 +33,22 @@ router.get('/logout', (req, res) => {
|
|||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
// Infos resto
|
||||
router.get('/restaurants/:id', async (req, res) => {
|
||||
const id = req.params.id;
|
||||
try {
|
||||
const restaurant = await db.get(`SELECT * FROM restaurants WHERE id = ?`, [id]);
|
||||
if (!restaurant) {
|
||||
res.status(404).send('Restaurant non trouvé');
|
||||
} else {
|
||||
res.render('restaurant', { restaurant });
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
res.status(500).send('Erreur lors de la récupération des informations du restaurant');
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
|
@ -1,76 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Diagramme Radar avec Chart.js</title>
|
||||
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div style="width: 35%; margin: 0 auto;">
|
||||
<canvas id="radarChart"></canvas>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const ctx = document.getElementById('radarChart').getContext('2d');
|
||||
const radarChart = new Chart(ctx, {
|
||||
type: 'radar',
|
||||
data: {
|
||||
labels: ['Qualité des plats', 'Ambiance', 'Accessibilité', 'Service', 'Tradition'],
|
||||
datasets: [
|
||||
{
|
||||
label: 'Moyenne des notes',
|
||||
data: [4.7, 4.6, 4.4, 4.3, 4.8],
|
||||
fill: true,
|
||||
backgroundColor: 'rgba(25, 80, 233, 0.2)',
|
||||
borderColor: 'rgb(25, 80, 233, 10)',
|
||||
pointBackgroundColor: 'rgb(55, 99, 132)',
|
||||
pointBorderColor: '#fff',
|
||||
pointHoverBackgroundColor: '#fff',
|
||||
pointHoverBorderColor: 'rgb(255, 99, 132)',
|
||||
pointStyle: 'circle',
|
||||
pointRadius: 5,
|
||||
pointRotation: 0,
|
||||
},
|
||||
]
|
||||
},
|
||||
options: {
|
||||
plugins: {
|
||||
legend: {
|
||||
display: false
|
||||
},
|
||||
tooltip: {
|
||||
callbacks: {
|
||||
label: function(context) {
|
||||
let label = context.dataset.label || '';
|
||||
if (label) {
|
||||
label += ': ';
|
||||
}
|
||||
label += context.formattedValue;
|
||||
return label;
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
scales: {
|
||||
r: {
|
||||
max: 5,
|
||||
min: 0,
|
||||
ticks: {
|
||||
stepSize: 1,
|
||||
callback: function(value, index, values) {
|
||||
return value.toFixed(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
elements: {
|
||||
line: {
|
||||
borderWidth: 3
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Reference in a new issue