✨ linkShortener: Count clicks
This commit is contained in:
parent
9f068614f5
commit
55c467f1e4
@ -9,5 +9,10 @@ module.exports = sequelize.define('short_link', {
|
||||
shortcut: {
|
||||
type: Sequelize.TEXT,
|
||||
allowNull: false
|
||||
},
|
||||
count: {
|
||||
type: Sequelize.INTEGER,
|
||||
allowNull: false,
|
||||
defaultValue: 0
|
||||
}
|
||||
})
|
||||
|
@ -51,9 +51,20 @@ app.get('/:shortcut', (req, res, next) => {
|
||||
return res.redirect('/error/404')
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
/* Errors */
|
||||
|
@ -277,6 +277,9 @@ const LinksList = ({
|
||||
<th className='table-row' scope='col'>
|
||||
Nom
|
||||
</th>
|
||||
<th className='table-row' scope='col'>
|
||||
Compteur de clics
|
||||
</th>
|
||||
<th className='table-row' scope='col'>
|
||||
Modifier
|
||||
</th>
|
||||
@ -297,6 +300,7 @@ const LinksList = ({
|
||||
{link.shortcut}
|
||||
</a>
|
||||
</td>
|
||||
<td className='table-row'>{link.count}</td>
|
||||
<td
|
||||
style={{ cursor: 'pointer' }}
|
||||
onClick={() => handleEditLink(link)}
|
||||
|
Reference in New Issue
Block a user