mirror of
https://github.com/hcengineering/platform.git
synced 2026-08-22 20:32:24 +02:00
28 lines
830 B
TypeScript
28 lines
830 B
TypeScript
//
|
|
// Copyright @ 2024 Hardcore Engineering Inc.
|
|
//
|
|
|
|
import {
|
|
type Training,
|
|
type TrainingAttempt,
|
|
TrainingAttemptState,
|
|
type TrainingRequest,
|
|
TrainingState
|
|
} from '@hcengineering/training'
|
|
import { getCurrentEmployeeRef } from './getCurrentEmployeeRef'
|
|
|
|
export function canCreateTrainingAttempt (
|
|
training: Training,
|
|
request: TrainingRequest,
|
|
latestOwnAttempt: TrainingAttempt | null
|
|
): boolean {
|
|
const currentEmployeeRef = getCurrentEmployeeRef()
|
|
return (
|
|
training.state === TrainingState.Released &&
|
|
request.canceledOn === null &&
|
|
request.trainees.includes(currentEmployeeRef) &&
|
|
(request.maxAttempts === null || latestOwnAttempt === null || latestOwnAttempt.seqNumber < request.maxAttempts) &&
|
|
(latestOwnAttempt === null || latestOwnAttempt.state === TrainingAttemptState.Failed)
|
|
)
|
|
}
|