correction server.js sql req
This commit is contained in:
parent
362380fe18
commit
97a95c9a91
@ -91,12 +91,12 @@ autopostRouter.get('/', async (req, res) => {
|
||||
|
||||
try {
|
||||
// Récupérer le nombre total d'enregistrements
|
||||
const [countResult] = await db.query("SELECT COUNT(*) as total FROM \`${config.DB_TABLE}\`");
|
||||
const [countResult] = await db.query(`SELECT COUNT(*) as total FROM \`${config.DB_TABLE}\``);
|
||||
const totalRecords = countResult[0].total;
|
||||
const totalPages = Math.ceil(totalRecords / limit);
|
||||
|
||||
const [rows] = await db.query(
|
||||
"SELECT nom, status, id FROM \`${config.DB_TABLE}\` ORDER BY (status = 2) DESC, id DESC LIMIT ? OFFSET ?",
|
||||
`SELECT nom, status, id FROM \`${config.DB_TABLE}\` ORDER BY (status = 2) DESC, id DESC LIMIT ? OFFSET ?`,
|
||||
[limit, offset]
|
||||
);
|
||||
|
||||
@ -456,7 +456,7 @@ autopostRouter.get('/search', async (req, res) => {
|
||||
const searchQuery = "%" + q + "%";
|
||||
try {
|
||||
const [rows] = await db.query(
|
||||
"SELECT nom, status, id FROM \`${config.DB_TABLE}\` WHERE nom LIKE ? ORDER BY id DESC LIMIT 500",
|
||||
`SELECT nom, status, id FROM \`${config.DB_TABLE}\` WHERE nom LIKE ? ORDER BY id DESC LIMIT 500`,
|
||||
[searchQuery]
|
||||
);
|
||||
res.json(rows);
|
||||
@ -576,7 +576,7 @@ autopostRouter.post('/edit/:id', async (req, res) => {
|
||||
const id = req.params.id;
|
||||
const newStatus = req.body.status;
|
||||
try {
|
||||
await db.query("UPDATE \`${config.DB_TABLE}\` SET status = ? WHERE id = ?", [newStatus, id]);
|
||||
await db.query(`UPDATE \`${config.DB_TABLE}\` SET status = ? WHERE id = ?`, [newStatus, id]);
|
||||
if (req.xhr || req.headers.accept.indexOf('json') > -1) {
|
||||
res.json({ success: true });
|
||||
} else {
|
||||
@ -592,7 +592,7 @@ autopostRouter.post('/edit/:id', async (req, res) => {
|
||||
autopostRouter.post('/delete/:id', async (req, res) => {
|
||||
const id = req.params.id;
|
||||
try {
|
||||
await db.query("DELETE FROM \`${config.DB_TABLE}\` WHERE id = ?", [id]);
|
||||
await db.query(`DELETE FROM \`${config.DB_TABLE}\` WHERE id = ?`, [id]);
|
||||
if (req.xhr || req.headers.accept.indexOf('json') > -1) {
|
||||
res.json({ success: true });
|
||||
} else {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user