mirror of
https://github.com/ArthurDanjou/artdanj-api.git
synced 2026-01-21 15:31:35 +01:00
working
This commit is contained in:
31
app/Controllers/Http/LocationsController.ts
Normal file
31
app/Controllers/Http/LocationsController.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||
import Location from "App/Models/Location";
|
||||
import StoreValidator from "App/Validators/locations/StoreValidator";
|
||||
|
||||
export default class LocationsController {
|
||||
|
||||
public async get ({ response }: HttpContextContract) {
|
||||
const location = await Location.query().orderBy('since', 'desc').firstOrFail()
|
||||
return response.status(200).send({
|
||||
place: location.place,
|
||||
left: location.left,
|
||||
since: location.since
|
||||
})
|
||||
}
|
||||
|
||||
public async history ({ response }: HttpContextContract) {
|
||||
const locations = await Location.query().orderBy('since', 'desc')
|
||||
return response.status(200).send({
|
||||
locations
|
||||
})
|
||||
}
|
||||
|
||||
public async set ({ request, response }: HttpContextContract) {
|
||||
const data = await request.validate(StoreValidator)
|
||||
await Location.create(data)
|
||||
return response.status(200).send({
|
||||
message: 'Location successfully added !'
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,31 +1,44 @@
|
||||
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||
import {getTotalStats, getWeeklyStats, getMonthlyStats, getOtherStats} from 'App/Helpers/StatsHelper'
|
||||
import DockerBuild from "App/Models/DockerBuild";
|
||||
import DockerCommand from "App/Models/DockerCommand";
|
||||
|
||||
export default class StatsController {
|
||||
|
||||
public async get ({response}: HttpContextContract) {
|
||||
return response.status(200).send({
|
||||
daily: this.getDailyStats(),
|
||||
weekly: this.getWeeklyStats(),
|
||||
monthly: this.getMontlyStats()
|
||||
weekly: getWeeklyStats(),
|
||||
monthly: getMonthlyStats(),
|
||||
total: getTotalStats(),
|
||||
other : getOtherStats()
|
||||
})
|
||||
}
|
||||
|
||||
getDailyStats() {
|
||||
return {
|
||||
development_hours: 0
|
||||
public async incrementBuild () {
|
||||
const date = new Date()
|
||||
const last_entry = await DockerBuild.findBy('created_at', date)
|
||||
|
||||
if (last_entry) {
|
||||
last_entry.builds = last_entry.builds ++
|
||||
await last_entry.save()
|
||||
} else {
|
||||
await DockerBuild.create({
|
||||
builds: BigInt(1)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
getWeeklyStats() {
|
||||
return {
|
||||
development_hours: 0
|
||||
}
|
||||
}
|
||||
public async incrementCommand () {
|
||||
const date = new Date()
|
||||
const last_entry = await DockerCommand.findBy('created_at', date)
|
||||
|
||||
getMontlyStats() {
|
||||
|
||||
return {
|
||||
development_hours: 0
|
||||
if (last_entry) {
|
||||
last_entry.commands = last_entry.commands ++
|
||||
await last_entry.save()
|
||||
} else {
|
||||
await DockerCommand.create({
|
||||
commands: BigInt(1)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user