2651501ad9576b288415a0f34fc89e894bc52b0a
[motion2.git] / server / api / faxApplication / faxApplication.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 _0xf04f=['length','hasOwnProperty','order','sort','pick','filter','where','VIRTUAL','merge','options','includeAll','findAll','rows','catch','show','params','include','create','body','find','destroy','eml-format','rimraf','request-promise','moment','bluebird','util','to-csv','fs-extra','lodash','crypto','desk.js','querystring','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','undefined','count','limit','set','apply','reject','save','update','then','error','stack','name','send','map','FaxApplication','rawAttributes','fieldName','type','key','model','keys','query','filters','intersection','attributes','fields'];(function(_0x3d816a,_0x59f66e){var _0x302cb3=function(_0x2d9bbb){while(--_0x2d9bbb){_0x3d816a['push'](_0x3d816a['shift']());}};_0x302cb3(++_0x59f66e);}(_0xf04f,0xed));var _0xff04=function(_0x5cb1af,_0x4bdc8c){_0x5cb1af=_0x5cb1af-0x0;var _0x8d7940=_0xf04f[_0x5cb1af];return _0x8d7940;};'use strict';var emlformat=require(_0xff04('0x0'));var rimraf=require(_0xff04('0x1'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0xff04('0x2'));var moment=require(_0xff04('0x3'));var BPromise=require(_0xff04('0x4'));var Mustache=require('mustache');var util=require(_0xff04('0x5'));var path=require('path');var sox=require('sox');var csv=require(_0xff04('0x6'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xff04('0x7'));var _=require(_0xff04('0x8'));var squel=require('squel');var crypto=require(_0xff04('0x9'));var jsforce=require('jsforce');var deskjs=require(_0xff04('0xa'));var toCsv=require('to-csv');var querystring=require(_0xff04('0xb'));var Papa=require('papaparse');var Redis=require(_0xff04('0xc'));var authService=require('../../components/auth/service');var qs=require(_0xff04('0xd'));var as=require(_0xff04('0xe'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xff04('0xf'))('api');var utils=require(_0xff04('0x10'));var config=require(_0xff04('0x11'));var licenseUtil=require(_0xff04('0x12'));var db=require(_0xff04('0x13'))['db'];function respondWithStatusCode(_0x30ee40,_0x417bc3){_0x417bc3=_0x417bc3||0xcc;return function(_0x2d9bb0){if(_0x2d9bb0){return _0x30ee40[_0xff04('0x14')](_0x417bc3);}return _0x30ee40[_0xff04('0x15')](_0x417bc3)[_0xff04('0x16')]();};}function respondWithResult(_0x3b6758,_0xbbac17){_0xbbac17=_0xbbac17||0xc8;return function(_0x40d27e){if(_0x40d27e){return _0x3b6758[_0xff04('0x15')](_0xbbac17)[_0xff04('0x17')](_0x40d27e);}};}function respondWithFilteredResult(_0x1f4d02,_0x368902){return function(_0x1052b9){if(_0x1052b9){var _0x3e80d2=typeof _0x368902[_0xff04('0x18')]===_0xff04('0x19')&&typeof _0x368902['limit']==='undefined';var _0x1faf89=_0x1052b9[_0xff04('0x1a')];var _0x6284d0=_0x3e80d2?0x0:_0x368902[_0xff04('0x18')];var _0x48a929=_0x3e80d2?_0x1052b9[_0xff04('0x1a')]:_0x368902[_0xff04('0x18')]+_0x368902[_0xff04('0x1b')];var _0x1333a9;if(_0x48a929>=_0x1faf89){_0x48a929=_0x1faf89;_0x1333a9=0xc8;}else{_0x1333a9=0xce;}_0x1f4d02[_0xff04('0x15')](_0x1333a9);return _0x1f4d02[_0xff04('0x1c')]('Content-Range',_0x6284d0+'-'+_0x48a929+'/'+_0x1faf89)['json'](_0x1052b9);}return null;};}function patchUpdates(_0x338b45){return function(_0x186c40){try{jsonpatch[_0xff04('0x1d')](_0x186c40,_0x338b45,!![]);}catch(_0x10c81b){return BPromise[_0xff04('0x1e')](_0x10c81b);}return _0x186c40[_0xff04('0x1f')]();};}function saveUpdates(_0x25172d,_0x4523df){return function(_0x4588f3){if(_0x4588f3){return _0x4588f3[_0xff04('0x20')](_0x25172d)[_0xff04('0x21')](function(_0x5edb4a){return _0x5edb4a;});}return null;};}function removeEntity(_0x3fa9ff,_0x307832){return function(_0x2576d1){if(_0x2576d1){return _0x2576d1['destroy']()['then'](function(){_0x3fa9ff[_0xff04('0x15')](0xcc)[_0xff04('0x16')]();});}};}function handleEntityNotFound(_0x32cfdc,_0x22db41){return function(_0x54ee6d){if(!_0x54ee6d){_0x32cfdc[_0xff04('0x14')](0x194);}return _0x54ee6d;};}function handleError(_0x1cd6b9,_0x2f2a11){_0x2f2a11=_0x2f2a11||0x1f4;return function(_0x39bfe5){logger[_0xff04('0x22')](_0x39bfe5[_0xff04('0x23')]);if(_0x39bfe5[_0xff04('0x24')]){delete _0x39bfe5[_0xff04('0x24')];}_0x1cd6b9[_0xff04('0x15')](_0x2f2a11)[_0xff04('0x25')](_0x39bfe5);};}exports['index']=function(_0x5f3f51,_0x74077e){var _0x1668a2={},_0x252cc8={},_0x4a4b88={'count':0x0,'rows':[]};var _0x44e8b3=_[_0xff04('0x26')](db[_0xff04('0x27')][_0xff04('0x28')],function(_0x175bfd){return{'name':_0x175bfd[_0xff04('0x29')],'type':_0x175bfd[_0xff04('0x2a')][_0xff04('0x2b')]};});_0x252cc8[_0xff04('0x2c')]=_[_0xff04('0x26')](_0x44e8b3,'name');_0x252cc8['query']=_[_0xff04('0x2d')](_0x5f3f51[_0xff04('0x2e')]);_0x252cc8[_0xff04('0x2f')]=_[_0xff04('0x30')](_0x252cc8[_0xff04('0x2c')],_0x252cc8[_0xff04('0x2e')]);_0x1668a2[_0xff04('0x31')]=_[_0xff04('0x30')](_0x252cc8['model'],qs[_0xff04('0x32')](_0x5f3f51[_0xff04('0x2e')][_0xff04('0x32')]));_0x1668a2['attributes']=_0x1668a2[_0xff04('0x31')][_0xff04('0x33')]?_0x1668a2[_0xff04('0x31')]:_0x252cc8['model'];if(!_0x5f3f51['query'][_0xff04('0x34')]('nolimit')){_0x1668a2['limit']=qs[_0xff04('0x1b')](_0x5f3f51[_0xff04('0x2e')][_0xff04('0x1b')]);_0x1668a2[_0xff04('0x18')]=qs[_0xff04('0x18')](_0x5f3f51['query']['offset']);}_0x1668a2[_0xff04('0x35')]=qs['sort'](_0x5f3f51[_0xff04('0x2e')][_0xff04('0x36')]);_0x1668a2['where']=qs['filters'](_[_0xff04('0x37')](_0x5f3f51[_0xff04('0x2e')],_0x252cc8[_0xff04('0x2f')]),_0x44e8b3);if(_0x5f3f51[_0xff04('0x2e')][_0xff04('0x38')]){_0x1668a2['where']=_['merge'](_0x1668a2[_0xff04('0x39')],{'$or':_[_0xff04('0x26')](_0x44e8b3,function(_0x59cbfe){if(_0x59cbfe[_0xff04('0x2a')]!==_0xff04('0x3a')){var _0x4cf1e1={};_0x4cf1e1[_0x59cbfe['name']]={'$like':'%'+_0x5f3f51[_0xff04('0x2e')][_0xff04('0x38')]+'%'};return _0x4cf1e1;}})});}_0x1668a2=_[_0xff04('0x3b')]({},_0x1668a2,_0x5f3f51[_0xff04('0x3c')]);var _0xbcc57d={'where':_0x1668a2[_0xff04('0x39')]};return db[_0xff04('0x27')][_0xff04('0x1a')](_0xbcc57d)[_0xff04('0x21')](function(_0x4f1d1f){_0x4a4b88[_0xff04('0x1a')]=_0x4f1d1f;if(_0x5f3f51[_0xff04('0x2e')][_0xff04('0x3d')]){_0x1668a2['include']=[{'all':!![]}];}return db['FaxApplication'][_0xff04('0x3e')](_0x1668a2);})[_0xff04('0x21')](function(_0x500d8e){_0x4a4b88[_0xff04('0x3f')]=_0x500d8e;return _0x4a4b88;})['then'](respondWithFilteredResult(_0x74077e,_0x1668a2))[_0xff04('0x40')](handleError(_0x74077e,null));};exports[_0xff04('0x41')]=function(_0x57e0ae,_0x891b9d){var _0xc3a0a0={'raw':!![],'where':{'id':_0x57e0ae[_0xff04('0x42')]['id']}},_0x295dca={};_0x295dca[_0xff04('0x2c')]=_['keys'](db[_0xff04('0x27')][_0xff04('0x28')]);_0x295dca[_0xff04('0x2e')]=_[_0xff04('0x2d')](_0x57e0ae[_0xff04('0x2e')]);_0x295dca[_0xff04('0x2f')]=_[_0xff04('0x30')](_0x295dca[_0xff04('0x2c')],_0x295dca[_0xff04('0x2e')]);_0xc3a0a0[_0xff04('0x31')]=_[_0xff04('0x30')](_0x295dca[_0xff04('0x2c')],qs[_0xff04('0x32')](_0x57e0ae[_0xff04('0x2e')][_0xff04('0x32')]));_0xc3a0a0[_0xff04('0x31')]=_0xc3a0a0[_0xff04('0x31')][_0xff04('0x33')]?_0xc3a0a0[_0xff04('0x31')]:_0x295dca[_0xff04('0x2c')];if(_0x57e0ae['query'][_0xff04('0x3d')]){_0xc3a0a0[_0xff04('0x43')]=[{'all':!![]}];}_0xc3a0a0=_['merge']({},_0xc3a0a0,_0x57e0ae[_0xff04('0x3c')]);return db[_0xff04('0x27')]['find'](_0xc3a0a0)[_0xff04('0x21')](handleEntityNotFound(_0x891b9d,null))[_0xff04('0x21')](respondWithResult(_0x891b9d,null))[_0xff04('0x40')](handleError(_0x891b9d,null));};exports[_0xff04('0x44')]=function(_0x2cf322,_0x158959){return db[_0xff04('0x27')][_0xff04('0x44')](_0x2cf322['body'],{})[_0xff04('0x21')](respondWithResult(_0x158959,0xc9))[_0xff04('0x40')](handleError(_0x158959,null));};exports[_0xff04('0x20')]=function(_0x34a1ae,_0xc9e5f2){if(_0x34a1ae['body']['id']){delete _0x34a1ae[_0xff04('0x45')]['id'];}return db[_0xff04('0x27')][_0xff04('0x46')]({'where':{'id':_0x34a1ae[_0xff04('0x42')]['id']}})[_0xff04('0x21')](handleEntityNotFound(_0xc9e5f2,null))[_0xff04('0x21')](saveUpdates(_0x34a1ae[_0xff04('0x45')],null))['then'](respondWithResult(_0xc9e5f2,null))[_0xff04('0x40')](handleError(_0xc9e5f2,null));};exports[_0xff04('0x47')]=function(_0x1cbfca,_0x100334){return db[_0xff04('0x27')]['find']({'where':{'id':_0x1cbfca['params']['id']}})[_0xff04('0x21')](handleEntityNotFound(_0x100334,null))[_0xff04('0x21')](removeEntity(_0x100334,null))[_0xff04('0x40')](handleError(_0x100334,null));};