@@ -85,6 +85,49 @@ export class ImportCredentialsCommand extends BaseCommand {
85
85
this . reportSuccess ( credentials . length ) ;
86
86
}
87
87
88
+ async catch ( error : Error ) {
89
+ this . logger . error (
90
+ 'An error occurred while importing credentials. See log messages for details.' ,
91
+ ) ;
92
+ this . logger . error ( error . message ) ;
93
+ }
94
+
95
+ private reportSuccess ( total : number ) {
96
+ this . logger . info (
97
+ `Successfully imported ${ total } ${ total === 1 ? 'credential.' : 'credentials.' } ` ,
98
+ ) ;
99
+ }
100
+
101
+ private async storeCredential ( credential : Partial < CredentialsEntity > , user : User ) {
102
+ const result = await this . transactionManager . upsert ( CredentialsEntity , credential , [ 'id' ] ) ;
103
+
104
+ const sharingExists = await this . transactionManager . existsBy ( SharedCredentials , {
105
+ credentialsId : credential . id ,
106
+ role : 'credential:owner' ,
107
+ } ) ;
108
+
109
+ if ( ! sharingExists ) {
110
+ await this . transactionManager . upsert (
111
+ SharedCredentials ,
112
+ {
113
+ credentialsId : result . identifiers [ 0 ] . id as string ,
114
+ userId : user . id ,
115
+ role : 'credential:owner' ,
116
+ } ,
117
+ [ 'credentialsId' , 'userId' ] ,
118
+ ) ;
119
+ }
120
+ }
121
+
122
+ private async getOwner ( ) {
123
+ const owner = await Container . get ( UserRepository ) . findOneBy ( { role : 'global:owner' } ) ;
124
+ if ( ! owner ) {
125
+ throw new ApplicationError ( `Failed to find owner. ${ UM_FIX_INSTRUCTION } ` ) ;
126
+ }
127
+
128
+ return owner ;
129
+ }
130
+
88
131
private async checkRelations ( credentials : ICredentialsEncrypted [ ] , userId ?: string ) {
89
132
if ( ! userId ) {
90
133
return {
@@ -163,49 +206,6 @@ export class ImportCredentialsCommand extends BaseCommand {
163
206
} ) ;
164
207
}
165
208
166
- async catch ( error : Error ) {
167
- this . logger . error (
168
- 'An error occurred while importing credentials. See log messages for details.' ,
169
- ) ;
170
- this . logger . error ( error . message ) ;
171
- }
172
-
173
- private reportSuccess ( total : number ) {
174
- this . logger . info (
175
- `Successfully imported ${ total } ${ total === 1 ? 'credential.' : 'credentials.' } ` ,
176
- ) ;
177
- }
178
-
179
- private async storeCredential ( credential : Partial < CredentialsEntity > , user : User ) {
180
- const result = await this . transactionManager . upsert ( CredentialsEntity , credential , [ 'id' ] ) ;
181
-
182
- const sharingExists = await this . transactionManager . existsBy ( SharedCredentials , {
183
- credentialsId : credential . id ,
184
- role : 'credential:owner' ,
185
- } ) ;
186
-
187
- if ( ! sharingExists ) {
188
- await this . transactionManager . upsert (
189
- SharedCredentials ,
190
- {
191
- credentialsId : result . identifiers [ 0 ] . id as string ,
192
- userId : user . id ,
193
- role : 'credential:owner' ,
194
- } ,
195
- [ 'credentialsId' , 'userId' ] ,
196
- ) ;
197
- }
198
- }
199
-
200
- private async getOwner ( ) {
201
- const owner = await Container . get ( UserRepository ) . findOneBy ( { role : 'global:owner' } ) ;
202
- if ( ! owner ) {
203
- throw new ApplicationError ( `Failed to find owner. ${ UM_FIX_INSTRUCTION } ` ) ;
204
- }
205
-
206
- return owner ;
207
- }
208
-
209
209
private async getAssignee ( userId : string ) {
210
210
const user = await Container . get ( UserRepository ) . findOneBy ( { id : userId } ) ;
211
211
0 commit comments