Added visits api
This commit is contained in:
parent
d8cb023765
commit
fd16b39443
|
@ -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;
|
||||
});
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue