5fd13541aa0a3e533c98e1ce9a966abf2c2ed21a
[motion2.git] / server / api / squareMessage / squareMessage.controller.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0x718f=['where','pick','filter','merge','options','includeAll','include','findAll','rows','catch','find','create','body','params','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','util','sox','to-csv','querystring','papaparse','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','count','limit','Content-Range','reject','save','update','then','destroy','error','stack','name','send','index','SquareMessage','rawAttributes','type','key','map','query','keys','filters','intersection','model','attributes','fields','length','nolimit','offset','order','sort'];(function(_0x1d69e5,_0x2a29af){var _0x17da11=function(_0x36c61f){while(--_0x36c61f){_0x1d69e5['push'](_0x1d69e5['shift']());}};_0x17da11(++_0x2a29af);}(_0x718f,0x1f1));var _0xf718=function(_0x2aba0e,_0x1872be){_0x2aba0e=_0x2aba0e-0x0;var _0x3f277e=_0x718f[_0x2aba0e];return _0x3f277e;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0xf718('0x0'));var rimraf=require(_0xf718('0x1'));var zipdir=require(_0xf718('0x2'));var jsonpatch=require(_0xf718('0x3'));var rp=require(_0xf718('0x4'));var moment=require(_0xf718('0x5'));var BPromise=require('bluebird');var Mustache=require(_0xf718('0x6'));var util=require(_0xf718('0x7'));var path=require('path');var sox=require(_0xf718('0x8'));var csv=require(_0xf718('0x9'));var ejs=require('ejs');var fs=require('fs');var _=require('lodash');var squel=require('squel');var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0xf718('0x9'));var querystring=require(_0xf718('0xa'));var Papa=require(_0xf718('0xb'));var Redis=require('ioredis');var authService=require(_0xf718('0xc'));var qs=require('../../components/parsers/qs');var as=require(_0xf718('0xd'));var hardwareService=require(_0xf718('0xe'));var logger=require(_0xf718('0xf'))(_0xf718('0x10'));var utils=require(_0xf718('0x11'));var config=require(_0xf718('0x12'));var licenseUtil=require(_0xf718('0x13'));var db=require(_0xf718('0x14'))['db'];function respondWithStatusCode(_0x27fded,_0x3a1023){_0x3a1023=_0x3a1023||0xcc;return function(_0x42e259){if(_0x42e259){return _0x27fded[_0xf718('0x15')](_0x3a1023);}return _0x27fded[_0xf718('0x16')](_0x3a1023)[_0xf718('0x17')]();};}function respondWithResult(_0x30bb94,_0x58f19a){_0x58f19a=_0x58f19a||0xc8;return function(_0x15a3e8){if(_0x15a3e8){return _0x30bb94[_0xf718('0x16')](_0x58f19a)[_0xf718('0x18')](_0x15a3e8);}};}function respondWithFilteredResult(_0x1581f1,_0x5b2e08){return function(_0xcb93da){if(_0xcb93da){var _0x1ee652=_0xcb93da[_0xf718('0x19')],_0x3530a8=_0x5b2e08['offset'],_0x1f5278=_0x5b2e08['offset']+_0x5b2e08[_0xf718('0x1a')],_0x108340;if(_0x1f5278>=_0x1ee652){_0x1f5278=_0x1ee652;_0x108340=0xc8;}else{_0x108340=0xce;}_0x1581f1['status'](_0x108340);return _0x1581f1['set'](_0xf718('0x1b'),_0x3530a8+'-'+_0x1f5278+'/'+_0x1ee652)[_0xf718('0x18')](_0xcb93da);}return null;};}function patchUpdates(_0x20d915){return function(_0x5a87f4){try{jsonpatch['apply'](_0x5a87f4,_0x20d915,!![]);}catch(_0x512d07){return BPromise[_0xf718('0x1c')](_0x512d07);}return _0x5a87f4[_0xf718('0x1d')]();};}function saveUpdates(_0x15e1c5,_0x434ac9){return function(_0x3c2828){if(_0x3c2828){return _0x3c2828[_0xf718('0x1e')](_0x15e1c5)[_0xf718('0x1f')](function(_0x4c1df){return _0x4c1df;});}return null;};}function removeEntity(_0x506889,_0x52ff0b){return function(_0x35829c){if(_0x35829c){return _0x35829c[_0xf718('0x20')]()[_0xf718('0x1f')](function(){_0x506889[_0xf718('0x16')](0xcc)[_0xf718('0x17')]();});}};}function handleEntityNotFound(_0x13bad1,_0x622ad0){return function(_0x32d98f){if(!_0x32d98f){_0x13bad1[_0xf718('0x15')](0x194);}return _0x32d98f;};}function handleError(_0xb4a218,_0xc82462){_0xc82462=_0xc82462||0x1f4;return function(_0x32b637){logger[_0xf718('0x21')](_0x32b637[_0xf718('0x22')]);if(_0x32b637['name']){delete _0x32b637[_0xf718('0x23')];}_0xb4a218['status'](_0xc82462)[_0xf718('0x24')](_0x32b637);};}exports[_0xf718('0x25')]=function(_0x1f6ee,_0x511a49){var _0x27c8e9={},_0x34d01e={},_0x34994d={'count':0x0,'rows':[]};var _0xdc5818=_['map'](db[_0xf718('0x26')][_0xf718('0x27')],function(_0x36a995){return{'name':_0x36a995['fieldName'],'type':_0x36a995[_0xf718('0x28')][_0xf718('0x29')]};});_0x34d01e['model']=_[_0xf718('0x2a')](_0xdc5818,_0xf718('0x23'));_0x34d01e[_0xf718('0x2b')]=_[_0xf718('0x2c')](_0x1f6ee[_0xf718('0x2b')]);_0x34d01e[_0xf718('0x2d')]=_[_0xf718('0x2e')](_0x34d01e[_0xf718('0x2f')],_0x34d01e[_0xf718('0x2b')]);_0x27c8e9[_0xf718('0x30')]=_[_0xf718('0x2e')](_0x34d01e[_0xf718('0x2f')],qs['fields'](_0x1f6ee[_0xf718('0x2b')][_0xf718('0x31')]));_0x27c8e9[_0xf718('0x30')]=_0x27c8e9[_0xf718('0x30')][_0xf718('0x32')]?_0x27c8e9[_0xf718('0x30')]:_0x34d01e['model'];if(!_0x1f6ee[_0xf718('0x2b')]['hasOwnProperty'](_0xf718('0x33'))){_0x27c8e9[_0xf718('0x1a')]=qs[_0xf718('0x1a')](_0x1f6ee['query'][_0xf718('0x1a')]);_0x27c8e9[_0xf718('0x34')]=qs[_0xf718('0x34')](_0x1f6ee['query'][_0xf718('0x34')]);}_0x27c8e9[_0xf718('0x35')]=qs['sort'](_0x1f6ee[_0xf718('0x2b')][_0xf718('0x36')]);_0x27c8e9[_0xf718('0x37')]=qs[_0xf718('0x2d')](_[_0xf718('0x38')](_0x1f6ee['query'],_0x34d01e['filters']),_0xdc5818);if(_0x1f6ee[_0xf718('0x2b')][_0xf718('0x39')]){_0x27c8e9[_0xf718('0x37')]=_[_0xf718('0x3a')](_0x27c8e9[_0xf718('0x37')],{'$or':_[_0xf718('0x2a')](_0xdc5818,function(_0x2943a1){if(_0x2943a1['type']!=='VIRTUAL'){var _0x273681={};_0x273681[_0x2943a1['name']]={'$like':'%'+_0x1f6ee[_0xf718('0x2b')]['filter']+'%'};return _0x273681;}})});}_0x27c8e9=_[_0xf718('0x3a')]({},_0x27c8e9,_0x1f6ee[_0xf718('0x3b')]);var _0x3fa9fa={'where':_0x27c8e9[_0xf718('0x37')]};return db[_0xf718('0x26')][_0xf718('0x19')](_0x3fa9fa)[_0xf718('0x1f')](function(_0x23a2ae){_0x34994d[_0xf718('0x19')]=_0x23a2ae;if(_0x1f6ee['query'][_0xf718('0x3c')]){_0x27c8e9[_0xf718('0x3d')]=[{'all':!![]}];}return db[_0xf718('0x26')][_0xf718('0x3e')](_0x27c8e9);})['then'](function(_0x3f8fb0){_0x34994d[_0xf718('0x3f')]=_0x3f8fb0;return _0x34994d;})[_0xf718('0x1f')](respondWithFilteredResult(_0x511a49,_0x27c8e9))[_0xf718('0x40')](handleError(_0x511a49,null));};exports['show']=function(_0x3c77ef,_0xa82ae){var _0x3c6009={'raw':!![],'where':{'id':_0x3c77ef['params']['id']}},_0x57809b={};_0x57809b[_0xf718('0x2f')]=_[_0xf718('0x2c')](db['SquareMessage'][_0xf718('0x27')]);_0x57809b['query']=_[_0xf718('0x2c')](_0x3c77ef['query']);_0x57809b['filters']=_[_0xf718('0x2e')](_0x57809b[_0xf718('0x2f')],_0x57809b[_0xf718('0x2b')]);_0x3c6009[_0xf718('0x30')]=_['intersection'](_0x57809b[_0xf718('0x2f')],qs[_0xf718('0x31')](_0x3c77ef['query'][_0xf718('0x31')]));_0x3c6009[_0xf718('0x30')]=_0x3c6009[_0xf718('0x30')][_0xf718('0x32')]?_0x3c6009[_0xf718('0x30')]:_0x57809b[_0xf718('0x2f')];if(_0x3c77ef[_0xf718('0x2b')]['includeAll']){_0x3c6009['include']=[{'all':!![]}];}_0x3c6009=_[_0xf718('0x3a')]({},_0x3c6009,_0x3c77ef[_0xf718('0x3b')]);return db[_0xf718('0x26')][_0xf718('0x41')](_0x3c6009)[_0xf718('0x1f')](handleEntityNotFound(_0xa82ae,null))[_0xf718('0x1f')](respondWithResult(_0xa82ae,null))['catch'](handleError(_0xa82ae,null));};exports[_0xf718('0x42')]=function(_0x16af11,_0x1abd84){return db[_0xf718('0x26')][_0xf718('0x42')](_0x16af11[_0xf718('0x43')],{})[_0xf718('0x1f')](respondWithResult(_0x1abd84,0xc9))['catch'](handleError(_0x1abd84,null));};exports[_0xf718('0x1e')]=function(_0x2da34f,_0x131314){if(_0x2da34f[_0xf718('0x43')]['id']){delete _0x2da34f[_0xf718('0x43')]['id'];}return db['SquareMessage'][_0xf718('0x41')]({'where':{'id':_0x2da34f[_0xf718('0x44')]['id']}})[_0xf718('0x1f')](handleEntityNotFound(_0x131314,null))[_0xf718('0x1f')](saveUpdates(_0x2da34f[_0xf718('0x43')],null))[_0xf718('0x1f')](respondWithResult(_0x131314,null))[_0xf718('0x40')](handleError(_0x131314,null));};exports['destroy']=function(_0x4efdb3,_0x3a2353){return db['SquareMessage'][_0xf718('0x41')]({'where':{'id':_0x4efdb3[_0xf718('0x44')]['id']}})[_0xf718('0x1f')](handleEntityNotFound(_0x3a2353,null))[_0xf718('0x1f')](removeEntity(_0x3a2353,null))['catch'](handleError(_0x3a2353,null));};