Added visits api

This commit is contained in:
Nicolai Ort 2021-08-14 09:28:10 +02:00
parent d8cb023765
commit fd16b39443
Signed by: niggl
GPG Key ID: 13AFA55AF62F269F
1 changed files with 22 additions and 0 deletions

View File

@ -161,7 +161,29 @@ fastify.get('/api/:shortcode', async (req, res) => {
visits: visits.length
}
});
//Get url api route
fastify.get('/api/:shortcode/visits', async (req, res) => {
const shortcode = req.params.shortcode;
//This should never happen but better safe than 500
if (!shortcode) {
return 404;
}
const exists = await knex.select('shortcode', 'target')
.from('urls')
.where('shortcode', '=', shortcode)
.limit(1);
if (exists.length == 0) {
return 404;
}
const visits = await knex.select('timestamp')
.from('visits')
.where('shortcode', '=', shortcode);
return visits;
});
/**