Built motion from commit aab208717af8d15f4fa224cdb6a202877019af9b. Version 3.0.0...
[motion-next.git] / server / api / automation / automation.controller.js
1 const a38_0x2e2a=['show','include','addConditions','json','fields','filters','Action','omit','findAll','Condition','like','destroy','create','key','fieldName','ids','rows','Automation','error','model','getConditions','catch','length','then','api','where','stack','update','lodash','count','type','nolimit','findOne','rawAttributes','includeAll','query','attributes','VIRTUAL','options','addActions','../../mysqldb','params','intersection','sort','undefined','getActions','merge','keys','name','offset','set','body','pick','map','limit','status','../../components/parsers/qs','filter','sequelize'];(function(_0x325207,_0x2e2a5b){const _0x5797d6=function(_0xd555){while(--_0xd555){_0x325207['push'](_0x325207['shift']());}};_0x5797d6(++_0x2e2a5b);}(a38_0x2e2a,0xa5));const a38_0x5797=function(_0x325207,_0x2e2a5b){_0x325207=_0x325207-0x0;let _0x5797d6=a38_0x2e2a[_0x325207];return _0x5797d6;};const _0xc4b5cd=a38_0x5797;'use strict';const _=require(_0xc4b5cd('0x28')),qs=require(_0xc4b5cd('0x9')),logger=require('../../config/logger')(_0xc4b5cd('0x24')),db=require(_0xc4b5cd('0x34'))['db'],{Op}=require(_0xc4b5cd('0xb'));function respondWithResult(_0xd555,_0x335623){return _0x335623=_0x335623||0xc8,function(_0x15f352){const _0x5d0e18=a38_0x5797;if(_0x15f352)return _0xd555[_0x5d0e18('0x8')](_0x335623)['json'](_0x15f352);};}function respondWithFilteredResult(_0x452ab3,_0x59716b){return function(_0x3d399e){const _0x54d88c=a38_0x5797;if(_0x3d399e){const _0xd04f06=_0x3d399e[_0x54d88c('0x29')],_0x1a1121=_0x59716b['offset'];let _0x1fa224=_0x59716b[_0x54d88c('0x2')]+_0x59716b['limit'],_0x5dc761;return _0x1fa224>=_0xd04f06?(_0x1fa224=_0xd04f06,_0x5dc761=0xc8):_0x5dc761=0xce,_0x452ab3[_0x54d88c('0x8')](_0x5dc761),_0x452ab3[_0x54d88c('0x3')]('Content-Range',_0x1a1121+'-'+_0x1fa224+'/'+_0xd04f06)[_0x54d88c('0xf')](_0x3d399e);}return null;};}function saveUpdates(_0x4959d8){return function(_0x5e71e3){const _0x254872=a38_0x5797;if(_0x5e71e3)return _0x5e71e3['update'](_0x4959d8)[_0x254872('0x23')](function(_0xbd0f90){return _0xbd0f90;});return null;};}function removeEntity(_0x357c03){return function(_0x321607){const _0x2d432b=a38_0x5797;if(_0x321607)return _0x321607[_0x2d432b('0x17')]()[_0x2d432b('0x23')](function(){const _0x27357c=_0x2d432b;_0x357c03[_0x27357c('0x8')](0xcc)['end']();});};}function handleEntityNotFound(_0x2d4d28){return function(_0x34a8e6){return!_0x34a8e6&&_0x2d4d28['sendStatus'](0x194),_0x34a8e6;};}function handleError(_0x32390b,_0x2240e3){return _0x2240e3=_0x2240e3||0x1f4,function(_0x5d07b3){const _0x1fb739=a38_0x5797;logger[_0x1fb739('0x1e')](_0x5d07b3[_0x1fb739('0x26')]),_0x5d07b3[_0x1fb739('0x1')]&&delete _0x5d07b3['name'],_0x32390b[_0x1fb739('0x8')](_0x2240e3)['send'](_0x5d07b3);};}exports['index']=function(_0x2e2f48,_0x4e539c){const _0x222092=_0xc4b5cd;let _0x53ba1a={};const _0x38a333={},_0x36f035={'count':0x0,'rows':[]},_0x486ec2=_['map'](db[_0x222092('0x1d')][_0x222092('0x2d')],function(_0x4432be){const _0x3868f6=_0x222092;return{'name':_0x4432be[_0x3868f6('0x1a')],'type':_0x4432be[_0x3868f6('0x2a')][_0x3868f6('0x19')]};});_0x38a333['model']=_['map'](_0x486ec2,_0x222092('0x1')),_0x38a333[_0x222092('0x2f')]=_[_0x222092('0x0')](_0x2e2f48['query']),_0x38a333[_0x222092('0x11')]=_[_0x222092('0x36')](_0x38a333[_0x222092('0x1f')],_0x38a333[_0x222092('0x2f')]),_0x53ba1a[_0x222092('0x30')]=_[_0x222092('0x36')](_0x38a333[_0x222092('0x1f')],qs[_0x222092('0x10')](_0x2e2f48[_0x222092('0x2f')][_0x222092('0x10')])),_0x53ba1a[_0x222092('0x30')]=_0x53ba1a['attributes'][_0x222092('0x22')]?_0x53ba1a[_0x222092('0x30')]:_0x38a333[_0x222092('0x1f')];typeof _0x2e2f48[_0x222092('0x2f')]['nolimit']===_0x222092('0x38')&&(_0x53ba1a['limit']=qs['limit'](_0x2e2f48['query']['limit']),_0x53ba1a[_0x222092('0x2')]=qs['offset'](_0x2e2f48[_0x222092('0x2f')][_0x222092('0x2')]));_0x53ba1a['order']=qs[_0x222092('0x37')](_0x2e2f48[_0x222092('0x2f')][_0x222092('0x37')]),_0x53ba1a[_0x222092('0x25')]=qs[_0x222092('0x11')](_[_0x222092('0x5')](_0x2e2f48['query'],_0x38a333[_0x222092('0x11')]),_0x486ec2);_0x2e2f48[_0x222092('0x2f')][_0x222092('0xa')]&&(_0x53ba1a['where']=_[_0x222092('0x3a')](_0x53ba1a[_0x222092('0x25')],{[Op['or']]:_[_0x222092('0x6')](_0x486ec2,function(_0x13e101){const _0x476bf0=_0x222092;if(_0x13e101[_0x476bf0('0x2a')]!==_0x476bf0('0x31')){const _0x35b1fd={};return _0x35b1fd[_0x13e101[_0x476bf0('0x1')]]={[Op[_0x476bf0('0x16')]]:'%'+_0x2e2f48[_0x476bf0('0x2f')][_0x476bf0('0xa')]+'%'},_0x35b1fd;}})}));_0x53ba1a=_['merge']({},_0x53ba1a,_0x2e2f48[_0x222092('0x32')]);const _0x3bf1b6={'where':_0x53ba1a[_0x222092('0x25')]};return db[_0x222092('0x1d')]['count'](_0x3bf1b6)['then'](function(_0x48ac13){const _0x2700d3=_0x222092;return _0x36f035[_0x2700d3('0x29')]=_0x48ac13,_0x2e2f48['query'][_0x2700d3('0x2e')]&&(_0x53ba1a[_0x2700d3('0xd')]=[{'all':!![]}]),db[_0x2700d3('0x1d')][_0x2700d3('0x14')](_0x53ba1a);})[_0x222092('0x23')](function(_0x50b3b0){const _0x437ca7=_0x222092;return _0x36f035[_0x437ca7('0x1c')]=_0x50b3b0,_0x36f035;})['then'](respondWithFilteredResult(_0x4e539c,_0x53ba1a))['catch'](handleError(_0x4e539c,null));},exports[_0xc4b5cd('0xc')]=function(_0x2681bc,_0x2fe747){const _0x17d579=_0xc4b5cd;let _0x2f9efe={'raw':![],'where':{'id':_0x2681bc['params']['id']}};const _0x54d935={};return _0x54d935[_0x17d579('0x1f')]=_['keys'](db[_0x17d579('0x1d')]['rawAttributes']),_0x54d935[_0x17d579('0x2f')]=_[_0x17d579('0x0')](_0x2681bc[_0x17d579('0x2f')]),_0x54d935[_0x17d579('0x11')]=_[_0x17d579('0x36')](_0x54d935[_0x17d579('0x1f')],_0x54d935[_0x17d579('0x2f')]),_0x2f9efe['attributes']=_['intersection'](_0x54d935[_0x17d579('0x1f')],qs[_0x17d579('0x10')](_0x2681bc[_0x17d579('0x2f')]['fields'])),_0x2f9efe[_0x17d579('0x30')]=_0x2f9efe[_0x17d579('0x30')][_0x17d579('0x22')]?_0x2f9efe[_0x17d579('0x30')]:_0x54d935[_0x17d579('0x1f')],_0x2681bc[_0x17d579('0x2f')][_0x17d579('0x2e')]&&(_0x2f9efe[_0x17d579('0xd')]=[{'all':!![]}]),_0x2f9efe=_[_0x17d579('0x3a')]({},_0x2f9efe,_0x2681bc[_0x17d579('0x32')]),db[_0x17d579('0x1d')][_0x17d579('0x2c')](_0x2f9efe)[_0x17d579('0x23')](handleEntityNotFound(_0x2fe747,null))[_0x17d579('0x23')](respondWithResult(_0x2fe747,null))[_0x17d579('0x21')](handleError(_0x2fe747,null));},exports[_0xc4b5cd('0x18')]=function(_0x304c60,_0x583626){const _0x14358e=_0xc4b5cd;return db[_0x14358e('0x1d')][_0x14358e('0x18')](_0x304c60[_0x14358e('0x4')],{})['then'](respondWithResult(_0x583626,0xc9))[_0x14358e('0x21')](handleError(_0x583626,null));},exports[_0xc4b5cd('0x27')]=function(_0xe471d,_0x35eeb2){const _0x2bc8ac=_0xc4b5cd;return _0xe471d[_0x2bc8ac('0x4')]['id']&&delete _0xe471d[_0x2bc8ac('0x4')]['id'],db[_0x2bc8ac('0x1d')]['findOne']({'where':{'id':_0xe471d[_0x2bc8ac('0x35')]['id']}})[_0x2bc8ac('0x23')](handleEntityNotFound(_0x35eeb2,null))[_0x2bc8ac('0x23')](saveUpdates(_0xe471d['body'],null))['then'](respondWithResult(_0x35eeb2,null))[_0x2bc8ac('0x21')](handleError(_0x35eeb2,null));},exports[_0xc4b5cd('0x17')]=function(_0x4d5370,_0x5525ae){const _0x45808d=_0xc4b5cd;return db['Automation'][_0x45808d('0x2c')]({'where':{'id':_0x4d5370[_0x45808d('0x35')]['id']}})[_0x45808d('0x23')](handleEntityNotFound(_0x5525ae,null))[_0x45808d('0x23')](removeEntity(_0x5525ae,null))[_0x45808d('0x21')](handleError(_0x5525ae,null));},exports['addConditions']=function(_0x19dba4,_0x2ec4e6){const _0x356864=_0xc4b5cd;return db[_0x356864('0x15')][_0x356864('0x2c')]({'where':{'id':_0x19dba4[_0x356864('0x35')]['id']}})[_0x356864('0x23')](function(_0x353729){const _0x255230=_0x356864;if(_0x353729)return _0x353729[_0x255230('0xe')](_0x19dba4[_0x255230('0x4')][_0x255230('0x1b')],{'through':_[_0x255230('0x13')](_0x19dba4[_0x255230('0x4')],[_0x255230('0x1b'),'id'])});})[_0x356864('0x23')](respondWithResult(_0x2ec4e6,null))['catch'](handleError(_0x2ec4e6,null));},exports[_0xc4b5cd('0x20')]=function(_0x107cf5,_0x223353){const _0x5bb459=_0xc4b5cd;let _0x3c307c={};const _0x36e940={};let _0x7594c5,_0x24a7f4;return db[_0x5bb459('0x1d')][_0x5bb459('0x2c')]({'where':{'id':_0x107cf5[_0x5bb459('0x35')]['id']}})[_0x5bb459('0x23')](handleEntityNotFound(_0x223353,null))['then'](function(_0x59cb9b){const _0x18e7b5=_0x5bb459;if(_0x59cb9b)return _0x7594c5=_0x59cb9b,_0x36e940[_0x18e7b5('0x1f')]=_[_0x18e7b5('0x0')](db[_0x18e7b5('0x15')][_0x18e7b5('0x2d')]),_0x36e940[_0x18e7b5('0x2f')]=_[_0x18e7b5('0x0')](_0x107cf5[_0x18e7b5('0x2f')]),_0x36e940['filters']=_[_0x18e7b5('0x36')](_0x36e940[_0x18e7b5('0x1f')],_0x36e940['query']),_0x3c307c['attributes']=_[_0x18e7b5('0x36')](_0x36e940[_0x18e7b5('0x1f')],qs[_0x18e7b5('0x10')](_0x107cf5[_0x18e7b5('0x2f')][_0x18e7b5('0x10')])),_0x3c307c['attributes']=_0x3c307c[_0x18e7b5('0x30')][_0x18e7b5('0x22')]?_0x3c307c[_0x18e7b5('0x30')]:_0x36e940[_0x18e7b5('0x1f')],_0x3c307c['order']=qs['sort'](_0x107cf5['query'][_0x18e7b5('0x37')]),_0x3c307c[_0x18e7b5('0x25')]=qs[_0x18e7b5('0x11')](_['pick'](_0x107cf5['query'],_0x36e940[_0x18e7b5('0x11')])),_0x107cf5[_0x18e7b5('0x2f')]['filter']&&(_0x3c307c['where']=_['merge'](_0x3c307c[_0x18e7b5('0x25')],{[Op['or']]:_[_0x18e7b5('0x6')](_0x3c307c[_0x18e7b5('0x30')],function(_0x456ecd){const _0x33e6b5=_0x18e7b5,_0x881c8f={};return _0x881c8f[_0x456ecd]={[Op[_0x33e6b5('0x16')]]:'%'+_0x107cf5[_0x33e6b5('0x2f')]['filter']+'%'},_0x881c8f;})})),_0x3c307c=_[_0x18e7b5('0x3a')]({},_0x3c307c,_0x107cf5['options']),_0x7594c5[_0x18e7b5('0x20')](_0x3c307c);})[_0x5bb459('0x23')](function(_0x25184b){const _0x5e3e52=_0x5bb459;if(_0x25184b)return _0x24a7f4=_0x25184b[_0x5e3e52('0x22')],typeof _0x107cf5[_0x5e3e52('0x2f')][_0x5e3e52('0x2b')]===_0x5e3e52('0x38')&&(_0x3c307c['limit']=qs[_0x5e3e52('0x7')](_0x107cf5['query'][_0x5e3e52('0x7')]),_0x3c307c[_0x5e3e52('0x2')]=qs[_0x5e3e52('0x2')](_0x107cf5['query'][_0x5e3e52('0x2')])),_0x7594c5[_0x5e3e52('0x20')](_0x3c307c);})[_0x5bb459('0x23')](function(_0x1ffab1){if(_0x1ffab1)return _0x1ffab1?{'count':_0x24a7f4,'rows':_0x1ffab1}:null;})[_0x5bb459('0x23')](respondWithResult(_0x223353,null))[_0x5bb459('0x21')](handleError(_0x223353,null));},exports['addActions']=function(_0x3a99aa,_0x14caf4){const _0x191ed9=_0xc4b5cd;return db[_0x191ed9('0x12')][_0x191ed9('0x2c')]({'where':{'id':_0x3a99aa[_0x191ed9('0x35')]['id']}})[_0x191ed9('0x23')](function(_0xa2f141){const _0x51a002=_0x191ed9;if(_0xa2f141)return _0xa2f141[_0x51a002('0x33')](_0x3a99aa[_0x51a002('0x4')][_0x51a002('0x1b')],{'through':_['omit'](_0x3a99aa[_0x51a002('0x4')],['ids','id'])});})[_0x191ed9('0x23')](respondWithResult(_0x14caf4,null))[_0x191ed9('0x21')](handleError(_0x14caf4,null));},exports['getActions']=function(_0x83f0ab,_0x2c7731){const _0x451483=_0xc4b5cd;let _0x5338ea={};const _0x581d70={};let _0x5ad845,_0x313a2f;return db['Automation'][_0x451483('0x2c')]({'where':{'id':_0x83f0ab[_0x451483('0x35')]['id']}})[_0x451483('0x23')](handleEntityNotFound(_0x2c7731,null))[_0x451483('0x23')](function(_0x384569){const _0x4faae7=_0x451483;if(_0x384569)return _0x5ad845=_0x384569,_0x581d70[_0x4faae7('0x1f')]=_[_0x4faae7('0x0')](db[_0x4faae7('0x12')]['rawAttributes']),_0x581d70['query']=_[_0x4faae7('0x0')](_0x83f0ab[_0x4faae7('0x2f')]),_0x581d70[_0x4faae7('0x11')]=_[_0x4faae7('0x36')](_0x581d70[_0x4faae7('0x1f')],_0x581d70[_0x4faae7('0x2f')]),_0x5338ea[_0x4faae7('0x30')]=_[_0x4faae7('0x36')](_0x581d70['model'],qs[_0x4faae7('0x10')](_0x83f0ab[_0x4faae7('0x2f')][_0x4faae7('0x10')])),_0x5338ea[_0x4faae7('0x30')]=_0x5338ea[_0x4faae7('0x30')][_0x4faae7('0x22')]?_0x5338ea[_0x4faae7('0x30')]:_0x581d70[_0x4faae7('0x1f')],_0x5338ea['order']=qs[_0x4faae7('0x37')](_0x83f0ab['query'][_0x4faae7('0x37')]),_0x5338ea[_0x4faae7('0x25')]=qs[_0x4faae7('0x11')](_[_0x4faae7('0x5')](_0x83f0ab['query'],_0x581d70['filters'])),_0x83f0ab['query'][_0x4faae7('0xa')]&&(_0x5338ea[_0x4faae7('0x25')]=_[_0x4faae7('0x3a')](_0x5338ea[_0x4faae7('0x25')],{[Op['or']]:_[_0x4faae7('0x6')](_0x5338ea[_0x4faae7('0x30')],function(_0x2fed26){const _0xbedaa4=_0x4faae7,_0x176562={};return _0x176562[_0x2fed26]={[Op['like']]:'%'+_0x83f0ab[_0xbedaa4('0x2f')][_0xbedaa4('0xa')]+'%'},_0x176562;})})),_0x5338ea=_[_0x4faae7('0x3a')]({},_0x5338ea,_0x83f0ab[_0x4faae7('0x32')]),_0x5ad845[_0x4faae7('0x39')](_0x5338ea);})[_0x451483('0x23')](function(_0x1d0659){const _0x222da5=_0x451483;if(_0x1d0659)return _0x313a2f=_0x1d0659[_0x222da5('0x22')],typeof _0x83f0ab[_0x222da5('0x2f')][_0x222da5('0x2b')]===_0x222da5('0x38')&&(_0x5338ea[_0x222da5('0x7')]=qs[_0x222da5('0x7')](_0x83f0ab['query']['limit']),_0x5338ea[_0x222da5('0x2')]=qs[_0x222da5('0x2')](_0x83f0ab['query'][_0x222da5('0x2')])),_0x5ad845[_0x222da5('0x39')](_0x5338ea);})['then'](function(_0x37abd9){if(_0x37abd9)return _0x37abd9?{'count':_0x313a2f,'rows':_0x37abd9}:null;})[_0x451483('0x23')](respondWithResult(_0x2c7731,null))[_0x451483('0x21')](handleError(_0x2c7731,null));};