bde148f286
* wip * some extra fixes * stuff kinda works? * need to figure out mocks * need to figure out mocks * fix db listener * gqlgen fix * minor gqlgen watch adjustment * lint fixes * delete old codegen file * converting migrations to ESM * getModuleDIrectory * vitest sort of works * added back ts-vitest * resolve gql double load * fixing test timeout configs * TSC lint fix * fix automate tests * moar debugging * debugging * more debugging * codegen update * server works * yargs migrated * chore(server): getting rid of global mocks for Server ESM (#5046) * got rid of email mock * got rid of comment mocks * got rid of multi region mocks * got rid of stripe mock * admin override mock updated * removed final mock * fixing import.meta.resolve calls * another import.meta.resolve fix * added requested test * nyc ESM fix * removed unneeded deps + linting * yarn lock forgot to commit * tryna fix flakyness * email capture util fix * sendEmail fix * fix TSX check * sender transporter fix + CR comments * merge main fix * test fixx * circleci fix * gqlgen bigint fix * error formatter fix * more error formatting improvements * esmloader added to Dockerfile * more dockerfile fixes * bg jobs fix
93 lines
3.2 KiB
TypeScript
93 lines
3.2 KiB
TypeScript
import { Optional } from '@speckle/shared'
|
|
import { isUndefined } from 'lodash-es'
|
|
import {
|
|
GetPaginatedBranchCommentsFactory,
|
|
GetPaginatedBranchCommentsPage,
|
|
GetPaginatedBranchCommentsTotalCount,
|
|
GetPaginatedCommitComments,
|
|
GetPaginatedCommitCommentsPage,
|
|
GetPaginatedCommitCommentsTotalCount,
|
|
GetPaginatedProjectComments,
|
|
GetPaginatedProjectCommentsPage,
|
|
GetPaginatedProjectCommentsTotalCount,
|
|
PaginatedBranchCommentsParams,
|
|
PaginatedCommitCommentsParams,
|
|
PaginatedProjectCommentsParams,
|
|
ResolvePaginatedProjectCommentsLatestModelResources
|
|
} from '@/modules/comments/domain/operations'
|
|
import { BranchLatestCommit } from '@/modules/core/domain/commits/types'
|
|
|
|
export const getPaginatedCommitCommentsFactory =
|
|
(deps: {
|
|
getPaginatedCommitCommentsPage: GetPaginatedCommitCommentsPage
|
|
getPaginatedCommitCommentsTotalCount: GetPaginatedCommitCommentsTotalCount
|
|
}): GetPaginatedCommitComments =>
|
|
async (params: PaginatedCommitCommentsParams) => {
|
|
const [result, totalCount] = await Promise.all([
|
|
deps.getPaginatedCommitCommentsPage(params),
|
|
deps.getPaginatedCommitCommentsTotalCount(params)
|
|
])
|
|
|
|
return {
|
|
...result,
|
|
totalCount
|
|
}
|
|
}
|
|
|
|
export const getPaginatedBranchCommentsFactory =
|
|
(deps: {
|
|
getPaginatedBranchCommentsPage: GetPaginatedBranchCommentsPage
|
|
getPaginatedBranchCommentsTotalCount: GetPaginatedBranchCommentsTotalCount
|
|
}): GetPaginatedBranchCommentsFactory =>
|
|
async (params: PaginatedBranchCommentsParams) => {
|
|
const [result, totalCount] = await Promise.all([
|
|
deps.getPaginatedBranchCommentsPage(params),
|
|
deps.getPaginatedBranchCommentsTotalCount(params)
|
|
])
|
|
|
|
return {
|
|
...result,
|
|
totalCount
|
|
}
|
|
}
|
|
|
|
export const getPaginatedProjectCommentsFactory =
|
|
(deps: {
|
|
resolvePaginatedProjectCommentsLatestModelResources: ResolvePaginatedProjectCommentsLatestModelResources
|
|
getPaginatedProjectCommentsPage: GetPaginatedProjectCommentsPage
|
|
getPaginatedProjectCommentsTotalCount: GetPaginatedProjectCommentsTotalCount
|
|
}): GetPaginatedProjectComments =>
|
|
async (params: PaginatedProjectCommentsParams) => {
|
|
let preloadedModelLatestVersions: Optional<BranchLatestCommit[]> = undefined
|
|
// optimization to ensure we don't request this stuff twice
|
|
if (!params.filter?.allModelVersions && params.filter?.resourceIdString) {
|
|
preloadedModelLatestVersions =
|
|
await deps.resolvePaginatedProjectCommentsLatestModelResources(
|
|
params.filter.resourceIdString
|
|
)
|
|
}
|
|
|
|
const alreadyRequestingArchivedOnly = !!params.filter?.archivedOnly
|
|
|
|
const [result, totalCount, totalArchivedCount] = await Promise.all([
|
|
deps.getPaginatedProjectCommentsPage(params, { preloadedModelLatestVersions }),
|
|
deps.getPaginatedProjectCommentsTotalCount(params, {
|
|
preloadedModelLatestVersions
|
|
}),
|
|
alreadyRequestingArchivedOnly
|
|
? undefined
|
|
: deps.getPaginatedProjectCommentsTotalCount(
|
|
{ ...params, filter: { ...(params.filter || {}), archivedOnly: true } },
|
|
{ preloadedModelLatestVersions }
|
|
)
|
|
])
|
|
|
|
return {
|
|
...result,
|
|
totalCount,
|
|
totalArchivedCount: isUndefined(totalArchivedCount)
|
|
? totalCount
|
|
: totalArchivedCount
|
|
}
|
|
}
|