Files
speckle-server/packages/server/modules/core/services/branches.js
T
2024-09-27 13:52:41 +03:00

31 lines
870 B
JavaScript

'use strict'
const knex = require('@/db/knex')
const { getStreamBranchCountFactory } = require('@/modules/core/repositories/branches')
const Branches = () => knex('branches')
module.exports = {
/**
* @returns {Promise<{
* items: import('@/modules/core/helpers/types').BranchRecord[],
* cursor: string | null,
* totalCount: number
* }>}
*/
async getBranchesByStreamId({ streamId, limit, cursor }) {
limit = limit || 25
const query = Branches().select('*').where({ streamId })
if (cursor) query.andWhere('createdAt', '>', cursor)
query.orderBy('createdAt').limit(limit)
const totalCount = await getStreamBranchCountFactory({ db: knex })(streamId)
const rows = await query
return {
items: rows,
cursor: rows.length > 0 ? rows[rows.length - 1].updatedAt.toISOString() : null,
totalCount
}
}
}