Merge pull request #3265 from specklesystems/fabians/core-ioc-47
chore(server): core IoC #47 - markBranchStreamUpdatedFactory
This commit is contained in:
@@ -182,6 +182,8 @@ export type GetUserStreamsCount = (
|
||||
params: UserStreamsQueryCountParams
|
||||
) => Promise<number>
|
||||
|
||||
export type MarkBranchStreamUpdated = (branchId: string) => Promise<boolean>
|
||||
|
||||
export type GetBatchUserFavoriteData = (params: {
|
||||
userId: string
|
||||
streamIds: string[]
|
||||
|
||||
@@ -33,8 +33,8 @@ const {
|
||||
addBranchDeletedActivity
|
||||
} = require('@/modules/activitystream/services/branchActivity')
|
||||
const {
|
||||
markBranchStreamUpdated,
|
||||
getStreamFactory
|
||||
getStreamFactory,
|
||||
markBranchStreamUpdatedFactory
|
||||
} = require('@/modules/core/repositories/streams')
|
||||
const { ModelsEmitter } = require('@/modules/core/events/modelsEmitter')
|
||||
|
||||
@@ -43,6 +43,7 @@ const BRANCH_CREATED = BranchPubsubEvents.BranchCreated
|
||||
const BRANCH_UPDATED = BranchPubsubEvents.BranchUpdated
|
||||
const BRANCH_DELETED = BranchPubsubEvents.BranchDeleted
|
||||
|
||||
const markBranchStreamUpdated = markBranchStreamUpdatedFactory({ db })
|
||||
const getStream = getStreamFactory({ db })
|
||||
const getBranchById = getBranchByIdFactory({ db })
|
||||
const getStreamBranchByName = getStreamBranchByNameFactory({ db })
|
||||
|
||||
@@ -54,10 +54,11 @@ import {
|
||||
} from '@/modules/activitystream/services/branchActivity'
|
||||
import {
|
||||
getStreamFactory,
|
||||
markBranchStreamUpdated
|
||||
markBranchStreamUpdatedFactory
|
||||
} from '@/modules/core/repositories/streams'
|
||||
import { ModelsEmitter } from '@/modules/core/events/modelsEmitter'
|
||||
|
||||
const markBranchStreamUpdated = markBranchStreamUpdatedFactory({ db })
|
||||
const getStream = getStreamFactory({ db })
|
||||
const getStreamObjects = getStreamObjectsFactory({ db })
|
||||
const getViewerResourceGroups = getViewerResourceGroupsFactory({
|
||||
|
||||
@@ -95,7 +95,8 @@ import {
|
||||
UserStreamsQueryParams,
|
||||
UserStreamsQueryCountParams,
|
||||
GetUserStreamsPage,
|
||||
GetUserStreamsCount
|
||||
GetUserStreamsCount,
|
||||
MarkBranchStreamUpdated
|
||||
} from '@/modules/core/domain/streams/operations'
|
||||
export type { StreamWithOptionalRole, StreamWithCommitId }
|
||||
|
||||
@@ -987,17 +988,20 @@ export const updateProjectFactory =
|
||||
return updatedStream
|
||||
}
|
||||
|
||||
export async function markBranchStreamUpdated(branchId: string) {
|
||||
const q = Streams.knex()
|
||||
.whereIn(Streams.col.id, (w) => {
|
||||
w.select(Branches.col.streamId)
|
||||
.from(Branches.name)
|
||||
.where(Branches.col.id, branchId)
|
||||
})
|
||||
.update(Streams.withoutTablePrefix.col.updatedAt, new Date())
|
||||
const updates = await q
|
||||
return updates > 0
|
||||
}
|
||||
export const markBranchStreamUpdatedFactory =
|
||||
(deps: { db: Knex }): MarkBranchStreamUpdated =>
|
||||
async (branchId: string) => {
|
||||
const q = tables
|
||||
.streams(deps.db)
|
||||
.whereIn(Streams.col.id, (w) => {
|
||||
w.select(Branches.col.streamId)
|
||||
.from(Branches.name)
|
||||
.where(Branches.col.id, branchId)
|
||||
})
|
||||
.update(Streams.withoutTablePrefix.col.updatedAt, new Date())
|
||||
const updates = await q
|
||||
return updates > 0
|
||||
}
|
||||
|
||||
export async function markCommitStreamUpdated(commitId: string) {
|
||||
const q = Streams.knex()
|
||||
|
||||
@@ -18,8 +18,6 @@ import {
|
||||
UpdateModelInput
|
||||
} from '@/modules/core/graph/generated/graphql'
|
||||
import { BranchRecord } from '@/modules/core/helpers/types'
|
||||
|
||||
import { markBranchStreamUpdated } from '@/modules/core/repositories/streams'
|
||||
import { has } from 'lodash'
|
||||
import { isBranchDeleteInput, isBranchUpdateInput } from '@/modules/core/helpers/branch'
|
||||
import { ModelsEmitter, ModelsEventsEmitter } from '@/modules/core/events/modelsEmitter'
|
||||
@@ -33,7 +31,10 @@ import {
|
||||
UpdateBranch,
|
||||
UpdateBranchAndNotify
|
||||
} from '@/modules/core/domain/branches/operations'
|
||||
import { GetStream } from '@/modules/core/domain/streams/operations'
|
||||
import {
|
||||
GetStream,
|
||||
MarkBranchStreamUpdated
|
||||
} from '@/modules/core/domain/streams/operations'
|
||||
|
||||
const isBranchCreateInput = (
|
||||
i: BranchCreateInput | CreateModelInput
|
||||
@@ -113,7 +114,7 @@ export const deleteBranchAndNotifyFactory =
|
||||
getStream: GetStream
|
||||
getBranchById: GetBranchById
|
||||
modelsEventsEmitter: ModelsEventsEmitter
|
||||
markBranchStreamUpdated: typeof markBranchStreamUpdated
|
||||
markBranchStreamUpdated: MarkBranchStreamUpdated
|
||||
addBranchDeletedActivity: typeof addBranchDeletedActivity
|
||||
deleteBranchById: DeleteBranchById
|
||||
}): DeleteBranchAndNotify =>
|
||||
|
||||
@@ -29,10 +29,10 @@ const {
|
||||
addBranchDeletedActivity
|
||||
} = require('@/modules/activitystream/services/branchActivity')
|
||||
const {
|
||||
markBranchStreamUpdated,
|
||||
markCommitStreamUpdated,
|
||||
getStreamFactory,
|
||||
createStreamFactory
|
||||
createStreamFactory,
|
||||
markBranchStreamUpdatedFactory
|
||||
} = require('@/modules/core/repositories/streams')
|
||||
const { ModelsEmitter } = require('@/modules/core/events/modelsEmitter')
|
||||
const {
|
||||
@@ -80,6 +80,8 @@ const {
|
||||
|
||||
const db = knex
|
||||
const Commits = () => knex('commits')
|
||||
|
||||
const markBranchStreamUpdated = markBranchStreamUpdatedFactory({ db })
|
||||
const getStream = getStreamFactory({ db: knex })
|
||||
const getBranchById = getBranchByIdFactory({ db: knex })
|
||||
const getStreamBranchByName = getStreamBranchByNameFactory({ db: knex })
|
||||
|
||||
@@ -21,7 +21,7 @@ import {
|
||||
getStreamFactory,
|
||||
grantStreamPermissionsFactory,
|
||||
legacyGetStreamUsersFactory,
|
||||
markBranchStreamUpdated,
|
||||
markBranchStreamUpdatedFactory,
|
||||
markCommitStreamUpdated,
|
||||
revokeStreamPermissionsFactory,
|
||||
updateStreamFactory
|
||||
@@ -96,6 +96,7 @@ import {
|
||||
} from '@/modules/core/services/streams/access'
|
||||
import { authorizeResolver } from '@/modules/shared'
|
||||
|
||||
const markBranchStreamUpdated = markBranchStreamUpdatedFactory({ db })
|
||||
const getStream = getStreamFactory({ db })
|
||||
const getStreamBranchByName = getStreamBranchByNameFactory({ db })
|
||||
const createBranch = createBranchFactory({ db })
|
||||
|
||||
Reference in New Issue
Block a user