@@ -12,7 +12,7 @@ const SIX_MONTHS_MS = 6 * 30 * 24 * 60 * 60 * 1000;
1212const TRAINING_VIDEO_IDS = [ 'sat-1' , 'sat-2' , 'sat-3' , 'sat-4' , 'sat-5' ] ;
1313
1414export async function getOverviewScores ( organizationId : string ) {
15- const [ allPolicies , allTasks , employees , onboarding ] = await Promise . all ( [
15+ const [ allPolicies , allTasks , employees , onboarding , org ] = await Promise . all ( [
1616 db . policy . findMany ( { where : { organizationId } } ) ,
1717 db . task . findMany ( { where : { organizationId } } ) ,
1818 db . member . findMany ( {
@@ -23,8 +23,14 @@ export async function getOverviewScores(organizationId: string) {
2323 where : { organizationId } ,
2424 select : { triggerJobId : true } ,
2525 } ) ,
26+ db . organization . findUnique ( {
27+ where : { id : organizationId } ,
28+ select : { securityTrainingStepEnabled : true } ,
29+ } ) ,
2630 ] ) ;
2731
32+ const securityTrainingStepEnabled = org ?. securityTrainingStepEnabled === true ;
33+
2834 // Policy breakdown
2935 const publishedPolicies = allPolicies . filter ( ( p ) => p . status === 'published' ) ;
3036 const draftPolicies = allPolicies . filter ( ( p ) => p . status === 'draft' ) ;
@@ -54,25 +60,30 @@ export async function getOverviewScores(organizationId: string) {
5460 p . isRequiredToSign && p . status === 'published' && ! p . isArchived ,
5561 ) ;
5662
57- const trainingCompletions =
58- await db . employeeTrainingVideoCompletion . findMany ( {
59- where : { memberId : { in : activeEmployees . map ( ( e ) => e . id ) } } ,
60- } ) ;
63+ const trainingCompletions = securityTrainingStepEnabled
64+ ? await db . employeeTrainingVideoCompletion . findMany ( {
65+ where : { memberId : { in : activeEmployees . map ( ( e ) => e . id ) } } ,
66+ } )
67+ : [ ] ;
6168
6269 for ( const emp of activeEmployees ) {
6370 const hasAcceptedAllPolicies =
6471 requiredPolicies . length === 0 ||
6572 requiredPolicies . every ( ( p ) => p . signedBy . includes ( emp . id ) ) ;
6673
67- const empCompletions = trainingCompletions . filter (
68- ( c ) => c . memberId === emp . id ,
69- ) ;
70- const completedVideoIds = empCompletions
71- . filter ( ( c ) => c . completedAt !== null )
72- . map ( ( c ) => c . videoId ) ;
73- const hasCompletedAllTraining = TRAINING_VIDEO_IDS . every ( ( vid ) =>
74- completedVideoIds . includes ( vid ) ,
75- ) ;
74+ const hasCompletedAllTraining = securityTrainingStepEnabled
75+ ? ( ( ) => {
76+ const empCompletions = trainingCompletions . filter (
77+ ( c ) => c . memberId === emp . id ,
78+ ) ;
79+ const completedVideoIds = empCompletions
80+ . filter ( ( c ) => c . completedAt !== null )
81+ . map ( ( c ) => c . videoId ) ;
82+ return TRAINING_VIDEO_IDS . every ( ( vid ) =>
83+ completedVideoIds . includes ( vid ) ,
84+ ) ;
85+ } ) ( )
86+ : true ;
7687
7788 if ( hasAcceptedAllPolicies && hasCompletedAllTraining ) {
7889 completedMembers ++ ;
0 commit comments