mirror of
https://github.com/ArthurDanjou/artdanj-api.git
synced 2026-01-14 12:14:33 +01:00
Remove Discord Activity route
This commit is contained in:
@@ -1,10 +1,67 @@
|
||||
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||
import {
|
||||
fetchDailyStatistics,
|
||||
fetchMonthlyStatistics,
|
||||
fetchStatistics,
|
||||
fetchWeeklyStatistics
|
||||
} from "App/Tasks/DevelopmentHoursTask";
|
||||
import CommandsRun from "App/Models/CommandsRun";
|
||||
import {DateTime} from "luxon";
|
||||
import BuildsRun from "App/Models/BuildsRun";
|
||||
|
||||
export default class StatsController {
|
||||
|
||||
public async index ({ response }: HttpContextContract) {
|
||||
const daily = await fetchDailyStatistics()
|
||||
const weekly = await fetchWeeklyStatistics()
|
||||
const monthly = await fetchMonthlyStatistics()
|
||||
const total = await fetchStatistics()
|
||||
|
||||
return response.status(200).send({
|
||||
message: 'Stats is under maintenance! Come back later.'
|
||||
daily,
|
||||
weekly,
|
||||
monthly,
|
||||
total
|
||||
})
|
||||
}
|
||||
|
||||
public async incrementCommandCount({ response }: HttpContextContract) {
|
||||
const current_date = DateTime.fromJSDate(new Date(new Date().setUTCMinutes(0, 0, 0)))
|
||||
const current_commands = await CommandsRun.firstOrCreate(
|
||||
{
|
||||
date: current_date
|
||||
},
|
||||
{
|
||||
date: current_date,
|
||||
commands: 0
|
||||
}
|
||||
)
|
||||
|
||||
current_commands.commands++
|
||||
await current_commands.save()
|
||||
|
||||
return response.status(200).send({
|
||||
message: 'Commands Count successfully incremented !'
|
||||
})
|
||||
}
|
||||
|
||||
public async incrementBuildCount({ response }: HttpContextContract) {
|
||||
const current_date = DateTime.fromJSDate(new Date(new Date().setUTCMinutes(0, 0, 0)))
|
||||
const current_builds = await BuildsRun.firstOrCreate(
|
||||
{
|
||||
date: current_date
|
||||
},
|
||||
{
|
||||
date: current_date,
|
||||
builds: 0
|
||||
}
|
||||
)
|
||||
|
||||
current_builds.builds++
|
||||
await current_builds.save()
|
||||
|
||||
return response.status(200).send({
|
||||
message: 'Builds Count successfully incremented !'
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import Route from "@ioc:Adonis/Core/Route";
|
||||
import Application from "@ioc:Adonis/Core/Application";
|
||||
|
||||
Route.get('/discord', 'ProfileController.discord')
|
||||
Route.get('/me', 'ProfileController.me')
|
||||
Route.get('/stats', 'StatsController.index')
|
||||
Route.get('/states', 'StatesController.index')
|
||||
Route.resource('/locations', 'LocationsController').only(['index', 'store'])
|
||||
|
||||
Route.group(() => {
|
||||
@@ -13,7 +13,17 @@ Route.group(() => {
|
||||
|
||||
Route.resource('/files', 'FilesController').only(['index', 'store', 'destroy'])
|
||||
|
||||
}).middleware('auth')
|
||||
Route.group(() => {
|
||||
Route.post('/sleeping', 'StatesController.setSleeping')
|
||||
Route.post('/developing', 'StatesController.setDeveloping')
|
||||
}).prefix('states')
|
||||
|
||||
Route.group(() => {
|
||||
Route.post('/commands', 'StatsController.incrementCommandCount')
|
||||
Route.post('/docker', 'StatsController.incrementBuildCount')
|
||||
}).prefix('stats')
|
||||
|
||||
}).middleware('auth:web,api')
|
||||
|
||||
Route.get('/files/:filename', async ({response, params}) => {
|
||||
response.download(Application.makePath('storage', params.filename))
|
||||
|
||||
@@ -10,10 +10,11 @@ Route.get('/', async ({response}: HttpContextContract) => {
|
||||
domain: BASE_URL,
|
||||
version: Env.get('API_VERSION'),
|
||||
source: `${BASE_URL}/source`,
|
||||
healthCheck: `${BASE_URL}/health`,
|
||||
health: `${BASE_URL}/health`,
|
||||
routes: {
|
||||
profile: `${BASE_URL}/me`,
|
||||
stats: `${BASE_URL}/stats`,
|
||||
states: `${BASE_URL}/states`,
|
||||
locations: `${BASE_URL}/locations`
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user