@@ -111,23 +111,33 @@ ipcMain.on('addApp', (message: IpcMainEvent, application: any) => {
111
111
112
112
/**
113
113
* @event addAwsApp
114
+ * @param name, 'AWS', region, description, typeOfService, instanceID, accessKey, secretAccessKey, awsURL
114
115
* @desc Adds an AWS application to the user's list in the settings.json with the provided fields
115
116
* @return New list of applications
116
117
*/
117
118
ipcMain . on ( 'addAwsApp' , ( message : IpcMainEvent , application : any ) => {
118
119
119
- const newAWSApp = JSON . parse ( application ) ;
120
- console . log ( 'parsed newApp: ' , newAWSApp ) ;
120
+ const newAwsApp = JSON . parse ( application ) ;
121
+ console . log ( 'parsed newApp: ' , newAwsApp ) ;
121
122
console . log ( 'currentUser' , currentUser ) ;
122
123
const createdOn = moment ( ) . format ( 'lll' ) ;
123
- newAWSApp . push ( createdOn ) ;
124
+ newAwsApp . push ( createdOn ) ;
124
125
125
126
if ( currentUser !== 'guest' ) {
126
-
127
- }
128
-
129
- // if user is not guest, should not have to pull info from settings.json file
130
-
127
+ return User . findOneAndUpdate ( { username : currentUser } , {
128
+ $push : { services : newAwsApp }
129
+ } , { new : true } )
130
+ . then ( ( data ) => {
131
+ console . log ( 'User updated' , data ) ;
132
+ // returning each array element name, 'AWS', region, 'AWS/(instance)', Date
133
+ message . returnValue = data . services . map ( ( arr : string [ ] ) => [ arr [ 0 ] , arr [ 1 ] , arr [ 2 ] , arr [ 4 ] , arr [ 5 ] ] )
134
+ } )
135
+ . catch ( ( error ) => {
136
+ console . log ( `addAWSApp failed : ${ error } ` )
137
+ } )
138
+ } else {
139
+ // if user is not guest, should not have to pull info from settings.json file
140
+ console . log ( 'current user is a guest, data will be saved locally...' )
131
141
// Retrieves file contents from settings.json
132
142
const settings = JSON . parse ( fs . readFileSync ( settingsLocation ) . toString ( 'utf8' ) ) ;
133
143
const services = settings [ currentUser ] . services ;
@@ -136,7 +146,7 @@ ipcMain.on('addAwsApp', (message: IpcMainEvent, application: any) => {
136
146
// name, instance, region, description, typeOfService, accessKey, secretAccessKey
137
147
138
148
// Add new applicaiton to list
139
- const newAwsApp = JSON . parse ( application ) ;
149
+ // const newAwsApp = JSON.parse(application);
140
150
141
151
// Add a creation date to the application on the 5th index
142
152
// const createdOn = moment().format('lll');
@@ -151,6 +161,7 @@ ipcMain.on('addAwsApp', (message: IpcMainEvent, application: any) => {
151
161
152
162
// Sync event - return new applications list
153
163
message . returnValue = services . map ( ( arr : string [ ] ) => [ arr [ 0 ] , arr [ 1 ] , arr [ 2 ] , arr [ 4 ] , arr [ 5 ] ] ) ;
164
+ }
154
165
} ) ;
155
166
156
167
/**
0 commit comments