Built motion from commit bfc7a72f7045b27461c9a5d1f71c1a658cfd0b8b. Version 3.0.0...
[motion-next.git] / server / api / automation / automation.controller.js
1 const a38_0x10a0=['key','send','order','Automation','addActions','undefined','like','length','getActions','body','sequelize','where','options','filters','sendStatus','json','set','catch','name','include','destroy','create','Content-Range','keys','Condition','findAll','offset','nolimit','findOne','attributes','type','model','api','pick','limit','end','intersection','stack','query','rows','fieldName','merge','status','omit','rawAttributes','params','filter','getConditions','show','error','Action','ids','then','VIRTUAL','sort','fields','addConditions','map','update','count','../../mysqldb'];(function(_0x55214b,_0x10a08b){const _0x2a8d6a=function(_0x3a3c94){while(--_0x3a3c94){_0x55214b['push'](_0x55214b['shift']());}};_0x2a8d6a(++_0x10a08b);}(a38_0x10a0,0x86));const a38_0x2a8d=function(_0x55214b,_0x10a08b){_0x55214b=_0x55214b-0x0;let _0x2a8d6a=a38_0x10a0[_0x55214b];return _0x2a8d6a;};const _0x2f5074=a38_0x2a8d;'use strict';const _=require('lodash'),qs=require('../../components/parsers/qs'),logger=require('../../config/logger')(_0x2f5074('0x14')),db=require(_0x2f5074('0x30'))['db'],{Op}=require(_0x2f5074('0x3b'));function respondWithResult(_0x3a3c94,_0x5ddc34){return _0x5ddc34=_0x5ddc34||0xc8,function(_0x570eec){const _0x1b0b37=a38_0x2a8d;if(_0x570eec)return _0x3a3c94[_0x1b0b37('0x1e')](_0x5ddc34)['json'](_0x570eec);};}function respondWithFilteredResult(_0x40a945,_0x2ad2ec){return function(_0x2d05e2){const _0xab3335=a38_0x2a8d;if(_0x2d05e2){const _0x474b1f=_0x2d05e2[_0xab3335('0x2f')],_0x27ad92=_0x2ad2ec[_0xab3335('0xe')];let _0x57b7cf=_0x2ad2ec[_0xab3335('0xe')]+_0x2ad2ec[_0xab3335('0x16')],_0x54a716;return _0x57b7cf>=_0x474b1f?(_0x57b7cf=_0x474b1f,_0x54a716=0xc8):_0x54a716=0xce,_0x40a945['status'](_0x54a716),_0x40a945[_0xab3335('0x4')](_0xab3335('0xa'),_0x27ad92+'-'+_0x57b7cf+'/'+_0x474b1f)[_0xab3335('0x3')](_0x2d05e2);}return null;};}function saveUpdates(_0x7727c3){return function(_0x18cf90){const _0x442229=a38_0x2a8d;if(_0x18cf90)return _0x18cf90[_0x442229('0x2e')](_0x7727c3)[_0x442229('0x28')](function(_0x113dcd){return _0x113dcd;});return null;};}function removeEntity(_0x2ecc2e){return function(_0x7bd656){const _0x443021=a38_0x2a8d;if(_0x7bd656)return _0x7bd656['destroy']()[_0x443021('0x28')](function(){const _0x9aa821=_0x443021;_0x2ecc2e['status'](0xcc)[_0x9aa821('0x17')]();});};}function handleEntityNotFound(_0x2ba191){return function(_0x51db23){const _0x3c5727=a38_0x2a8d;return!_0x51db23&&_0x2ba191[_0x3c5727('0x2')](0x194),_0x51db23;};}function handleError(_0x5e7988,_0x2936e5){return _0x2936e5=_0x2936e5||0x1f4,function(_0x3b5528){const _0x5b4f1d=a38_0x2a8d;logger[_0x5b4f1d('0x25')](_0x3b5528[_0x5b4f1d('0x19')]),_0x3b5528[_0x5b4f1d('0x6')]&&delete _0x3b5528['name'],_0x5e7988['status'](_0x2936e5)[_0x5b4f1d('0x32')](_0x3b5528);};}exports['index']=function(_0x171ab9,_0x5ad4d2){const _0x12ea4f=_0x2f5074;let _0x5c24b5={};const _0x2d82c1={},_0x16f603={'count':0x0,'rows':[]},_0x258213=_[_0x12ea4f('0x2d')](db[_0x12ea4f('0x34')]['rawAttributes'],function(_0x303a49){const _0x44ebec=_0x12ea4f;return{'name':_0x303a49[_0x44ebec('0x1c')],'type':_0x303a49[_0x44ebec('0x12')][_0x44ebec('0x31')]};});_0x2d82c1[_0x12ea4f('0x13')]=_[_0x12ea4f('0x2d')](_0x258213,_0x12ea4f('0x6')),_0x2d82c1[_0x12ea4f('0x1a')]=_[_0x12ea4f('0xb')](_0x171ab9[_0x12ea4f('0x1a')]),_0x2d82c1['filters']=_[_0x12ea4f('0x18')](_0x2d82c1['model'],_0x2d82c1['query']),_0x5c24b5[_0x12ea4f('0x11')]=_[_0x12ea4f('0x18')](_0x2d82c1['model'],qs[_0x12ea4f('0x2b')](_0x171ab9[_0x12ea4f('0x1a')][_0x12ea4f('0x2b')])),_0x5c24b5[_0x12ea4f('0x11')]=_0x5c24b5[_0x12ea4f('0x11')][_0x12ea4f('0x38')]?_0x5c24b5[_0x12ea4f('0x11')]:_0x2d82c1[_0x12ea4f('0x13')];typeof _0x171ab9[_0x12ea4f('0x1a')][_0x12ea4f('0xf')]===_0x12ea4f('0x36')&&(_0x5c24b5[_0x12ea4f('0x16')]=qs[_0x12ea4f('0x16')](_0x171ab9[_0x12ea4f('0x1a')]['limit']),_0x5c24b5[_0x12ea4f('0xe')]=qs[_0x12ea4f('0xe')](_0x171ab9['query'][_0x12ea4f('0xe')]));_0x5c24b5[_0x12ea4f('0x33')]=qs[_0x12ea4f('0x2a')](_0x171ab9[_0x12ea4f('0x1a')]['sort']),_0x5c24b5['where']=qs['filters'](_[_0x12ea4f('0x15')](_0x171ab9[_0x12ea4f('0x1a')],_0x2d82c1[_0x12ea4f('0x1')]),_0x258213);_0x171ab9['query'][_0x12ea4f('0x22')]&&(_0x5c24b5[_0x12ea4f('0x3c')]=_[_0x12ea4f('0x1d')](_0x5c24b5[_0x12ea4f('0x3c')],{[Op['or']]:_['map'](_0x258213,function(_0x498c51){const _0x224aeb=_0x12ea4f;if(_0x498c51[_0x224aeb('0x12')]!==_0x224aeb('0x29')){const _0x112878={};return _0x112878[_0x498c51[_0x224aeb('0x6')]]={[Op[_0x224aeb('0x37')]]:'%'+_0x171ab9['query'][_0x224aeb('0x22')]+'%'},_0x112878;}})}));_0x5c24b5=_['merge']({},_0x5c24b5,_0x171ab9[_0x12ea4f('0x0')]);const _0x57b754={'where':_0x5c24b5[_0x12ea4f('0x3c')]};return db[_0x12ea4f('0x34')][_0x12ea4f('0x2f')](_0x57b754)[_0x12ea4f('0x28')](function(_0x43247e){const _0x36ea31=_0x12ea4f;return _0x16f603[_0x36ea31('0x2f')]=_0x43247e,_0x171ab9[_0x36ea31('0x1a')]['includeAll']&&(_0x5c24b5[_0x36ea31('0x7')]=[{'all':!![]}]),db[_0x36ea31('0x34')][_0x36ea31('0xd')](_0x5c24b5);})[_0x12ea4f('0x28')](function(_0x4da83d){const _0x287832=_0x12ea4f;return _0x16f603[_0x287832('0x1b')]=_0x4da83d,_0x16f603;})[_0x12ea4f('0x28')](respondWithFilteredResult(_0x5ad4d2,_0x5c24b5))['catch'](handleError(_0x5ad4d2,null));},exports[_0x2f5074('0x24')]=function(_0xde5cf2,_0x3f2432){const _0x1d1b91=_0x2f5074;let _0x4956c9={'raw':![],'where':{'id':_0xde5cf2[_0x1d1b91('0x21')]['id']}};const _0x3f4a71={};return _0x3f4a71[_0x1d1b91('0x13')]=_[_0x1d1b91('0xb')](db[_0x1d1b91('0x34')][_0x1d1b91('0x20')]),_0x3f4a71['query']=_['keys'](_0xde5cf2[_0x1d1b91('0x1a')]),_0x3f4a71[_0x1d1b91('0x1')]=_[_0x1d1b91('0x18')](_0x3f4a71[_0x1d1b91('0x13')],_0x3f4a71['query']),_0x4956c9[_0x1d1b91('0x11')]=_[_0x1d1b91('0x18')](_0x3f4a71[_0x1d1b91('0x13')],qs[_0x1d1b91('0x2b')](_0xde5cf2[_0x1d1b91('0x1a')][_0x1d1b91('0x2b')])),_0x4956c9[_0x1d1b91('0x11')]=_0x4956c9['attributes'][_0x1d1b91('0x38')]?_0x4956c9['attributes']:_0x3f4a71[_0x1d1b91('0x13')],_0xde5cf2['query']['includeAll']&&(_0x4956c9[_0x1d1b91('0x7')]=[{'all':!![]}]),_0x4956c9=_[_0x1d1b91('0x1d')]({},_0x4956c9,_0xde5cf2[_0x1d1b91('0x0')]),db['Automation'][_0x1d1b91('0x10')](_0x4956c9)['then'](handleEntityNotFound(_0x3f2432,null))['then'](respondWithResult(_0x3f2432,null))[_0x1d1b91('0x5')](handleError(_0x3f2432,null));},exports[_0x2f5074('0x9')]=function(_0x50b674,_0x5acd0a){const _0x29e568=_0x2f5074;return db[_0x29e568('0x34')][_0x29e568('0x9')](_0x50b674[_0x29e568('0x3a')],{})[_0x29e568('0x28')](respondWithResult(_0x5acd0a,0xc9))[_0x29e568('0x5')](handleError(_0x5acd0a,null));},exports[_0x2f5074('0x2e')]=function(_0x37c0d8,_0x4bf84b){const _0x4de70f=_0x2f5074;return _0x37c0d8[_0x4de70f('0x3a')]['id']&&delete _0x37c0d8['body']['id'],db['Automation'][_0x4de70f('0x10')]({'where':{'id':_0x37c0d8[_0x4de70f('0x21')]['id']}})[_0x4de70f('0x28')](handleEntityNotFound(_0x4bf84b,null))[_0x4de70f('0x28')](saveUpdates(_0x37c0d8[_0x4de70f('0x3a')],null))['then'](respondWithResult(_0x4bf84b,null))['catch'](handleError(_0x4bf84b,null));},exports[_0x2f5074('0x8')]=function(_0x2e94ab,_0x16fece){const _0x464e74=_0x2f5074;return db['Automation'][_0x464e74('0x10')]({'where':{'id':_0x2e94ab[_0x464e74('0x21')]['id']}})['then'](handleEntityNotFound(_0x16fece,null))['then'](removeEntity(_0x16fece,null))[_0x464e74('0x5')](handleError(_0x16fece,null));},exports['addConditions']=function(_0x34ba2d,_0xf7cdb0){const _0x5cd6c9=_0x2f5074;return db[_0x5cd6c9('0xc')][_0x5cd6c9('0x10')]({'where':{'id':_0x34ba2d[_0x5cd6c9('0x21')]['id']}})[_0x5cd6c9('0x28')](function(_0x49b5f9){const _0x100ecc=_0x5cd6c9;if(_0x49b5f9)return _0x49b5f9[_0x100ecc('0x2c')](_0x34ba2d['body'][_0x100ecc('0x27')],{'through':_[_0x100ecc('0x1f')](_0x34ba2d[_0x100ecc('0x3a')],[_0x100ecc('0x27'),'id'])});})['then'](respondWithResult(_0xf7cdb0,null))[_0x5cd6c9('0x5')](handleError(_0xf7cdb0,null));},exports['getConditions']=function(_0x53a2b6,_0x1c111f){const _0x577cc3=_0x2f5074;let _0x4354c1={};const _0x39dc7c={};let _0x11e95b,_0x520be0;return db[_0x577cc3('0x34')][_0x577cc3('0x10')]({'where':{'id':_0x53a2b6[_0x577cc3('0x21')]['id']}})[_0x577cc3('0x28')](handleEntityNotFound(_0x1c111f,null))['then'](function(_0x3888a1){const _0x3b758b=_0x577cc3;if(_0x3888a1)return _0x11e95b=_0x3888a1,_0x39dc7c[_0x3b758b('0x13')]=_[_0x3b758b('0xb')](db[_0x3b758b('0xc')]['rawAttributes']),_0x39dc7c[_0x3b758b('0x1a')]=_[_0x3b758b('0xb')](_0x53a2b6[_0x3b758b('0x1a')]),_0x39dc7c[_0x3b758b('0x1')]=_[_0x3b758b('0x18')](_0x39dc7c[_0x3b758b('0x13')],_0x39dc7c['query']),_0x4354c1['attributes']=_[_0x3b758b('0x18')](_0x39dc7c['model'],qs[_0x3b758b('0x2b')](_0x53a2b6['query'][_0x3b758b('0x2b')])),_0x4354c1[_0x3b758b('0x11')]=_0x4354c1[_0x3b758b('0x11')]['length']?_0x4354c1[_0x3b758b('0x11')]:_0x39dc7c[_0x3b758b('0x13')],_0x4354c1[_0x3b758b('0x33')]=qs[_0x3b758b('0x2a')](_0x53a2b6[_0x3b758b('0x1a')]['sort']),_0x4354c1[_0x3b758b('0x3c')]=qs[_0x3b758b('0x1')](_[_0x3b758b('0x15')](_0x53a2b6['query'],_0x39dc7c[_0x3b758b('0x1')])),_0x53a2b6['query'][_0x3b758b('0x22')]&&(_0x4354c1['where']=_[_0x3b758b('0x1d')](_0x4354c1[_0x3b758b('0x3c')],{[Op['or']]:_[_0x3b758b('0x2d')](_0x4354c1['attributes'],function(_0x5ac19f){const _0x13ebf1=_0x3b758b,_0x59c1e0={};return _0x59c1e0[_0x5ac19f]={[Op[_0x13ebf1('0x37')]]:'%'+_0x53a2b6[_0x13ebf1('0x1a')][_0x13ebf1('0x22')]+'%'},_0x59c1e0;})})),_0x4354c1=_[_0x3b758b('0x1d')]({},_0x4354c1,_0x53a2b6[_0x3b758b('0x0')]),_0x11e95b[_0x3b758b('0x23')](_0x4354c1);})[_0x577cc3('0x28')](function(_0x479e91){const _0x5bd6a9=_0x577cc3;if(_0x479e91)return _0x520be0=_0x479e91['length'],typeof _0x53a2b6[_0x5bd6a9('0x1a')]['nolimit']===_0x5bd6a9('0x36')&&(_0x4354c1[_0x5bd6a9('0x16')]=qs[_0x5bd6a9('0x16')](_0x53a2b6['query']['limit']),_0x4354c1[_0x5bd6a9('0xe')]=qs[_0x5bd6a9('0xe')](_0x53a2b6[_0x5bd6a9('0x1a')]['offset'])),_0x11e95b[_0x5bd6a9('0x23')](_0x4354c1);})[_0x577cc3('0x28')](function(_0x41ef3c){if(_0x41ef3c)return _0x41ef3c?{'count':_0x520be0,'rows':_0x41ef3c}:null;})[_0x577cc3('0x28')](respondWithResult(_0x1c111f,null))['catch'](handleError(_0x1c111f,null));},exports[_0x2f5074('0x35')]=function(_0xe368a1,_0x1343cf){const _0x5c8908=_0x2f5074;return db[_0x5c8908('0x26')][_0x5c8908('0x10')]({'where':{'id':_0xe368a1[_0x5c8908('0x21')]['id']}})['then'](function(_0x2441ca){const _0x5101bd=_0x5c8908;if(_0x2441ca)return _0x2441ca[_0x5101bd('0x35')](_0xe368a1[_0x5101bd('0x3a')]['ids'],{'through':_[_0x5101bd('0x1f')](_0xe368a1[_0x5101bd('0x3a')],[_0x5101bd('0x27'),'id'])});})[_0x5c8908('0x28')](respondWithResult(_0x1343cf,null))[_0x5c8908('0x5')](handleError(_0x1343cf,null));},exports[_0x2f5074('0x39')]=function(_0xe6fde3,_0x52a306){const _0x463143=_0x2f5074;let _0x4ccd30={};const _0x4a7612={};let _0x211c83,_0x2adbcd;return db[_0x463143('0x34')][_0x463143('0x10')]({'where':{'id':_0xe6fde3[_0x463143('0x21')]['id']}})[_0x463143('0x28')](handleEntityNotFound(_0x52a306,null))[_0x463143('0x28')](function(_0x43a5b3){const _0x159155=_0x463143;if(_0x43a5b3)return _0x211c83=_0x43a5b3,_0x4a7612[_0x159155('0x13')]=_[_0x159155('0xb')](db[_0x159155('0x26')][_0x159155('0x20')]),_0x4a7612[_0x159155('0x1a')]=_[_0x159155('0xb')](_0xe6fde3[_0x159155('0x1a')]),_0x4a7612['filters']=_[_0x159155('0x18')](_0x4a7612[_0x159155('0x13')],_0x4a7612['query']),_0x4ccd30[_0x159155('0x11')]=_[_0x159155('0x18')](_0x4a7612[_0x159155('0x13')],qs[_0x159155('0x2b')](_0xe6fde3['query'][_0x159155('0x2b')])),_0x4ccd30[_0x159155('0x11')]=_0x4ccd30[_0x159155('0x11')]['length']?_0x4ccd30[_0x159155('0x11')]:_0x4a7612['model'],_0x4ccd30[_0x159155('0x33')]=qs[_0x159155('0x2a')](_0xe6fde3['query']['sort']),_0x4ccd30[_0x159155('0x3c')]=qs['filters'](_[_0x159155('0x15')](_0xe6fde3[_0x159155('0x1a')],_0x4a7612[_0x159155('0x1')])),_0xe6fde3['query'][_0x159155('0x22')]&&(_0x4ccd30[_0x159155('0x3c')]=_['merge'](_0x4ccd30['where'],{[Op['or']]:_[_0x159155('0x2d')](_0x4ccd30[_0x159155('0x11')],function(_0x2f9ff2){const _0x33baad=_0x159155,_0x4ec707={};return _0x4ec707[_0x2f9ff2]={[Op['like']]:'%'+_0xe6fde3[_0x33baad('0x1a')][_0x33baad('0x22')]+'%'},_0x4ec707;})})),_0x4ccd30=_[_0x159155('0x1d')]({},_0x4ccd30,_0xe6fde3[_0x159155('0x0')]),_0x211c83[_0x159155('0x39')](_0x4ccd30);})[_0x463143('0x28')](function(_0x446c32){const _0x3035b9=_0x463143;if(_0x446c32)return _0x2adbcd=_0x446c32[_0x3035b9('0x38')],typeof _0xe6fde3[_0x3035b9('0x1a')][_0x3035b9('0xf')]==='undefined'&&(_0x4ccd30[_0x3035b9('0x16')]=qs['limit'](_0xe6fde3[_0x3035b9('0x1a')][_0x3035b9('0x16')]),_0x4ccd30[_0x3035b9('0xe')]=qs[_0x3035b9('0xe')](_0xe6fde3[_0x3035b9('0x1a')][_0x3035b9('0xe')])),_0x211c83[_0x3035b9('0x39')](_0x4ccd30);})['then'](function(_0x5621e1){if(_0x5621e1)return _0x5621e1?{'count':_0x2adbcd,'rows':_0x5621e1}:null;})[_0x463143('0x28')](respondWithResult(_0x52a306,null))[_0x463143('0x5')](handleError(_0x52a306,null));};