chore(server): stats IoC 6 - getCommitHistoryFactory

This commit is contained in:
Kristaps Fabians Geikins
2024-09-10 15:06:42 +03:00
parent f59916f4cc
commit 6ff39dde82
3 changed files with 6 additions and 6 deletions
@@ -3,7 +3,7 @@ import { Resolvers } from '@/modules/core/graph/generated/graphql'
import { validateScopes } from '@/modules/shared'
import {
getStreamHistoryFactory,
getCommitHistory,
getCommitHistoryFactory,
getObjectHistory,
getUserHistory,
getTotalStreamCountFactory,
@@ -49,7 +49,7 @@ export = {
},
async commitHistory() {
return await getCommitHistory()
return await getCommitHistoryFactory({ db })()
},
async objectHistory() {
@@ -45,7 +45,7 @@ export const getStreamHistoryFactory = (deps: { db: Knex }) => async () => {
return result.rows
}
export async function getCommitHistory() {
export const getCommitHistoryFactory = (deps: { db: Knex }) => async () => {
const query = `
SELECT
DATE_TRUNC('month', commits. "createdAt") AS created_month,
@@ -55,7 +55,7 @@ export async function getCommitHistory() {
GROUP BY
DATE_TRUNC('month', commits. "createdAt")
`
const result = (await knex.raw(query)) as {
const result = (await deps.db.raw(query)) as {
rows: Array<{ created_month: Date; count: string | number }>
}
result.rows.forEach((row) => (row.count = parseInt(row.count + '')))
@@ -11,7 +11,7 @@ import { createManyObjects } from '@/test/helpers'
import {
getStreamHistoryFactory,
getCommitHistory,
getCommitHistoryFactory,
getObjectHistory,
getUserHistory,
getTotalStreamCountFactory,
@@ -63,7 +63,7 @@ describe('Server stats services @stats-services', function () {
})
it('should return the commit creation history by month', async () => {
const res = await getCommitHistory()
const res = await getCommitHistoryFactory({ db })()
expect(res).to.be.an('array')
expect(res[0]).to.have.property('count')
expect(res[0]).to.have.property('created_month')