mirror of
https://github.com/ArthurDanjou/artdanj-api.git
synced 2026-01-27 10:00:27 +01:00
Simplify code with Lucid
This commit is contained in:
@@ -17,19 +17,13 @@ export async function getDevelopmentHours(start: Date, end: Date): Promise<numbe
|
|||||||
.where('date', '>=', start)
|
.where('date', '>=', start)
|
||||||
.where('date', '<=', end)
|
.where('date', '<=', end)
|
||||||
.orderBy('date', 'desc')
|
.orderBy('date', 'desc')
|
||||||
|
.first()
|
||||||
|
|
||||||
if (!development_seconds || development_seconds.length <= 0) {
|
if (!development_seconds) {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
const reduced = development_seconds.reduce((a: DevelopmentHour, b: DevelopmentHour) => {
|
return development_seconds.seconds
|
||||||
return {
|
|
||||||
...a,
|
|
||||||
seconds: a.seconds + b.seconds
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
return Number(reduced.seconds)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getCommandsRan(start: Date, end: Date): Promise<number> {
|
export async function getCommandsRan(start: Date, end: Date): Promise<number> {
|
||||||
@@ -38,19 +32,13 @@ export async function getCommandsRan(start: Date, end: Date): Promise<number> {
|
|||||||
.where('date', '>=', start)
|
.where('date', '>=', start)
|
||||||
.where('date', '<=', end)
|
.where('date', '<=', end)
|
||||||
.orderBy('date', 'desc')
|
.orderBy('date', 'desc')
|
||||||
|
.first()
|
||||||
|
|
||||||
if (!commands_run || commands_run.length <= 0) {
|
if (!commands_run) {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
const reduced = commands_run.reduce((a: CommandsRun, b: CommandsRun) => {
|
return commands_run.commands
|
||||||
return {
|
|
||||||
...a,
|
|
||||||
commands: a.commands + b.commands
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
return Number(reduced.commands)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getBuildsRan(start: Date, end: Date): Promise<number> {
|
export async function getBuildsRan(start: Date, end: Date): Promise<number> {
|
||||||
@@ -59,19 +47,13 @@ export async function getBuildsRan(start: Date, end: Date): Promise<number> {
|
|||||||
.where('date', '>=', start)
|
.where('date', '>=', start)
|
||||||
.where('date', '<=', end)
|
.where('date', '<=', end)
|
||||||
.orderBy('date', 'desc')
|
.orderBy('date', 'desc')
|
||||||
|
.first()
|
||||||
|
|
||||||
if (!builds_run || builds_run.length <= 0) {
|
if (!builds_run) {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
const reduced = builds_run.reduce((a: BuildsRun, b: BuildsRun) => {
|
return builds_run.builds
|
||||||
return {
|
|
||||||
...a,
|
|
||||||
builds: a.builds + b.builds
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
return Number(reduced.builds)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function fetchStatistics(): Promise<Stats> {
|
export async function fetchStatistics(): Promise<Stats> {
|
||||||
|
|||||||
Reference in New Issue
Block a user