Files
speckle-server/packages/server/modules/automate/services/tracking.ts
T
Kristaps Fabians Geikins 4b06f42db7 chore(server): run TS files directly (no compilation) (#5134)
* sort of works

* type fixes

* added option to run old way too
2025-07-23 11:20:40 +02:00

45 lines
1.5 KiB
TypeScript

import type {
GetFullAutomationRevisionMetadata,
GetFullAutomationRunById
} from '@/modules/automate/domain/operations'
import type { InsertableAutomationRun } from '@/modules/automate/repositories/automations'
import type { GetCommit } from '@/modules/core/domain/commits/operations'
import type { LegacyGetUser } from '@/modules/core/domain/users/operations'
import { CommitNotFoundError } from '@/modules/core/errors/commit'
import { throwUncoveredError } from '@speckle/shared'
export type AutomateTrackingDeps = {
getFullAutomationRevisionMetadata: GetFullAutomationRevisionMetadata
getFullAutomationRunById: GetFullAutomationRunById
getCommit: GetCommit
getUser: LegacyGetUser
}
export const getUserEmailFromAutomationRunFactory =
(deps: AutomateTrackingDeps) =>
async (
automationRun: Pick<InsertableAutomationRun, 'triggers'>,
projectId: string
): Promise<string | undefined> => {
let userEmail: string | undefined = undefined
const trigger = automationRun.triggers[0]
switch (trigger.triggerType) {
case 'versionCreation': {
const version = await deps.getCommit(trigger.triggeringId, {
streamId: projectId
})
if (!version) throw new CommitNotFoundError("Version doesn't exist any more")
const userId = version.author
if (userId) {
const user = await deps.getUser(userId)
if (user) userEmail = user.email
}
break
}
default:
throwUncoveredError(trigger.triggerType)
}
return userEmail
}