Built motion from commit f861bcb808219e66da88ba48b61bddb35224a65e. Version 3.0.0...
[motion-next.git] / server / api / cannedAnswer / cannedAnswer.controller.js
1 'use strict';const a57_0x4b1e=['show','30431ehTtdr','@config/logger','findAll','The\x20inserted\x20key\x20already\x20exists.','stack','rows','sort','fieldName','UserProfileSection','role','limit','keys','offset','key','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','user','options','attributes','destroy','CannedAnswer','rawAttributes','246287lkEmbQ','set','send','status','include','query','catch','UserProfileResource','MailAccountId','@utils/filter-attributes','212329ZaHmXA','@mysqldb','autoAssociation','ChatWebsiteId','@components/parsers/qs','lodash','merge','136087GzLqoM','180819hLRrIR','where','3Deyauy','fields','body','count','CannedAnswers','1Emxccm','intersection','type','create','index','SmsAccountId','findOne','then','name','length','filters','filter','1vbzffV','map','pick','sequelize','json','model','update','get','undefined','error','OpenchannelAccountId','252926etAtgz','includeAll','190184OcfBzh'];const a57_0x31c5=function(_0x34e14a,_0x272880){_0x34e14a=_0x34e14a-0xf8;let _0x4b1ece=a57_0x4b1e[_0x34e14a];return _0x4b1ece;};const a57_0x3cbec2=a57_0x31c5;(function(_0x435eea,_0x249336){const _0x347416=a57_0x31c5;while(!![]){try{const _0x6233a9=parseInt(_0x347416(0x100))*parseInt(_0x347416(0x125))+-parseInt(_0x347416(0x112))+-parseInt(_0x347416(0x10a))+-parseInt(_0x347416(0x119))*parseInt(_0x347416(0x132))+parseInt(_0x347416(0x114))*parseInt(_0x347416(0x134))+parseInt(_0x347416(0x130))+parseInt(_0x347416(0x111));if(_0x6233a9===_0x249336)break;else _0x435eea['push'](_0x435eea['shift']());}catch(_0x23554a){_0x435eea['push'](_0x435eea['shift']());}}}(a57_0x4b1e,0x22f9d));const _=require(a57_0x3cbec2(0x10f)),qs=require(a57_0x3cbec2(0x10e)),logger=require(a57_0x3cbec2(0x135))('api'),{db}=require(a57_0x3cbec2(0x10b)),{ValidationError}=require(a57_0x3cbec2(0x128)),{filterAttributes}=require(a57_0x3cbec2(0x109));function respondWithResult(_0x55c301,_0x1370de){return _0x1370de=_0x1370de||0xc8,function(_0x95f5dd){const _0x302b49=a57_0x31c5;if(_0x95f5dd)return _0x55c301['status'](_0x1370de)[_0x302b49(0x129)](_0x95f5dd);};}function respondWithFilteredResult(_0x1f88cf,_0x63309){return function(_0x106367){const _0x3b1442=a57_0x31c5;if(_0x106367){const _0x38a99f=_0x106367[_0x3b1442(0x117)],_0x4e5d9d=_0x63309[_0x3b1442(0x140)];let _0x430e17=_0x63309['offset']+_0x63309['limit'],_0x4f80ac;return _0x430e17>=_0x38a99f?(_0x430e17=_0x38a99f,_0x4f80ac=0xc8):_0x4f80ac=0xce,_0x1f88cf[_0x3b1442(0x103)](_0x4f80ac),_0x1f88cf[_0x3b1442(0x101)]('Content-Range',_0x4e5d9d+'-'+_0x430e17+'/'+_0x38a99f)[_0x3b1442(0x129)](_0x106367);}return null;};}function saveUpdates(_0x7116d3){return function(_0x204b46){if(_0x204b46)return _0x204b46['update'](_0x7116d3)['then'](function(_0x2d2c22){return _0x2d2c22;});return null;};}function removeEntity(_0x3ad351){return function(_0x48c30e){const _0x51f2a9=a57_0x31c5;if(_0x48c30e)return _0x48c30e['destroy']()[_0x51f2a9(0x120)](function(){const _0x537044=_0x51f2a9,_0x4f5e00=_0x48c30e[_0x537044(0x12c)]({'plain':!![]}),_0x4f4b59=_0x537044(0x118);return db[_0x537044(0x107)][_0x537044(0xfd)]({'where':{'type':_0x4f4b59,'resourceId':_0x4f5e00['id']}})['then'](function(){return _0x48c30e;});})['then'](function(){_0x3ad351['status'](0xcc)['end']();});};}function handleEntityNotFound(_0x3b4b7e){return function(_0x508a3b){return!_0x508a3b&&_0x3b4b7e['sendStatus'](0x194),_0x508a3b;};}function handleError(_0x32bb9f,_0x340160){return _0x340160=_0x340160||0x1f4,function(_0x2ae595){const _0x2e3856=a57_0x31c5;logger['error'](_0x2ae595[_0x2e3856(0x138)]),_0x2ae595['name']&&delete _0x2ae595['name'],_0x32bb9f[_0x2e3856(0x103)](_0x340160)[_0x2e3856(0x102)](_0x2ae595);};}exports[a57_0x3cbec2(0x11d)]=function(_0x3d67b1,_0x4e5418){const _0x573cbf=a57_0x3cbec2;let _0x498321={};const _0xbec479={},_0x1fc893={'count':0x0,'rows':[]},_0xcb95de=_[_0x573cbf(0x126)](db[_0x573cbf(0xfe)][_0x573cbf(0xff)],function(_0x24b116){const _0xbae7d0=_0x573cbf;return{'name':_0x24b116[_0xbae7d0(0x13b)],'type':_0x24b116[_0xbae7d0(0x11b)][_0xbae7d0(0xf8)]};});_0xbec479[_0x573cbf(0x12a)]=_['map'](_0xcb95de,_0x573cbf(0x121)),_0xbec479['query']=_[_0x573cbf(0x13f)](_0x3d67b1[_0x573cbf(0x105)]),_0xbec479[_0x573cbf(0x123)]=_[_0x573cbf(0x11a)](_0xbec479[_0x573cbf(0x12a)],_0xbec479[_0x573cbf(0x105)]),_0x498321[_0x573cbf(0xfc)]=_[_0x573cbf(0x11a)](_0xbec479[_0x573cbf(0x12a)],qs[_0x573cbf(0x115)](_0x3d67b1[_0x573cbf(0x105)]['fields'])),_0x498321[_0x573cbf(0xfc)]=_0x498321[_0x573cbf(0xfc)][_0x573cbf(0x122)]?_0x498321['attributes']:_0xbec479[_0x573cbf(0x12a)];typeof _0x3d67b1[_0x573cbf(0x105)]['nolimit']===_0x573cbf(0x12d)&&(_0x498321['limit']=qs['limit'](_0x3d67b1['query'][_0x573cbf(0x13e)]),_0x498321[_0x573cbf(0x140)]=qs['offset'](_0x3d67b1['query'][_0x573cbf(0x140)]));_0x498321['order']=qs[_0x573cbf(0x13a)](_0x3d67b1[_0x573cbf(0x105)][_0x573cbf(0x13a)]),_0x498321[_0x573cbf(0x113)]=qs[_0x573cbf(0x123)](_[_0x573cbf(0x127)](_0x3d67b1[_0x573cbf(0x105)],_0xbec479[_0x573cbf(0x123)]),_0xcb95de),_0x498321=filterAttributes(_0x498321,_0x3d67b1['query'][_0x573cbf(0x124)],_0xcb95de,_0x3d67b1[_0x573cbf(0xfb)]);const _0x289b73={'where':_0x498321[_0x573cbf(0x113)]};return db[_0x573cbf(0xfe)][_0x573cbf(0x117)](_0x289b73)['then'](function(_0x5e43f7){const _0x4361d8=_0x573cbf;return _0x1fc893[_0x4361d8(0x117)]=_0x5e43f7,_0x3d67b1[_0x4361d8(0x105)][_0x4361d8(0x131)]&&(_0x498321['include']=[{'all':!![]}]),db['CannedAnswer'][_0x4361d8(0x136)](_0x498321);})[_0x573cbf(0x120)](function(_0x42c0f5){const _0x55c003=_0x573cbf;return _0x1fc893[_0x55c003(0x139)]=_0x42c0f5,_0x1fc893;})['then'](respondWithFilteredResult(_0x4e5418,_0x498321))['catch'](handleError(_0x4e5418,null));},exports[a57_0x3cbec2(0x133)]=function(_0x29b21e,_0x331b75){const _0x16fd73=a57_0x3cbec2;let _0x4e9dc6={'raw':!![],'where':{'id':_0x29b21e['params']['id']}};const _0x1a87b5={};return _0x1a87b5[_0x16fd73(0x12a)]=_['keys'](db[_0x16fd73(0xfe)][_0x16fd73(0xff)]),_0x1a87b5[_0x16fd73(0x105)]=_[_0x16fd73(0x13f)](_0x29b21e['query']),_0x1a87b5[_0x16fd73(0x123)]=_[_0x16fd73(0x11a)](_0x1a87b5[_0x16fd73(0x12a)],_0x1a87b5[_0x16fd73(0x105)]),_0x4e9dc6[_0x16fd73(0xfc)]=_[_0x16fd73(0x11a)](_0x1a87b5[_0x16fd73(0x12a)],qs['fields'](_0x29b21e['query'][_0x16fd73(0x115)])),_0x4e9dc6['attributes']=_0x4e9dc6[_0x16fd73(0xfc)]['length']?_0x4e9dc6[_0x16fd73(0xfc)]:_0x1a87b5[_0x16fd73(0x12a)],_0x29b21e['query'][_0x16fd73(0x131)]&&(_0x4e9dc6[_0x16fd73(0x104)]=[{'all':!![]}]),_0x4e9dc6=_[_0x16fd73(0x110)]({},_0x4e9dc6,_0x29b21e['options']),db[_0x16fd73(0xfe)][_0x16fd73(0x11f)](_0x4e9dc6)[_0x16fd73(0x120)](handleEntityNotFound(_0x331b75,null))[_0x16fd73(0x120)](respondWithResult(_0x331b75,null))[_0x16fd73(0x106)](handleError(_0x331b75,null));},exports[a57_0x3cbec2(0x12b)]=function(_0x171376,_0x1268d7){const _0x169cc7=a57_0x3cbec2;return _0x171376[_0x169cc7(0x116)]['id']&&delete _0x171376[_0x169cc7(0x116)]['id'],db['CannedAnswer'][_0x169cc7(0x11f)]({'where':{'id':_0x171376['params']['id']}})[_0x169cc7(0x120)](handleEntityNotFound(_0x1268d7,null))[_0x169cc7(0x120)](saveUpdates(_0x171376[_0x169cc7(0x116)],null))[_0x169cc7(0x120)](respondWithResult(_0x1268d7,null))['catch'](handleError(_0x1268d7,null));},exports[a57_0x3cbec2(0xfd)]=function(_0x2ba732,_0x376585){const _0x5ef40a=a57_0x3cbec2;return db[_0x5ef40a(0xfe)][_0x5ef40a(0x11f)]({'where':{'id':_0x2ba732['params']['id']}})[_0x5ef40a(0x120)](handleEntityNotFound(_0x376585,null))[_0x5ef40a(0x120)](removeEntity(_0x376585,null))['catch'](handleError(_0x376585,null));},exports[a57_0x3cbec2(0x11c)]=function(_0x5d6071,_0x2cee09){const _0xb13f5b=a57_0x3cbec2,_0x182bf1={'key':_0x5d6071[_0xb13f5b(0x116)]['key']};if(_0x5d6071[_0xb13f5b(0x116)]['MailAccountId'])_0x182bf1['MailAccountId']=_0x5d6071[_0xb13f5b(0x116)][_0xb13f5b(0x108)];else{if(_0x5d6071[_0xb13f5b(0x116)][_0xb13f5b(0x11e)])_0x182bf1['SmsAccountId']=_0x5d6071[_0xb13f5b(0x116)][_0xb13f5b(0x11e)];else{if(_0x5d6071[_0xb13f5b(0x116)][_0xb13f5b(0x12f)])_0x182bf1['OpenchannelAccountId']=_0x5d6071[_0xb13f5b(0x116)][_0xb13f5b(0x12f)];else _0x5d6071[_0xb13f5b(0x116)]['ChatWebsiteId']&&(_0x182bf1[_0xb13f5b(0x10d)]=_0x5d6071[_0xb13f5b(0x116)][_0xb13f5b(0x10d)]);}}return db[_0xb13f5b(0xfe)][_0xb13f5b(0x11f)]({'where':_0x182bf1})['then'](function(_0x121792){const _0x1dcf6b=_0xb13f5b;if(_0x121792)throw new ValidationError(_0x1dcf6b(0x137));return db[_0x1dcf6b(0xfe)][_0x1dcf6b(0x11c)](_0x5d6071[_0x1dcf6b(0x116)]);})[_0xb13f5b(0x120)](function(_0x7c78af){const _0x42eb39=_0xb13f5b,_0x57353d=_0x5d6071[_0x42eb39(0xfa)][_0x42eb39(0x12c)]({'plain':!![]});if(!_0x57353d)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x57353d[_0x42eb39(0x13d)]===_0x42eb39(0xfa)){const _0x22e8b3=_0x7c78af[_0x42eb39(0x12c)]({'plain':!![]});return db[_0x42eb39(0x13c)][_0x42eb39(0x11f)]({'where':{'name':_0x42eb39(0x118),'userProfileId':_0x57353d['userProfileId']},'raw':!![]})[_0x42eb39(0x120)](function(_0x1a701f){const _0x300036=_0x42eb39;return _0x1a701f&&_0x1a701f[_0x300036(0x10c)]===0x0?db[_0x300036(0x107)][_0x300036(0x11c)]({'name':_0x22e8b3[_0x300036(0x121)],'resourceId':_0x22e8b3['id'],'type':_0x1a701f[_0x300036(0x121)],'sectionId':_0x1a701f['id']},{})[_0x300036(0x120)](function(){return _0x7c78af;}):_0x7c78af;})[_0x42eb39(0x106)](function(_0x44cdc1){const _0x18f8fc=_0x42eb39;logger[_0x18f8fc(0x12e)](_0x18f8fc(0xf9),_0x44cdc1);throw _0x44cdc1;});}return _0x7c78af;})['then'](respondWithResult(_0x2cee09,0xc9))[_0xb13f5b(0x106)](handleError(_0x2cee09,null));};