chore(server): core IoC 13 - getCommit(s)Factory

This commit is contained in:
Kristaps Fabians Geikins
2024-09-27 14:02:29 +03:00
parent 9dbde37438
commit 972af78fce
12 changed files with 95 additions and 63 deletions
@@ -20,7 +20,7 @@ import {
} from '@/modules/core/repositories/branches'
import {
deleteCommits,
getCommits,
getCommitsFactory,
moveCommitsToBranch
} from '@/modules/core/repositories/commits'
import { getStreams } from '@/modules/core/repositories/streams'
@@ -48,7 +48,7 @@ async function validateBatchBaseRules(params: CommitBatchInput, userId: string)
throw new CommitBatchUpdateError('No commits specified')
}
const commits = await getCommits(commitIds)
const commits = await getCommitsFactory({ db })(commitIds)
const foundCommitIds = commits.map((c) => c.id)
if (
commitIds.length !== foundCommitIds.length ||
@@ -27,8 +27,8 @@ import {
import {
createCommit,
deleteCommit,
getCommit,
getCommitBranch,
getCommitFactory,
insertBranchCommits,
insertStreamCommits,
switchCommitBranch,
@@ -58,7 +58,9 @@ export async function markCommitReceivedAndNotify(params: {
}
: input
const commit = await getCommit(oldInput.commitId, { streamId: oldInput.streamId })
const commit = await getCommitFactory({ db })(oldInput.commitId, {
streamId: oldInput.streamId
})
if (!commit) {
throw new CommitReceiveError(
`Failed to find commit with id ${oldInput.commitId} in stream ${oldInput.streamId}.`,
@@ -247,7 +249,7 @@ export async function updateCommitAndNotify(
}
const [commit, stream] = await Promise.all([
getCommit(commitId),
getCommitFactory({ db })(commitId),
streamId ? getStream({ streamId, userId }) : getCommitStream({ commitId, userId })
])
if (!commit) {
@@ -321,7 +323,7 @@ export async function deleteCommitAndNotify(
streamId: string,
userId: string
) {
const commit = await getCommit(commitId)
const commit = await getCommitFactory({ db })(commitId)
if (!commit) {
throw new CommitDeleteError("Couldn't delete nonexistant commit", {
info: { commitId, streamId, userId }