Files
speckle-server/packages/server/test/speckle-helpers/activityStreamHelper.ts
T
2022-09-06 11:10:38 +03:00

25 lines
641 B
TypeScript

import { StreamActivityRecord } from '@/modules/activitystream/helpers/types'
import { StreamActivity } from '@/modules/core/dbSchema'
export async function getStreamActivities(
streamId: string,
extraFilters: Partial<{ actionType: string; userId: string }> = {}
): Promise<StreamActivityRecord[]> {
const { actionType, userId } = extraFilters
const q = StreamActivity.knex<StreamActivityRecord[]>().where(
StreamActivity.col.streamId,
streamId
)
if (actionType) {
q.andWhere(StreamActivity.col.actionType, actionType)
}
if (userId) {
q.andWhere(StreamActivity.col.userId, userId)
}
return await q
}