mirror of
https://github.com/ArthurDanjou/artdanj-shortener.git
synced 2026-02-01 16:29:33 +01:00
Move cli commands in core module to use node ace
This commit is contained in:
41
commands/Logs.ts
Normal file
41
commands/Logs.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import {args, BaseCommand} from '@adonisjs/core/build/standalone'
|
||||
import Link from "App/Models/Link";
|
||||
|
||||
export default class Logs extends BaseCommand {
|
||||
|
||||
public static commandName = 'link:logs'
|
||||
|
||||
public static description = 'Retrieves the number of visits of a link'
|
||||
|
||||
public static aliases = ['link:stats', 'link:show']
|
||||
|
||||
public static settings = {
|
||||
loadApp: true,
|
||||
stayAlive: false,
|
||||
}
|
||||
|
||||
@args.string({ description: 'Code of the new link' })
|
||||
public code: string
|
||||
|
||||
public async run () {
|
||||
const link = await Link.findBy('code', this.code)
|
||||
if (!link) {
|
||||
this.logger.warning(`The link with code '${this.code}' does not exist!`)
|
||||
return
|
||||
}
|
||||
await link.load('clicks')
|
||||
const table = this.ui.table()
|
||||
table.head(['Id', 'IP', 'Country', 'Date'])
|
||||
|
||||
link.clicks.forEach((click) => {
|
||||
table.row([
|
||||
`${click.id}`,
|
||||
click.ip,
|
||||
click.country.length == 0 ? this.colors.grey('Unknown') : click.country,
|
||||
click.date.toSQL()
|
||||
])
|
||||
})
|
||||
|
||||
table.render()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user