@@ -12,7 +12,7 @@ import DashboardContentChangelog from '../../models/dashboard_content_changelog'
12
12
import DashboardContent from '../../models/dashboard_content' ;
13
13
import { DashboardContentChangelogService } from '../../services/dashboard_content_changelog.service' ;
14
14
import { FIXED_ROLE_TYPES } from '../../services/role.service' ;
15
- import { Repository } from 'typeorm' ;
15
+ import { QueryRunner , Repository } from 'typeorm' ;
16
16
import { ensureDirSync } from 'fs-extra' ;
17
17
18
18
type Source = {
@@ -32,11 +32,7 @@ async function upsert() {
32
32
const superadmin : Account = await queryRunner . manager
33
33
. getRepository ( Account )
34
34
. findOneByOrFail ( { role_id : FIXED_ROLE_TYPES . SUPERADMIN } ) ;
35
- const dashboardChangelogRepo = queryRunner . manager . getRepository ( DashboardChangelog ) ;
36
35
const dashboardRepo = queryRunner . manager . getRepository ( Dashboard ) ;
37
- const dashboardContentChangelogRepo = queryRunner . manager . getRepository ( DashboardContentChangelog ) ;
38
- const dashboardContentRepo = queryRunner . manager . getRepository ( DashboardContent ) ;
39
- const dashboardPermissionRepo = queryRunner . manager . getRepository ( DashboardPermission ) ;
40
36
const datasourceRepo = queryRunner . manager . getRepository ( DataSource ) ;
41
37
42
38
const basePath = path . join ( __dirname , '../dashboards' ) ;
@@ -48,16 +44,7 @@ async function upsert() {
48
44
const config : Record < string , any > = JSON . parse ( readFileSync ( path . join ( basePath , files [ i ] ) , 'utf-8' ) ) ;
49
45
await checkConfigForErrors ( datasourceRepo , config , errors ) ;
50
46
const name = dashboardNames [ i ] ;
51
- await upsertDashboard (
52
- dashboardRepo ,
53
- dashboardPermissionRepo ,
54
- dashboardContentRepo ,
55
- dashboardChangelogRepo ,
56
- dashboardContentChangelogRepo ,
57
- name ,
58
- config ,
59
- superadmin . id ,
60
- ) ;
47
+ await upsertDashboard ( queryRunner , name , config , superadmin . id ) ;
61
48
}
62
49
if ( ! _ . isEmpty ( errors ) ) {
63
50
throw new Error ( `Missing preset datasources: ${ JSON . stringify ( errors ) } ` ) ;
@@ -119,15 +106,16 @@ async function checkConfigForErrors(
119
106
}
120
107
121
108
async function upsertDashboard (
122
- dashboardRepo : Repository < Dashboard > ,
123
- dashboardPermissionRepo : Repository < DashboardPermission > ,
124
- dashboardContentRepo : Repository < DashboardContent > ,
125
- dashboardChangelogRepo : Repository < DashboardChangelog > ,
126
- dashboardContentChangelogRepo : Repository < DashboardContentChangelog > ,
109
+ queryRunner : QueryRunner ,
127
110
name : string ,
128
111
config : Record < string , any > ,
129
112
superadminId : string ,
130
113
) {
114
+ const dashboardChangelogRepo = queryRunner . manager . getRepository ( DashboardChangelog ) ;
115
+ const dashboardRepo = queryRunner . manager . getRepository ( Dashboard ) ;
116
+ const dashboardContentChangelogRepo = queryRunner . manager . getRepository ( DashboardContentChangelog ) ;
117
+ const dashboardContentRepo = queryRunner . manager . getRepository ( DashboardContent ) ;
118
+ const dashboardPermissionRepo = queryRunner . manager . getRepository ( DashboardPermission ) ;
131
119
let dashboard = await dashboardRepo . findOneBy ( { name, is_preset : true } ) ;
132
120
const originalDashboard : Dashboard | null = _ . cloneDeep ( dashboard ) ;
133
121
let isNew = false ;
0 commit comments