1
1
const resetDatabase = async ( knex ) => {
2
+ await knex . raw ( 'TRUNCATE TABLE compliance_checks_results RESTART IDENTITY CASCADE' )
3
+ await knex . raw ( 'TRUNCATE TABLE compliance_checks_tasks RESTART IDENTITY CASCADE' )
4
+ await knex . raw ( 'TRUNCATE TABLE compliance_checks_alerts RESTART IDENTITY CASCADE' )
2
5
await knex . raw ( 'TRUNCATE TABLE github_repositories RESTART IDENTITY CASCADE' )
3
6
await knex . raw ( 'TRUNCATE TABLE github_organizations RESTART IDENTITY CASCADE' )
4
7
await knex . raw ( 'TRUNCATE TABLE projects RESTART IDENTITY CASCADE' )
@@ -23,7 +26,29 @@ const addGithubRepo = async (knex, data) => {
23
26
return githubRepo
24
27
}
25
28
29
+ const getAllResults = ( knex ) => knex ( 'compliance_checks_results' ) . select ( '*' )
30
+ const getAllTasks = ( knex ) => knex ( 'compliance_checks_tasks' ) . select ( '*' )
31
+ const getAllAlerts = ( knex ) => knex ( 'compliance_checks_alerts' ) . select ( '*' )
32
+ const addAlert = async ( knex , alert ) => {
33
+ const [ newAlert ] = await knex ( 'compliance_checks_alerts' ) . insert ( alert ) . returning ( '*' )
34
+ return newAlert
35
+ }
36
+
37
+ const addTask = async ( knex , task ) => {
38
+ const [ newTask ] = await knex ( 'compliance_checks_tasks' ) . insert ( task ) . returning ( '*' )
39
+ return newTask
40
+ }
41
+
42
+ const addResult = async ( knex , result ) => {
43
+ const [ newResult ] = await knex ( 'compliance_checks_results' ) . insert ( result ) . returning ( '*' )
44
+ return newResult
45
+ }
46
+
26
47
const getAllComplianceChecks = ( knex ) => knex ( 'compliance_checks' ) . select ( '*' )
48
+ const getCheckByCodeName = async ( knex , codeName ) => {
49
+ const check = await knex ( 'compliance_checks' ) . where ( { code_name : codeName } ) . first ( )
50
+ return check
51
+ }
27
52
28
53
module . exports = {
29
54
getAllComplianceChecks,
@@ -33,5 +58,12 @@ module.exports = {
33
58
addProject,
34
59
addGithubOrg,
35
60
getAllGithubRepos,
36
- addGithubRepo
61
+ addGithubRepo,
62
+ getAllResults,
63
+ getAllTasks,
64
+ getAllAlerts,
65
+ addAlert,
66
+ addTask,
67
+ addResult,
68
+ getCheckByCodeName
37
69
}
0 commit comments