@@ -51,6 +51,45 @@ const getAllComplianceChecks = knex => async () => {
51
51
return knex ( 'compliance_checks' ) . select ( ) . returning ( '*' )
52
52
}
53
53
54
+ const getCheckByCodeName = knex => async ( codeName ) => {
55
+ debug ( `Getting check by code name (${ codeName } )...` )
56
+ return knex ( 'compliance_checks' ) . where ( { code_name : codeName } ) . first ( )
57
+ }
58
+
59
+ const getAllProjects = knex => async ( ) => {
60
+ debug ( 'Getting all projects...' )
61
+ return knex ( 'projects' ) . select ( ) . returning ( '*' )
62
+ }
63
+
64
+ const deleteAlertsByComplianceCheckId = knex => async ( complianceCheckId ) => {
65
+ debug ( `Deleting alerts by compliance_check_id (${ complianceCheckId } )...` )
66
+ return knex ( 'compliance_checks_alerts' ) . where ( { compliance_check_id : complianceCheckId } ) . delete ( )
67
+ }
68
+
69
+ const deleteTasksByComplianceCheckId = knex => async ( complianceCheckId ) => {
70
+ debug ( `Deleting tasks by compliance_check_id (${ complianceCheckId } )...` )
71
+ return knex ( 'compliance_checks_tasks' ) . where ( { compliance_check_id : complianceCheckId } ) . delete ( )
72
+ }
73
+
74
+ const addAlert = knex => async ( alert ) => {
75
+ debug ( 'Inserting alert...' )
76
+ return knex ( 'compliance_checks_alerts' ) . insert ( alert ) . returning ( '*' )
77
+ }
78
+
79
+ const addTask = knex => async ( task ) => {
80
+ debug ( 'Inserting task...' )
81
+ return knex ( 'compliance_checks_tasks' ) . insert ( task ) . returning ( '*' )
82
+ }
83
+
84
+ const upsertComplianceCheckResult = knex => async ( result ) => {
85
+ const existingComplianceCheck = await knex ( 'compliance_checks_results' ) . where ( { compliance_check_id : result . compliance_check_id } ) . first ( )
86
+ if ( existingComplianceCheck ) {
87
+ return knex ( 'compliance_checks_results' ) . where ( { compliance_check_id : result . compliance_check_id } ) . update ( result ) . returning ( '*' )
88
+ } else {
89
+ return knex ( 'compliance_checks_results' ) . insert ( result ) . returning ( '*' )
90
+ }
91
+ }
92
+
54
93
const initializeStore = ( knex ) => {
55
94
debug ( 'Initializing store...' )
56
95
return {
@@ -59,7 +98,14 @@ const initializeStore = (knex) => {
59
98
getAllGithubOrganizations : getAllGithubOrganizations ( knex ) ,
60
99
updateGithubOrganization : updateGithubOrganization ( knex ) ,
61
100
upsertGithubRepository : upsertGithubRepository ( knex ) ,
62
- getAllComplianceChecks : getAllComplianceChecks ( knex )
101
+ getAllComplianceChecks : getAllComplianceChecks ( knex ) ,
102
+ getCheckByCodeName : getCheckByCodeName ( knex ) ,
103
+ getAllProjects : getAllProjects ( knex ) ,
104
+ deleteTasksByComplianceCheckId : deleteTasksByComplianceCheckId ( knex ) ,
105
+ deleteAlertsByComplianceCheckId : deleteAlertsByComplianceCheckId ( knex ) ,
106
+ addAlert : addAlert ( knex ) ,
107
+ addTask : addTask ( knex ) ,
108
+ upsertComplianceCheckResult : upsertComplianceCheckResult ( knex )
63
109
}
64
110
}
65
111
0 commit comments