diff --git a/api/models/short_links.js b/api/models/short_links.js index b994d1c..c68c43c 100644 --- a/api/models/short_links.js +++ b/api/models/short_links.js @@ -9,5 +9,10 @@ module.exports = sequelize.define('short_link', { shortcut: { type: Sequelize.TEXT, allowNull: false + }, + count: { + type: Sequelize.INTEGER, + allowNull: false, + defaultValue: 0 } }) diff --git a/s.divlo.fr/app.js b/s.divlo.fr/app.js index 250e6ea..e8d2124 100644 --- a/s.divlo.fr/app.js +++ b/s.divlo.fr/app.js @@ -51,7 +51,18 @@ app.get('/:shortcut', (req, res, next) => { return res.redirect('/error/404') } - return res.redirect(result.url) + const count = (result.count += 1) + database.query( + 'UPDATE short_links SET count = ? WHERE id = ?', + [count, result.id], + error => { + if (error != null) { + return next(error) + } + + return res.redirect(result.url) + } + ) } ) }) diff --git a/website/pages/functions/linkShortener.jsx b/website/pages/functions/linkShortener.jsx index 79adc94..48ce763 100644 --- a/website/pages/functions/linkShortener.jsx +++ b/website/pages/functions/linkShortener.jsx @@ -277,6 +277,9 @@ const LinksList = ({ Nom + + Compteur de clics + Modifier @@ -297,6 +300,7 @@ const LinksList = ({ {link.shortcut} + {link.count} handleEditLink(link)} diff --git a/website/pages/users/[name].jsx b/website/pages/users/[name].jsx index 3fcd6e3..f48ad2a 100644 --- a/website/pages/users/[name].jsx +++ b/website/pages/users/[name].jsx @@ -41,8 +41,8 @@ const Profile = props => { event.target.files != null ? event.target.files[0] : isTypeCheck - ? event.target.checked - : event.target.value + ? event.target.checked + : event.target.value setInputState(inputStateNew) }