4e432d8886d989c7889b898a4ccd3cf3a6618af2
[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 _0x070f=['options','includeAll','include','rows','catch','show','params','keys','find','create','body','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','util','path','sox','fs-extra','lodash','crypto','jsforce','desk.js','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','undefined','limit','offset','count','Content-Range','apply','reject','save','update','then','destroy','name','map','FaxApplication','rawAttributes','fieldName','type','query','filters','intersection','model','attributes','fields','length','hasOwnProperty','nolimit','sort','pick','filter','merge','where','VIRTUAL'];(function(_0x297eea,_0x5060be){var _0x1c42d2=function(_0x3afff4){while(--_0x3afff4){_0x297eea['push'](_0x297eea['shift']());}};_0x1c42d2(++_0x5060be);}(_0x070f,0x137));var _0xf070=function(_0x140611,_0x433a97){_0x140611=_0x140611-0x0;var _0x4638fc=_0x070f[_0x140611];return _0x4638fc;};'use strict';var emlformat=require(_0xf070('0x0'));var rimraf=require(_0xf070('0x1'));var zipdir=require(_0xf070('0x2'));var jsonpatch=require(_0xf070('0x3'));var rp=require(_0xf070('0x4'));var moment=require(_0xf070('0x5'));var BPromise=require('bluebird');var Mustache=require(_0xf070('0x6'));var util=require(_0xf070('0x7'));var path=require(_0xf070('0x8'));var sox=require(_0xf070('0x9'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xf070('0xa'));var _=require(_0xf070('0xb'));var squel=require('squel');var crypto=require(_0xf070('0xc'));var jsforce=require(_0xf070('0xd'));var deskjs=require(_0xf070('0xe'));var toCsv=require(_0xf070('0xf'));var querystring=require(_0xf070('0x10'));var Papa=require(_0xf070('0x11'));var Redis=require(_0xf070('0x12'));var authService=require(_0xf070('0x13'));var qs=require(_0xf070('0x14'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xf070('0x15'));var logger=require(_0xf070('0x16'))(_0xf070('0x17'));var utils=require(_0xf070('0x18'));var config=require(_0xf070('0x19'));var licenseUtil=require(_0xf070('0x1a'));var db=require(_0xf070('0x1b'))['db'];function respondWithStatusCode(_0x506aa4,_0x22aa5d){_0x22aa5d=_0x22aa5d||0xcc;return function(_0x2c7bc3){if(_0x2c7bc3){return _0x506aa4[_0xf070('0x1c')](_0x22aa5d);}return _0x506aa4[_0xf070('0x1d')](_0x22aa5d)[_0xf070('0x1e')]();};}function respondWithResult(_0x2e61b5,_0x3a5619){_0x3a5619=_0x3a5619||0xc8;return function(_0x99bea3){if(_0x99bea3){return _0x2e61b5['status'](_0x3a5619)[_0xf070('0x1f')](_0x99bea3);}};}function respondWithFilteredResult(_0x1a6fea,_0x10b72a){return function(_0x5dc945){if(_0x5dc945){var _0xa14008=typeof _0x10b72a['offset']===_0xf070('0x20')&&typeof _0x10b72a[_0xf070('0x21')]===_0xf070('0x20');var _0x3aec4d=_0x5dc945['count'];var _0x39f8d6=_0xa14008?0x0:_0x10b72a[_0xf070('0x22')];var _0x6e678b=_0xa14008?_0x5dc945[_0xf070('0x23')]:_0x10b72a[_0xf070('0x22')]+_0x10b72a[_0xf070('0x21')];var _0x2bbbdb;if(_0x6e678b>=_0x3aec4d){_0x6e678b=_0x3aec4d;_0x2bbbdb=0xc8;}else{_0x2bbbdb=0xce;}_0x1a6fea[_0xf070('0x1d')](_0x2bbbdb);return _0x1a6fea['set'](_0xf070('0x24'),_0x39f8d6+'-'+_0x6e678b+'/'+_0x3aec4d)[_0xf070('0x1f')](_0x5dc945);}return null;};}function patchUpdates(_0x45c861){return function(_0x5ef460){try{jsonpatch[_0xf070('0x25')](_0x5ef460,_0x45c861,!![]);}catch(_0x36e9a2){return BPromise[_0xf070('0x26')](_0x36e9a2);}return _0x5ef460[_0xf070('0x27')]();};}function saveUpdates(_0xa72108,_0x38753e){return function(_0x29cca6){if(_0x29cca6){return _0x29cca6[_0xf070('0x28')](_0xa72108)[_0xf070('0x29')](function(_0x3d58cf){return _0x3d58cf;});}return null;};}function removeEntity(_0x2a417b,_0x342fe3){return function(_0x4c5882){if(_0x4c5882){return _0x4c5882[_0xf070('0x2a')]()[_0xf070('0x29')](function(){_0x2a417b['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x4fbd6a,_0x3712b9){return function(_0x171486){if(!_0x171486){_0x4fbd6a[_0xf070('0x1c')](0x194);}return _0x171486;};}function handleError(_0x6b41b3,_0x5b482e){_0x5b482e=_0x5b482e||0x1f4;return function(_0x485fc4){logger['error'](_0x485fc4['stack']);if(_0x485fc4[_0xf070('0x2b')]){delete _0x485fc4[_0xf070('0x2b')];}_0x6b41b3[_0xf070('0x1d')](_0x5b482e)['send'](_0x485fc4);};}exports['index']=function(_0x5e10ae,_0x3b8698){var _0x65ecba={},_0x2390dd={},_0xf811cf={'count':0x0,'rows':[]};var _0x300689=_[_0xf070('0x2c')](db[_0xf070('0x2d')][_0xf070('0x2e')],function(_0x31687a){return{'name':_0x31687a[_0xf070('0x2f')],'type':_0x31687a[_0xf070('0x30')]['key']};});_0x2390dd['model']=_[_0xf070('0x2c')](_0x300689,_0xf070('0x2b'));_0x2390dd[_0xf070('0x31')]=_['keys'](_0x5e10ae[_0xf070('0x31')]);_0x2390dd[_0xf070('0x32')]=_[_0xf070('0x33')](_0x2390dd[_0xf070('0x34')],_0x2390dd[_0xf070('0x31')]);_0x65ecba[_0xf070('0x35')]=_['intersection'](_0x2390dd[_0xf070('0x34')],qs[_0xf070('0x36')](_0x5e10ae[_0xf070('0x31')][_0xf070('0x36')]));_0x65ecba[_0xf070('0x35')]=_0x65ecba[_0xf070('0x35')][_0xf070('0x37')]?_0x65ecba['attributes']:_0x2390dd['model'];if(!_0x5e10ae[_0xf070('0x31')][_0xf070('0x38')](_0xf070('0x39'))){_0x65ecba[_0xf070('0x21')]=qs[_0xf070('0x21')](_0x5e10ae[_0xf070('0x31')]['limit']);_0x65ecba[_0xf070('0x22')]=qs[_0xf070('0x22')](_0x5e10ae[_0xf070('0x31')][_0xf070('0x22')]);}_0x65ecba['order']=qs[_0xf070('0x3a')](_0x5e10ae[_0xf070('0x31')][_0xf070('0x3a')]);_0x65ecba['where']=qs[_0xf070('0x32')](_[_0xf070('0x3b')](_0x5e10ae[_0xf070('0x31')],_0x2390dd[_0xf070('0x32')]),_0x300689);if(_0x5e10ae['query'][_0xf070('0x3c')]){_0x65ecba['where']=_[_0xf070('0x3d')](_0x65ecba[_0xf070('0x3e')],{'$or':_[_0xf070('0x2c')](_0x300689,function(_0x6ea346){if(_0x6ea346[_0xf070('0x30')]!==_0xf070('0x3f')){var _0x1792b9={};_0x1792b9[_0x6ea346['name']]={'$like':'%'+_0x5e10ae[_0xf070('0x31')][_0xf070('0x3c')]+'%'};return _0x1792b9;}})});}_0x65ecba=_[_0xf070('0x3d')]({},_0x65ecba,_0x5e10ae[_0xf070('0x40')]);var _0x310b0c={'where':_0x65ecba[_0xf070('0x3e')]};return db[_0xf070('0x2d')][_0xf070('0x23')](_0x310b0c)[_0xf070('0x29')](function(_0x379a1){_0xf811cf[_0xf070('0x23')]=_0x379a1;if(_0x5e10ae[_0xf070('0x31')][_0xf070('0x41')]){_0x65ecba[_0xf070('0x42')]=[{'all':!![]}];}return db[_0xf070('0x2d')]['findAll'](_0x65ecba);})['then'](function(_0x66603b){_0xf811cf[_0xf070('0x43')]=_0x66603b;return _0xf811cf;})[_0xf070('0x29')](respondWithFilteredResult(_0x3b8698,_0x65ecba))[_0xf070('0x44')](handleError(_0x3b8698,null));};exports[_0xf070('0x45')]=function(_0x2ad79a,_0x27de84){var _0x18be20={'raw':!![],'where':{'id':_0x2ad79a[_0xf070('0x46')]['id']}},_0x1883c8={};_0x1883c8[_0xf070('0x34')]=_['keys'](db[_0xf070('0x2d')][_0xf070('0x2e')]);_0x1883c8[_0xf070('0x31')]=_[_0xf070('0x47')](_0x2ad79a['query']);_0x1883c8[_0xf070('0x32')]=_[_0xf070('0x33')](_0x1883c8[_0xf070('0x34')],_0x1883c8[_0xf070('0x31')]);_0x18be20[_0xf070('0x35')]=_[_0xf070('0x33')](_0x1883c8['model'],qs[_0xf070('0x36')](_0x2ad79a[_0xf070('0x31')]['fields']));_0x18be20['attributes']=_0x18be20[_0xf070('0x35')][_0xf070('0x37')]?_0x18be20[_0xf070('0x35')]:_0x1883c8['model'];if(_0x2ad79a[_0xf070('0x31')][_0xf070('0x41')]){_0x18be20[_0xf070('0x42')]=[{'all':!![]}];}_0x18be20=_[_0xf070('0x3d')]({},_0x18be20,_0x2ad79a['options']);return db[_0xf070('0x2d')][_0xf070('0x48')](_0x18be20)[_0xf070('0x29')](handleEntityNotFound(_0x27de84,null))[_0xf070('0x29')](respondWithResult(_0x27de84,null))[_0xf070('0x44')](handleError(_0x27de84,null));};exports[_0xf070('0x49')]=function(_0x227018,_0x48cf95){return db[_0xf070('0x2d')][_0xf070('0x49')](_0x227018[_0xf070('0x4a')],{})[_0xf070('0x29')](respondWithResult(_0x48cf95,0xc9))[_0xf070('0x44')](handleError(_0x48cf95,null));};exports['update']=function(_0x45e4c7,_0x45c09e){if(_0x45e4c7['body']['id']){delete _0x45e4c7[_0xf070('0x4a')]['id'];}return db[_0xf070('0x2d')][_0xf070('0x48')]({'where':{'id':_0x45e4c7['params']['id']}})['then'](handleEntityNotFound(_0x45c09e,null))[_0xf070('0x29')](saveUpdates(_0x45e4c7[_0xf070('0x4a')],null))[_0xf070('0x29')](respondWithResult(_0x45c09e,null))['catch'](handleError(_0x45c09e,null));};exports['destroy']=function(_0x3a878d,_0x3a7f9c){return db[_0xf070('0x2d')][_0xf070('0x48')]({'where':{'id':_0x3a878d[_0xf070('0x46')]['id']}})['then'](handleEntityNotFound(_0x3a7f9c,null))[_0xf070('0x29')](removeEntity(_0x3a7f9c,null))[_0xf070('0x44')](handleError(_0x3a7f9c,null));};