Merge pull request #2924 from specklesystems/fabians/stats-ioc-3

chore(server): stats IoC 3 - getTotalObjectCountFactory
This commit is contained in:
Alessandro Magionami
2024-09-11 09:52:11 +02:00
committed by GitHub
3 changed files with 6 additions and 6 deletions
@@ -8,7 +8,7 @@ import {
getUserHistory,
getTotalStreamCountFactory,
getTotalCommitCountFactory,
getTotalObjectCount,
getTotalObjectCountFactory,
getTotalUserCount
} from '@/modules/stats/repositories/index'
import { Roles, Scopes } from '@speckle/shared'
@@ -37,7 +37,7 @@ export = {
},
async totalObjectCount() {
return await getTotalObjectCount()
return await getTotalObjectCountFactory({ db })()
},
async totalUserCount() {
@@ -13,9 +13,9 @@ export const getTotalCommitCountFactory = (deps: { db: Knex }) => async () => {
return parseInt(result.rows[0].count)
}
export async function getTotalObjectCount() {
export const getTotalObjectCountFactory = (deps: { db: Knex }) => async () => {
const query = 'SELECT COUNT(*) FROM objects'
const result = await knex.raw(query)
const result = await deps.db.raw(query)
return parseInt(result.rows[0].count)
}
@@ -16,7 +16,7 @@ import {
getUserHistory,
getTotalStreamCountFactory,
getTotalCommitCountFactory,
getTotalObjectCount,
getTotalObjectCountFactory,
getTotalUserCount
} from '@/modules/stats/repositories/index'
import { Scopes } from '@speckle/shared'
@@ -49,7 +49,7 @@ describe('Server stats services @stats-services', function () {
})
it('should return the total number of objects on this server', async () => {
const res = await getTotalObjectCount()
const res = await getTotalObjectCountFactory({ db })()
expect(res).to.equal(params.numObjects)
})