45a48d52cb90dfad1fd1a1321027665c389bee63
[motion-next.git] / server / api / cannedAnswer / cannedAnswer.controller.js
1 const a47_0xb83a=['lodash','SmsAccountId','like','query','catch','limit','../../mysqldb','get','UserProfileResource','includeAll','attributes','VIRTUAL','type','options','length','count','pick','stack','keys','findAll','OpenchannelAccountId','undefined','set','user','role','CannedAnswer','MailAccountId','Content-Range','show','../../components/parsers/qs','UserProfileSection','fields','json','name','filters','merge','CannedAnswers','destroy','sort','status','sequelize','map','ChatWebsiteId','api','body','model','Unable\x20to\x20retrieve\x20the\x20current\x20user','create','order','rawAttributes','include','where','../../config/logger','error','offset','intersection','filter','send','findOne','then','autoAssociation','end','nolimit','params'];(function(_0x5b34c0,_0xb83adf){const _0x555366=function(_0x28e484){while(--_0x28e484){_0x5b34c0['push'](_0x5b34c0['shift']());}};_0x555366(++_0xb83adf);}(a47_0xb83a,0x93));const a47_0x5553=function(_0x5b34c0,_0xb83adf){_0x5b34c0=_0x5b34c0-0x0;let _0x555366=a47_0xb83a[_0x5b34c0];return _0x555366;};const _0x1fb9f4=a47_0x5553;'use strict';const _=require(_0x1fb9f4('0x2d')),qs=require(_0x1fb9f4('0xa')),logger=require(_0x1fb9f4('0x21'))(_0x1fb9f4('0x18')),db=require(_0x1fb9f4('0x33'))['db'],{Op,ValidationError}=require(_0x1fb9f4('0x15'));function respondWithResult(_0x28e484,_0x58ea1e){return _0x58ea1e=_0x58ea1e||0xc8,function(_0x746257){const _0x35df76=a47_0x5553;if(_0x746257)return _0x28e484[_0x35df76('0x14')](_0x58ea1e)[_0x35df76('0xd')](_0x746257);};}function respondWithFilteredResult(_0xdf8c6b,_0x15b605){return function(_0x1670f7){const _0x118df6=a47_0x5553;if(_0x1670f7){const _0x361118=_0x1670f7[_0x118df6('0x3c')],_0x1b2f0b=_0x15b605[_0x118df6('0x23')];let _0x493513=_0x15b605[_0x118df6('0x23')]+_0x15b605[_0x118df6('0x32')],_0x2af152;return _0x493513>=_0x361118?(_0x493513=_0x361118,_0x2af152=0xc8):_0x2af152=0xce,_0xdf8c6b[_0x118df6('0x14')](_0x2af152),_0xdf8c6b[_0x118df6('0x3')](_0x118df6('0x8'),_0x1b2f0b+'-'+_0x493513+'/'+_0x361118)[_0x118df6('0xd')](_0x1670f7);}return null;};}function saveUpdates(_0x2c3798){return function(_0x3613b7){const _0x2e41ea=a47_0x5553;if(_0x3613b7)return _0x3613b7['update'](_0x2c3798)[_0x2e41ea('0x28')](function(_0x402b1f){return _0x402b1f;});return null;};}function removeEntity(_0x5f46ad){return function(_0x127e5e){const _0x589965=a47_0x5553;if(_0x127e5e)return _0x127e5e[_0x589965('0x12')]()[_0x589965('0x28')](function(){const _0x474a12=_0x589965,_0x215b0d=_0x127e5e[_0x474a12('0x34')]({'plain':!![]}),_0x275cab=_0x474a12('0x11');return db[_0x474a12('0x35')][_0x474a12('0x12')]({'where':{'type':_0x275cab,'resourceId':_0x215b0d['id']}})['then'](function(){return _0x127e5e;});})[_0x589965('0x28')](function(){const _0x1c21b6=_0x589965;_0x5f46ad[_0x1c21b6('0x14')](0xcc)[_0x1c21b6('0x2a')]();});};}function handleEntityNotFound(_0x2bc8d0){return function(_0x4d3e01){return!_0x4d3e01&&_0x2bc8d0['sendStatus'](0x194),_0x4d3e01;};}function handleError(_0x5db265,_0x3be8cf){return _0x3be8cf=_0x3be8cf||0x1f4,function(_0x558c93){const _0x43ecd9=a47_0x5553;logger[_0x43ecd9('0x22')](_0x558c93[_0x43ecd9('0x3e')]),_0x558c93[_0x43ecd9('0xe')]&&delete _0x558c93[_0x43ecd9('0xe')],_0x5db265[_0x43ecd9('0x14')](_0x3be8cf)[_0x43ecd9('0x26')](_0x558c93);};}exports['index']=function(_0x5be238,_0x3eb494){const _0xc9fb26=_0x1fb9f4;let _0x53ca44={};const _0x4135cc={},_0x2cc2b3={'count':0x0,'rows':[]},_0x5d9a71=_['map'](db['CannedAnswer'][_0xc9fb26('0x1e')],function(_0x3dcdb9){const _0x38da03=_0xc9fb26;return{'name':_0x3dcdb9['fieldName'],'type':_0x3dcdb9[_0x38da03('0x39')]['key']};});_0x4135cc['model']=_[_0xc9fb26('0x16')](_0x5d9a71,_0xc9fb26('0xe')),_0x4135cc['query']=_[_0xc9fb26('0x3f')](_0x5be238[_0xc9fb26('0x30')]),_0x4135cc[_0xc9fb26('0xf')]=_[_0xc9fb26('0x24')](_0x4135cc['model'],_0x4135cc['query']),_0x53ca44[_0xc9fb26('0x37')]=_[_0xc9fb26('0x24')](_0x4135cc[_0xc9fb26('0x1a')],qs[_0xc9fb26('0xc')](_0x5be238['query'][_0xc9fb26('0xc')])),_0x53ca44['attributes']=_0x53ca44[_0xc9fb26('0x37')][_0xc9fb26('0x3b')]?_0x53ca44[_0xc9fb26('0x37')]:_0x4135cc['model'];typeof _0x5be238[_0xc9fb26('0x30')][_0xc9fb26('0x2b')]===_0xc9fb26('0x2')&&(_0x53ca44[_0xc9fb26('0x32')]=qs[_0xc9fb26('0x32')](_0x5be238[_0xc9fb26('0x30')][_0xc9fb26('0x32')]),_0x53ca44[_0xc9fb26('0x23')]=qs['offset'](_0x5be238['query'][_0xc9fb26('0x23')]));_0x53ca44[_0xc9fb26('0x1d')]=qs[_0xc9fb26('0x13')](_0x5be238[_0xc9fb26('0x30')]['sort']),_0x53ca44[_0xc9fb26('0x20')]=qs[_0xc9fb26('0xf')](_[_0xc9fb26('0x3d')](_0x5be238[_0xc9fb26('0x30')],_0x4135cc['filters']),_0x5d9a71);_0x5be238[_0xc9fb26('0x30')][_0xc9fb26('0x25')]&&(_0x53ca44[_0xc9fb26('0x20')]=_[_0xc9fb26('0x10')](_0x53ca44[_0xc9fb26('0x20')],{[Op['or']]:_[_0xc9fb26('0x16')](_0x5d9a71,function(_0x4a4f1d){const _0x334455=_0xc9fb26;if(_0x4a4f1d[_0x334455('0x39')]!==_0x334455('0x38')){const _0x37577e={};return _0x37577e[_0x4a4f1d[_0x334455('0xe')]]={[Op[_0x334455('0x2f')]]:'%'+_0x5be238[_0x334455('0x30')]['filter']+'%'},_0x37577e;}})}));_0x53ca44=_[_0xc9fb26('0x10')]({},_0x53ca44,_0x5be238[_0xc9fb26('0x3a')]);const _0x2c27e3={'where':_0x53ca44[_0xc9fb26('0x20')]};return db['CannedAnswer']['count'](_0x2c27e3)['then'](function(_0x4bc04b){const _0x1f1c5b=_0xc9fb26;return _0x2cc2b3[_0x1f1c5b('0x3c')]=_0x4bc04b,_0x5be238['query'][_0x1f1c5b('0x36')]&&(_0x53ca44[_0x1f1c5b('0x1f')]=[{'all':!![]}]),db[_0x1f1c5b('0x6')][_0x1f1c5b('0x0')](_0x53ca44);})['then'](function(_0x314b4a){return _0x2cc2b3['rows']=_0x314b4a,_0x2cc2b3;})['then'](respondWithFilteredResult(_0x3eb494,_0x53ca44))[_0xc9fb26('0x31')](handleError(_0x3eb494,null));},exports[_0x1fb9f4('0x9')]=function(_0x4483ed,_0x4c7c54){const _0x29018b=_0x1fb9f4;let _0x4fe663={'raw':!![],'where':{'id':_0x4483ed[_0x29018b('0x2c')]['id']}};const _0x4271b9={};return _0x4271b9[_0x29018b('0x1a')]=_['keys'](db[_0x29018b('0x6')][_0x29018b('0x1e')]),_0x4271b9[_0x29018b('0x30')]=_[_0x29018b('0x3f')](_0x4483ed[_0x29018b('0x30')]),_0x4271b9[_0x29018b('0xf')]=_[_0x29018b('0x24')](_0x4271b9[_0x29018b('0x1a')],_0x4271b9[_0x29018b('0x30')]),_0x4fe663[_0x29018b('0x37')]=_[_0x29018b('0x24')](_0x4271b9[_0x29018b('0x1a')],qs[_0x29018b('0xc')](_0x4483ed[_0x29018b('0x30')]['fields'])),_0x4fe663[_0x29018b('0x37')]=_0x4fe663[_0x29018b('0x37')][_0x29018b('0x3b')]?_0x4fe663[_0x29018b('0x37')]:_0x4271b9[_0x29018b('0x1a')],_0x4483ed[_0x29018b('0x30')][_0x29018b('0x36')]&&(_0x4fe663[_0x29018b('0x1f')]=[{'all':!![]}]),_0x4fe663=_[_0x29018b('0x10')]({},_0x4fe663,_0x4483ed[_0x29018b('0x3a')]),db[_0x29018b('0x6')]['findOne'](_0x4fe663)[_0x29018b('0x28')](handleEntityNotFound(_0x4c7c54,null))[_0x29018b('0x28')](respondWithResult(_0x4c7c54,null))[_0x29018b('0x31')](handleError(_0x4c7c54,null));},exports['update']=function(_0x5c3c7b,_0x2a7c07){const _0x4edb9c=_0x1fb9f4;return _0x5c3c7b[_0x4edb9c('0x19')]['id']&&delete _0x5c3c7b[_0x4edb9c('0x19')]['id'],db[_0x4edb9c('0x6')]['findOne']({'where':{'id':_0x5c3c7b[_0x4edb9c('0x2c')]['id']}})[_0x4edb9c('0x28')](handleEntityNotFound(_0x2a7c07,null))[_0x4edb9c('0x28')](saveUpdates(_0x5c3c7b['body'],null))[_0x4edb9c('0x28')](respondWithResult(_0x2a7c07,null))['catch'](handleError(_0x2a7c07,null));},exports[_0x1fb9f4('0x12')]=function(_0x1cdb03,_0x2fd931){const _0x4a9b0b=_0x1fb9f4;return db[_0x4a9b0b('0x6')]['findOne']({'where':{'id':_0x1cdb03[_0x4a9b0b('0x2c')]['id']}})[_0x4a9b0b('0x28')](handleEntityNotFound(_0x2fd931,null))[_0x4a9b0b('0x28')](removeEntity(_0x2fd931,null))[_0x4a9b0b('0x31')](handleError(_0x2fd931,null));},exports['create']=function(_0x459f0e,_0x5b91a4){const _0xbd21e0=_0x1fb9f4,_0x154a80={'key':_0x459f0e[_0xbd21e0('0x19')]['key']};if(_0x459f0e[_0xbd21e0('0x19')][_0xbd21e0('0x7')])_0x154a80[_0xbd21e0('0x7')]=_0x459f0e[_0xbd21e0('0x19')][_0xbd21e0('0x7')];else{if(_0x459f0e[_0xbd21e0('0x19')][_0xbd21e0('0x2e')])_0x154a80[_0xbd21e0('0x2e')]=_0x459f0e[_0xbd21e0('0x19')][_0xbd21e0('0x2e')];else{if(_0x459f0e[_0xbd21e0('0x19')][_0xbd21e0('0x1')])_0x154a80[_0xbd21e0('0x1')]=_0x459f0e[_0xbd21e0('0x19')][_0xbd21e0('0x1')];else _0x459f0e[_0xbd21e0('0x19')][_0xbd21e0('0x17')]&&(_0x154a80[_0xbd21e0('0x17')]=_0x459f0e['body'][_0xbd21e0('0x17')]);}}return db[_0xbd21e0('0x6')]['findOne']({'where':_0x154a80})[_0xbd21e0('0x28')](function(_0x400b2f){const _0xb62bea=_0xbd21e0;if(_0x400b2f)throw new ValidationError('The\x20inserted\x20key\x20already\x20exists.');return db[_0xb62bea('0x6')][_0xb62bea('0x1c')](_0x459f0e['body']);})[_0xbd21e0('0x28')](function(_0x524b93){const _0x2ac11b=_0xbd21e0,_0x181cc6=_0x459f0e[_0x2ac11b('0x4')]['get']({'plain':!![]});if(!_0x181cc6)throw new Error(_0x2ac11b('0x1b'));if(_0x181cc6[_0x2ac11b('0x5')]==='user'){const _0x5d1df2=_0x524b93[_0x2ac11b('0x34')]({'plain':!![]});return db[_0x2ac11b('0xb')][_0x2ac11b('0x27')]({'where':{'name':'CannedAnswers','userProfileId':_0x181cc6['userProfileId']},'raw':!![]})[_0x2ac11b('0x28')](function(_0x2f645e){const _0x87b168=_0x2ac11b;return _0x2f645e&&_0x2f645e[_0x87b168('0x29')]===0x0?db[_0x87b168('0x35')][_0x87b168('0x1c')]({'name':_0x5d1df2['name'],'resourceId':_0x5d1df2['id'],'type':_0x2f645e[_0x87b168('0xe')],'sectionId':_0x2f645e['id']},{})[_0x87b168('0x28')](function(){return _0x524b93;}):_0x524b93;})[_0x2ac11b('0x31')](function(_0x239e19){const _0x457cec=_0x2ac11b;logger[_0x457cec('0x22')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x239e19);throw _0x239e19;});}return _0x524b93;})[_0xbd21e0('0x28')](respondWithResult(_0x5b91a4,0xc9))[_0xbd21e0('0x31')](handleError(_0x5b91a4,null));};