Fix formatting
This commit is contained in:
@ -6,9 +6,7 @@ import redis from '@adonisjs/redis/services/main'
|
||||
import { fetchBatch } from '../Helpers/Replays.js'
|
||||
import { sendDataToWebhook } from '../Helpers/Webhook.js'
|
||||
|
||||
|
||||
export default class ReplaysController {
|
||||
|
||||
public async stats({ request, response }: HttpContext) {
|
||||
const { sendToWebhook } = request.qs()
|
||||
const latestVersion = await redis.get(`replays:stats:latest_version`)
|
||||
@ -24,7 +22,12 @@ export default class ReplaysController {
|
||||
}
|
||||
}
|
||||
|
||||
let responseData = { version: results.version, updatedAt: results.updatedAt, numberOfRecords: results.rows.length, data: results.rows }
|
||||
let responseData = {
|
||||
version: results.version,
|
||||
updatedAt: results.updatedAt,
|
||||
numberOfRecords: results.rows.length,
|
||||
data: results.rows,
|
||||
}
|
||||
if (sendToWebhook) {
|
||||
await sendDataToWebhook(responseData)
|
||||
}
|
||||
@ -40,7 +43,7 @@ export default class ReplaysController {
|
||||
let paginated, meta, replays
|
||||
|
||||
if (data) {
|
||||
({ paginated, meta, replays } = JSON.parse(data))
|
||||
;({ paginated, meta, replays } = JSON.parse(data))
|
||||
} else {
|
||||
paginated = await Replay.query().paginate(page, perPage)
|
||||
paginated.baseUrl('/list')
|
||||
@ -49,7 +52,7 @@ export default class ReplaysController {
|
||||
|
||||
meta = {
|
||||
...json.meta,
|
||||
links: buildPaginationLinks(json.meta)
|
||||
links: buildPaginationLinks(json.meta),
|
||||
}
|
||||
|
||||
replays = json.data
|
||||
@ -60,17 +63,14 @@ export default class ReplaysController {
|
||||
return inertia.render('Replays/Index', {
|
||||
data: {
|
||||
replays,
|
||||
meta
|
||||
}
|
||||
meta,
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
}
|
||||
|
||||
async index({ request, response }: HttpContext) {
|
||||
const { statsPeriod, start, end } = request.qs()
|
||||
|
||||
let queryString: string = '?statsPeriod=24h'// Default in case none is provided
|
||||
let queryString: string = '?statsPeriod=24h' // Default in case none is provided
|
||||
if (statsPeriod) {
|
||||
queryString = `?statsPeriod=${statsPeriod}`
|
||||
} else if (start && end) {
|
||||
@ -82,25 +82,28 @@ export default class ReplaysController {
|
||||
|
||||
return response.json({ version: queryResults.latestVersion, ...queryResults })
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
function buildPaginationLinks(meta: { previousPageUrl: string, lastPage: number; currentPage: number; nextPageUrl: string }) {
|
||||
function buildPaginationLinks(meta: {
|
||||
previousPageUrl: string
|
||||
lastPage: number
|
||||
currentPage: number
|
||||
nextPageUrl: string
|
||||
}) {
|
||||
const links = []
|
||||
|
||||
// Previous
|
||||
links.push({
|
||||
url: meta.previousPageUrl,
|
||||
label: '« Prev',
|
||||
active: false
|
||||
active: false,
|
||||
})
|
||||
|
||||
for (let page = 1; page <= meta.lastPage; page++) {
|
||||
links.push({
|
||||
url: `/list?page=${page}`,
|
||||
label: page.toString(),
|
||||
active: page === meta.currentPage
|
||||
active: page === meta.currentPage,
|
||||
})
|
||||
}
|
||||
|
||||
@ -108,7 +111,7 @@ function buildPaginationLinks(meta: { previousPageUrl: string, lastPage: number;
|
||||
links.push({
|
||||
url: meta.nextPageUrl,
|
||||
label: 'Next »',
|
||||
active: false
|
||||
active: false,
|
||||
})
|
||||
|
||||
return links
|
||||
|
Reference in New Issue
Block a user