@@ -103,14 +103,14 @@ const getAllVotingAddressByUser = async (req, res, next) => {
103103 if ( ! addrValue [ key ] . timestampValue ) {
104104 data [ key ] = decryptAes (
105105 addrValue [ key ] . stringValue ,
106- process . env . KEY_FOR_ENCRYPTION ,
106+ process . env . KEY_FOR_ENCRYPTION
107107 )
108108 } else {
109109 data [ key ] = Number ( addrValue [ key ] . timestampValue . nanos )
110110 }
111111 } )
112112 addresses . push ( data )
113- } ) ,
113+ } )
114114 ) . catch ( ( err ) => {
115115 throw err
116116 } )
@@ -127,7 +127,9 @@ const getAllVotingAddressByUser = async (req, res, next) => {
127127 } , { } )
128128
129129 Object . keys ( votesFiltered ) . forEach ( ( key ) => {
130- rdata [ key ] = votesFiltered [ key ] . find ( ( el ) => Math . max ( Number ( el . timestamp ) ) )
130+ rdata [ key ] = votesFiltered [ key ] . find ( ( el ) =>
131+ Math . max ( Number ( el . timestamp ) )
132+ )
131133 } )
132134
133135 addresses . forEach ( ( e ) => {
@@ -204,12 +206,12 @@ const getVotingAddress = async (req, res, next) => {
204206 }
205207
206208 if (
207- typeof addressesList !== 'undefined'
208- && addressesList . arrayValue . values . length > 0
209+ typeof addressesList !== 'undefined' &&
210+ addressesList . arrayValue . values . length > 0
209211 ) {
210212 if (
211213 typeof addressesList . arrayValue . values . find (
212- ( e ) => e . stringValue === id ,
214+ ( e ) => e . stringValue === id
213215 ) === 'undefined'
214216 ) {
215217 return res . status ( 403 ) . json ( {
@@ -219,7 +221,7 @@ const getVotingAddress = async (req, res, next) => {
219221 }
220222
221223 existMasterNodeInUser = addressesList . arrayValue . values . find (
222- ( element ) => element . stringValue === id ,
224+ ( element ) => element . stringValue === id
223225 )
224226
225227 if ( typeof existMasterNodeInUser !== 'undefined' ) {
@@ -236,7 +238,7 @@ const getVotingAddress = async (req, res, next) => {
236238 if ( key !== 'date' ) {
237239 decryptData [ key ] = decryptAes (
238240 fieldsProto [ key ] . stringValue ,
239- process . env . KEY_FOR_ENCRYPTION ,
241+ process . env . KEY_FOR_ENCRYPTION
240242 )
241243 } else if ( key === 'date' ) {
242244 decryptData [ key ] = Number ( fieldsProto [ key ] . timestampValue . seconds )
@@ -286,9 +288,7 @@ const createVotingAddress = async (req, res, next) => {
286288 return res . status ( 406 ) . json ( { ok : false , message : 'Required fields' } )
287289 }
288290
289- const {
290- name, address, privateKey, txId, listMN,
291- } = req . body
291+ const { name, address, privateKey, txId, listMN } = req . body
292292
293293 const re = / [ ' " ] + / g
294294 let serializedArray = [ ]
@@ -324,7 +324,7 @@ const createVotingAddress = async (req, res, next) => {
324324 // eslint-disable-next-line max-len
325325 const votingAddressCurrentMns = Object . keys ( currentMN ) . reduce (
326326 ( acc , el ) => acc . concat ( currentMN [ el ] . votingaddress ) ,
327- [ ] ,
327+ [ ]
328328 )
329329
330330 if ( addressesList ) {
@@ -362,10 +362,10 @@ const createVotingAddress = async (req, res, next) => {
362362 name : decryptAes ( name . stringValue , process . env . KEY_FOR_ENCRYPTION ) ,
363363 address : decryptAes (
364364 addrUser . stringValue ,
365- process . env . KEY_FOR_ENCRYPTION ,
365+ process . env . KEY_FOR_ENCRYPTION
366366 ) ,
367367 }
368- } ) ,
368+ } )
369369 )
370370
371371 if ( ! listMN ) {
@@ -376,12 +376,13 @@ const createVotingAddress = async (req, res, next) => {
376376 txId : `${ txId . replace ( re , '' ) } ` . trim ( ) ,
377377 }
378378 const existInMn = votingAddressCurrentMns . find (
379- ( addr ) => addr === newAddress . address ,
379+ ( addr ) => addr === newAddress . address
380380 )
381381 const isExist = resp . find ( ( e ) => e . address === newAddress . address )
382382 const verifyName = resp . find ( ( e ) => e . name === newAddress . name )
383383 if ( typeof verifyName !== 'undefined' ) {
384- newAddress . name = `${ name . replace ( re , '' ) } -${ crypto . randomBytes ( 12 ) . toString ( 'hex' ) } ` . trim ( )
384+ newAddress . name =
385+ `${ name . replace ( re , '' ) } -${ crypto . randomBytes ( 12 ) . toString ( 'hex' ) } ` . trim ( )
385386 }
386387
387388 if ( typeof isExist === 'undefined' && typeof existInMn !== 'undefined' ) {
@@ -409,29 +410,31 @@ const createVotingAddress = async (req, res, next) => {
409410 txId : `${ collateralHash } -${ collateralIndex } ` . trim ( ) ,
410411 }
411412 const existInMn = votingAddressCurrentMns . find (
412- ( addr ) => addr === newVotingAddress . address ,
413+ ( addr ) => addr === newVotingAddress . address
413414 )
414415 const isExist = resp . find (
415- ( el ) => el . address === newVotingAddress . address ,
416+ ( el ) => el . address === newVotingAddress . address
416417 )
417418 const verifyName = resp . find ( ( el ) => el . name === newVotingAddress . name )
418419
419420 if ( typeof verifyName !== 'undefined' ) {
420- newVotingAddress . name = `${ label . replace ( re , '' ) } -${ crypto . randomBytes ( 12 ) . toString ( 'hex' ) } ` . trim ( )
421+ newVotingAddress . name =
422+ `${ label . replace ( re , '' ) } -${ crypto . randomBytes ( 12 ) . toString ( 'hex' ) } ` . trim ( )
421423 }
422424
423425 if ( aggregateAddresses . length > 0 ) {
424426 const verifyNameInAddresses = aggregateAddresses . find (
425- ( el ) => el . name === newVotingAddress . name ,
427+ ( el ) => el . name === newVotingAddress . name
426428 )
427429 if ( typeof verifyNameInAddresses !== 'undefined' ) {
428- newVotingAddress . name = `${ label . replace ( re , '' ) } -${ crypto . randomBytes ( 12 ) . toString ( 'hex' ) } ` . trim ( )
430+ newVotingAddress . name =
431+ `${ label . replace ( re , '' ) } -${ crypto . randomBytes ( 12 ) . toString ( 'hex' ) } ` . trim ( )
429432 }
430433 }
431434
432435 if (
433- typeof isExist === 'undefined'
434- && typeof existInMn !== 'undefined'
436+ typeof isExist === 'undefined' &&
437+ typeof existInMn !== 'undefined'
435438 ) {
436439 aggregateAddresses . push ( newVotingAddress )
437440 }
@@ -466,7 +469,7 @@ const createVotingAddress = async (req, res, next) => {
466469 } else {
467470 addressesInvalid . push ( data )
468471 }
469- } ) ,
472+ } )
470473 ) . catch ( ( err ) => {
471474 throw err
472475 } )
@@ -483,12 +486,10 @@ const createVotingAddress = async (req, res, next) => {
483486 . json ( { ok : true , message : 'Data saved successfully' , addressesInvalid } )
484487 } catch ( err ) {
485488 if ( err . message === 'Unexpected end of JSON input' ) {
486- return res
487- . status ( 406 )
488- . json ( {
489- ok : false ,
490- message : 'Invalid format, Please verify the data and try again' ,
491- } )
489+ return res . status ( 406 ) . json ( {
490+ ok : false ,
491+ message : 'Invalid format, Please verify the data and try again' ,
492+ } )
492493 }
493494 next ( err )
494495 }
@@ -535,7 +536,7 @@ const updateVotingAddress = async (req, res, next) => {
535536
536537 if (
537538 typeof fieldsProto . addressesList . arrayValue . values . find (
538- ( e ) => e . stringValue === id ,
539+ ( e ) => e . stringValue === id
539540 ) === 'undefined'
540541 ) {
541542 return res . status ( 403 ) . json ( {
@@ -560,28 +561,32 @@ const updateVotingAddress = async (req, res, next) => {
560561 name : decryptAes ( name . stringValue , process . env . KEY_FOR_ENCRYPTION ) ,
561562 address : decryptAes (
562563 addrUser . stringValue ,
563- process . env . KEY_FOR_ENCRYPTION ,
564+ process . env . KEY_FOR_ENCRYPTION
564565 ) ,
565566 }
566- } ) ,
567+ } )
567568 )
568569
569570 // eslint-disable-next-line max-len
570571 if (
571- typeof addresses . find ( ( addrItem ) => addrItem . name === data . name )
572- !== 'undefined'
573- && addresses . filter (
574- ( addrItem ) => addrItem . name === data . name && addrItem . address !== data . address ,
572+ typeof addresses . find ( ( addrItem ) => addrItem . name === data . name ) !==
573+ 'undefined' &&
574+ addresses . filter (
575+ ( addrItem ) =>
576+ addrItem . name === data . name && addrItem . address !== data . address
575577 ) . length > 0
576578 ) {
577579 if ( ! data . name . split ( '-' ) [ 1 ] ) {
578- data . name = `${ data . name . replace ( re , '' ) } -${ crypto . randomBytes ( 12 ) . toString ( 'hex' ) } ` . trim ( )
580+ data . name =
581+ `${ data . name . replace ( re , '' ) } -${ crypto . randomBytes ( 12 ) . toString ( 'hex' ) } ` . trim ( )
579582 }
580583 }
581584
582585 // if (user.id !== req.user) return res.status(406).json({ ok: false, message: 'you do not have permissions to perform this action' });
583- if ( ! data ) return res . status ( 406 ) . json ( { ok : false , message : 'Required fields' } )
584- if ( ! checkDataMN ( data ) ) return res . status ( 406 ) . json ( { ok : false , messasge : 'invalid MasterNode' } )
586+ if ( ! data )
587+ return res . status ( 406 ) . json ( { ok : false , message : 'Required fields' } )
588+ if ( ! checkDataMN ( data ) )
589+ return res . status ( 406 ) . json ( { ok : false , messasge : 'invalid MasterNode' } )
585590 const validateAddr = await validateAddress ( data . address )
586591 if ( ! validateAddr ) {
587592 return res . status ( 400 ) . json ( {
@@ -650,15 +655,15 @@ const destroyVotingAddress = async (req, res, next) => {
650655 }
651656 if ( fieldsProto . addressesList . arrayValue . values . length > 0 ) {
652657 existMasterNodeInUser = fieldsProto . addressesList . arrayValue . values . find (
653- ( element ) => element . stringValue === id ,
658+ ( element ) => element . stringValue === id
654659 )
655660 if ( typeof existMasterNodeInUser !== 'undefined' ) {
656661 // eslint-disable-next-line array-callback-return
657662 fieldsProto . addressesList . arrayValue . values . map ( ( node ) => {
658663 addresses . push ( node . stringValue )
659664 } )
660665 const index = addresses . findIndex (
661- ( element ) => element === existMasterNodeInUser . stringValue ,
666+ ( element ) => element === existMasterNodeInUser . stringValue
662667 )
663668 addresses . splice ( index , 1 )
664669 await admin
0 commit comments