@@ -210,28 +210,36 @@ const FEATURE_NAME = 'populator';
210
210
211
211
const saveEnvironment = function ( ob ) {
212
212
const obParams = ob . params ;
213
- const users = JSON . parse ( ob . params . qstring . users ) ;
214
- const setEnviromentInformationOnce = ob . params . qstring . setEnviromentInformationOnce ;
215
- if ( ! users || ! users . length ) {
216
- common . returnMessage ( obParams , 400 , "Missing params: " + users ) ;
217
- return false ;
218
- }
219
-
220
- const environmentId = common . crypto . createHash ( 'sha1' ) . update ( users [ 0 ] . appId + users [ 0 ] . environmentName ) . digest ( 'hex' ) ;
221
- const insertedInformations = [ ] ;
222
- const createdAt = new Date ( ) . getTime ( ) ;
223
- for ( let i = 0 ; i < users . length ; i ++ ) {
224
- insertedInformations . push ( {
225
- _id : users [ i ] . appId + "_" + users [ i ] . templateId + "_" + environmentId + "_" + users [ i ] . deviceId ,
226
- userName : users [ i ] . userName ,
227
- platform : users [ i ] . platform ,
228
- device : users [ i ] . device ,
229
- appVersion : users [ i ] . appVersion ,
230
- custom : users [ i ] . custom ,
231
- createdAt : createdAt
232
- } ) ;
233
- }
234
213
validateCreate ( obParams , FEATURE_NAME , function ( params ) {
214
+ var users = [ ] ;
215
+ try {
216
+ users = JSON . parse ( ob . params ?. qstring ?. users ) ;
217
+ }
218
+ catch ( e ) {
219
+ log . e ( e ) ;
220
+ users = [ ] ;
221
+ }
222
+ const setEnviromentInformationOnce = ob . params ?. qstring ?. setEnviromentInformationOnce ;
223
+ if ( ! users || ! users . length ) {
224
+ common . returnMessage ( obParams , 400 , "Missing params: users" ) ;
225
+ return false ;
226
+ }
227
+
228
+ const environmentId = common . crypto . createHash ( 'sha1' ) . update ( users [ 0 ] . appId + users [ 0 ] . environmentName ) . digest ( 'hex' ) ;
229
+ const insertedInformations = [ ] ;
230
+ const createdAt = new Date ( ) . getTime ( ) ;
231
+ for ( let i = 0 ; i < users . length ; i ++ ) {
232
+ insertedInformations . push ( {
233
+ _id : users [ i ] . appId + "_" + users [ i ] . templateId + "_" + environmentId + "_" + users [ i ] . deviceId ,
234
+ userName : users [ i ] . userName ,
235
+ platform : users [ i ] . platform ,
236
+ device : users [ i ] . device ,
237
+ appVersion : users [ i ] . appVersion ,
238
+ custom : users [ i ] . custom ,
239
+ createdAt : createdAt
240
+ } ) ;
241
+ }
242
+
235
243
if ( setEnviromentInformationOnce ) {
236
244
common . db . collection ( 'populator_environments' ) . insertOne ( {
237
245
_id : environmentId ,
0 commit comments