Skip to content
Snippets Groups Projects
Commit 6d8bec65 authored by Bastien's avatar Bastien
Browse files

refactor

parent 1710682b
No related branches found
No related tags found
No related merge requests found
......@@ -7,7 +7,7 @@ exports.getMovieInformations = async (req, res, next) => {
let result = await movieServices.getMovieById(filmId);
res.status(200).json(result);
} catch (error) {
res.status(500).json({ error });
res.status(500).json({ error : error.toString()});
}
};
......@@ -18,7 +18,7 @@ exports.searchMovie = async (req, res, next) => {
let result = await movieServices.searchMovie(search);
res.status(200).json(result);
} catch (error) {
res.status(500).json({ error });
res.status(500).json({ error : error.toString()});
}
};
......@@ -28,7 +28,7 @@ exports.searchMovie = async (req, res, next) => {
// db.query('SELECT * FROM Film WHERE releaseDate <= CURDATE() ORDER BY releaseDate DESC LIMIT ?',
// [parseInt(numberOfMovies)], (error, results, fields) => {
// if (error) {
// res.status(500).json({ error });
// res.status(500).json({ error : error.toString()});
// } else {
// res.status(200).json(results);
// }
......@@ -42,7 +42,7 @@ exports.getMovieCast = async (req, res, next) => {
let result = await movieServices.getMovieCast(filmId);
res.status(200).json(result);
} catch (error) {
res.status(500).json({ error });
res.status(500).json({ error : error.toString()});
}
};
......@@ -54,7 +54,7 @@ exports.getMovieNote = async (req, res, next) => {
let result = await movieServices.getMovieUserRate(filmId,username);
res.status(200).json(result);
} catch (error) {
res.status(500).json({ error });
res.status(500).json({ error : error.toString()});
}
};
......@@ -68,20 +68,20 @@ exports.addMovieNote = async (req,res,next) => {
let result = await movieServices.insertOrUpdateMovieUserRate(filmId,username,note);
res.status(200).json({ message: 'Note ajoutée ou modifiée' });
} catch (error) {
res.status(500).json({ error });
res.status(500).json({ error : error.toString()});
}
}
exports.deleteMovieNote = async (req,res,next) => {
let filmId = req.query.id;
let filmId = req.params.id;
let username = req.session.username;
try {
let result = await movieServices.deleteMovieUserRate(filmId,username);
res.status(200).json({ message: 'Note supprimée' });
} catch (error) {
res.status(500).json({ error });
res.status(500).json({ error : error.toString()});
}
}
\ No newline at end of file
......@@ -8,7 +8,7 @@ exports.getPersonInformations = async (req, res, next) => {
let result = await personServices.getPersonById(personId);
res.status(200).json(result);
} catch (error) {
res.status(500).json({ error });
res.status(500).json({ error : error.toString()});
}
};
exports.getPersonMovies = async (req, res, next) => {
......@@ -18,6 +18,6 @@ exports.getPersonMovies = async (req, res, next) => {
let result = await personServices.getPersonMovies(personId);
res.status(200).json(result);
} catch (error) {
res.status(500).json({ error });
res.status(500).json({ error : error.toString()});
}
};
\ No newline at end of file
......@@ -11,7 +11,7 @@ exports.signup = async (req, res, next) => {
let result = await userServices.signup(username, lastname, firstname, birthdate, password)
res.status(201).json({ message: 'Utilisateur ajouté' });
} catch (error) {
res.status(500).json({ error });
res.status(500).json({ error : error.toString()});
}
};
......@@ -30,7 +30,7 @@ exports.login = async (req, res, next) => {
}
} catch (error) {
res.status(500).json({ error });
res.status(500).json({ error : error.toString()});
}
};
......@@ -56,7 +56,7 @@ exports.getUserInformations = async (req, res, next) => {
};
res.status(200).json(infos);
} catch (error) {
res.status(500).json({ error });
res.status(500).json({ error : error.toString()});
}
};
......@@ -95,7 +95,7 @@ exports.getUserInformations = async (req, res, next) => {
// }
// } catch (error) {
// console.error('Erreur lors de la mise à jour des informations utilisateur :', error);
// res.status(500).json({ error });
// res.status(500).json({ error : error.toString()});
// }
// };
......
......@@ -50,7 +50,7 @@ exports.searchMovieByTitle = (searchTitle) => {
*/
exports.getMovieCast = (movieId) => {
return new Promise((resolve, reject) => {
db.query('SELECT * FROM roles r JOIN personne p on r.nconst=p.nconst WHERE r.tconst = ?',
db.query('SELECT * FROM role r JOIN personne p on r.nconst=p.nconst WHERE r.tconst = ?',
[movieId], function (error, results, fields) {
if (error) {
return reject(error);
......
......@@ -33,7 +33,7 @@ exports.getPersonById = (personId) => {
exports.getPersonMovies = (personId) => {
return new Promise((resolve, reject) => {
db.query('SELECT * FROM roles r JOIN film f ON r.tconst=f.tconst WHERE r.nconst = ?',
db.query('SELECT * FROM role r JOIN film f ON r.tconst=f.tconst WHERE r.nconst = ?',
[personId], function (error, results, fields) {
if (error) {
......
......@@ -74,7 +74,7 @@ exports.getMovieUserRate = async (movieId, userId) => {
exports.insertOrUpdateMovieUserRate = async (movieId, userId, rate) => {
try {
let existingRate = await moviesDb.getMovieUserRate(movieId, userId);
if (existingRate.length == 0) {
if (existingRate == null) {
//L'utilisateur n'a pas encore noté ce film, on ajoute la note
return await moviesDb.insertMovieUserRate(movieId, userId, rate);
} else {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment