Built motion from commit d5e4af8c.|2.6.23
[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 _0xbafb=['FaxApplication','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','VIRTUAL','merge','includeAll','include','findAll','rows','catch','show','find','create','body','destroy','params','eml-format','zip-dir','fast-json-patch','moment','util','path','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','to-csv','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','end','status','undefined','limit','count','offset','Content-Range','json','apply','reject','update','then','stack','name','send','index','map'];(function(_0x1c8c28,_0x3ee093){var _0x1f59b4=function(_0x29bcc0){while(--_0x29bcc0){_0x1c8c28['push'](_0x1c8c28['shift']());}};_0x1f59b4(++_0x3ee093);}(_0xbafb,0x19d));var _0xbbaf=function(_0x2d2013,_0x4028b8){_0x2d2013=_0x2d2013-0x0;var _0x5b31b6=_0xbafb[_0x2d2013];return _0x5b31b6;};'use strict';var emlformat=require(_0xbbaf('0x0'));var rimraf=require('rimraf');var zipdir=require(_0xbbaf('0x1'));var jsonpatch=require(_0xbbaf('0x2'));var rp=require('request-promise');var moment=require(_0xbbaf('0x3'));var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0xbbaf('0x4'));var path=require(_0xbbaf('0x5'));var sox=require('sox');var csv=require('to-csv');var ejs=require(_0xbbaf('0x6'));var fs=require('fs');var fs_extra=require(_0xbbaf('0x7'));var _=require(_0xbbaf('0x8'));var squel=require(_0xbbaf('0x9'));var crypto=require(_0xbbaf('0xa'));var jsforce=require(_0xbbaf('0xb'));var deskjs=require(_0xbbaf('0xc'));var toCsv=require(_0xbbaf('0xd'));var querystring=require(_0xbbaf('0xe'));var Papa=require(_0xbbaf('0xf'));var Redis=require('ioredis');var authService=require(_0xbbaf('0x10'));var qs=require(_0xbbaf('0x11'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xbbaf('0x12'));var logger=require(_0xbbaf('0x13'))(_0xbbaf('0x14'));var utils=require(_0xbbaf('0x15'));var config=require(_0xbbaf('0x16'));var licenseUtil=require(_0xbbaf('0x17'));var db=require(_0xbbaf('0x18'))['db'];function respondWithStatusCode(_0x17e520,_0x12775a){_0x12775a=_0x12775a||0xcc;return function(_0x20d086){if(_0x20d086){return _0x17e520[_0xbbaf('0x19')](_0x12775a);}return _0x17e520['status'](_0x12775a)[_0xbbaf('0x1a')]();};}function respondWithResult(_0x5d0070,_0x4ff322){_0x4ff322=_0x4ff322||0xc8;return function(_0x1c307d){if(_0x1c307d){return _0x5d0070[_0xbbaf('0x1b')](_0x4ff322)['json'](_0x1c307d);}};}function respondWithFilteredResult(_0x20b34f,_0x294caa){return function(_0x193884){if(_0x193884){var _0x1f13b3=typeof _0x294caa['offset']===_0xbbaf('0x1c')&&typeof _0x294caa[_0xbbaf('0x1d')]===_0xbbaf('0x1c');var _0x5edafe=_0x193884[_0xbbaf('0x1e')];var _0x40eb97=_0x1f13b3?0x0:_0x294caa[_0xbbaf('0x1f')];var _0xaf1cd0=_0x1f13b3?_0x193884[_0xbbaf('0x1e')]:_0x294caa[_0xbbaf('0x1f')]+_0x294caa[_0xbbaf('0x1d')];var _0x1321a3;if(_0xaf1cd0>=_0x5edafe){_0xaf1cd0=_0x5edafe;_0x1321a3=0xc8;}else{_0x1321a3=0xce;}_0x20b34f[_0xbbaf('0x1b')](_0x1321a3);return _0x20b34f['set'](_0xbbaf('0x20'),_0x40eb97+'-'+_0xaf1cd0+'/'+_0x5edafe)[_0xbbaf('0x21')](_0x193884);}return null;};}function patchUpdates(_0x47700b){return function(_0x10afdb){try{jsonpatch[_0xbbaf('0x22')](_0x10afdb,_0x47700b,!![]);}catch(_0x35f6d){return BPromise[_0xbbaf('0x23')](_0x35f6d);}return _0x10afdb['save']();};}function saveUpdates(_0x4e54c2,_0x1bc1c4){return function(_0xd65fd8){if(_0xd65fd8){return _0xd65fd8[_0xbbaf('0x24')](_0x4e54c2)[_0xbbaf('0x25')](function(_0x2a1c64){return _0x2a1c64;});}return null;};}function removeEntity(_0x349d9c,_0x469fc4){return function(_0x18820e){if(_0x18820e){return _0x18820e['destroy']()[_0xbbaf('0x25')](function(){_0x349d9c['status'](0xcc)[_0xbbaf('0x1a')]();});}};}function handleEntityNotFound(_0xe7b060,_0x4a7048){return function(_0x49649f){if(!_0x49649f){_0xe7b060[_0xbbaf('0x19')](0x194);}return _0x49649f;};}function handleError(_0xceb6d8,_0x4c26e1){_0x4c26e1=_0x4c26e1||0x1f4;return function(_0x20f678){logger['error'](_0x20f678[_0xbbaf('0x26')]);if(_0x20f678[_0xbbaf('0x27')]){delete _0x20f678[_0xbbaf('0x27')];}_0xceb6d8[_0xbbaf('0x1b')](_0x4c26e1)[_0xbbaf('0x28')](_0x20f678);};}exports[_0xbbaf('0x29')]=function(_0x14b623,_0x4477db){var _0x17633a={},_0x2187a4={},_0x1f11e7={'count':0x0,'rows':[]};var _0x50497e=_[_0xbbaf('0x2a')](db[_0xbbaf('0x2b')][_0xbbaf('0x2c')],function(_0x1f7b7c){return{'name':_0x1f7b7c[_0xbbaf('0x2d')],'type':_0x1f7b7c[_0xbbaf('0x2e')][_0xbbaf('0x2f')]};});_0x2187a4[_0xbbaf('0x30')]=_[_0xbbaf('0x2a')](_0x50497e,_0xbbaf('0x27'));_0x2187a4[_0xbbaf('0x31')]=_[_0xbbaf('0x32')](_0x14b623[_0xbbaf('0x31')]);_0x2187a4[_0xbbaf('0x33')]=_[_0xbbaf('0x34')](_0x2187a4[_0xbbaf('0x30')],_0x2187a4[_0xbbaf('0x31')]);_0x17633a['attributes']=_[_0xbbaf('0x34')](_0x2187a4[_0xbbaf('0x30')],qs[_0xbbaf('0x35')](_0x14b623['query']['fields']));_0x17633a[_0xbbaf('0x36')]=_0x17633a[_0xbbaf('0x36')][_0xbbaf('0x37')]?_0x17633a[_0xbbaf('0x36')]:_0x2187a4['model'];if(!_0x14b623[_0xbbaf('0x31')][_0xbbaf('0x38')](_0xbbaf('0x39'))){_0x17633a[_0xbbaf('0x1d')]=qs[_0xbbaf('0x1d')](_0x14b623[_0xbbaf('0x31')][_0xbbaf('0x1d')]);_0x17633a[_0xbbaf('0x1f')]=qs[_0xbbaf('0x1f')](_0x14b623[_0xbbaf('0x31')][_0xbbaf('0x1f')]);}_0x17633a[_0xbbaf('0x3a')]=qs['sort'](_0x14b623['query'][_0xbbaf('0x3b')]);_0x17633a[_0xbbaf('0x3c')]=qs['filters'](_[_0xbbaf('0x3d')](_0x14b623['query'],_0x2187a4[_0xbbaf('0x33')]),_0x50497e);if(_0x14b623['query'][_0xbbaf('0x3e')]){_0x17633a[_0xbbaf('0x3c')]=_['merge'](_0x17633a[_0xbbaf('0x3c')],{'$or':_[_0xbbaf('0x2a')](_0x50497e,function(_0x48d20e){if(_0x48d20e['type']!==_0xbbaf('0x3f')){var _0x3c2fcd={};_0x3c2fcd[_0x48d20e[_0xbbaf('0x27')]]={'$like':'%'+_0x14b623[_0xbbaf('0x31')][_0xbbaf('0x3e')]+'%'};return _0x3c2fcd;}})});}_0x17633a=_[_0xbbaf('0x40')]({},_0x17633a,_0x14b623['options']);var _0x32dba6={'where':_0x17633a[_0xbbaf('0x3c')]};return db[_0xbbaf('0x2b')][_0xbbaf('0x1e')](_0x32dba6)['then'](function(_0x4e6d92){_0x1f11e7[_0xbbaf('0x1e')]=_0x4e6d92;if(_0x14b623['query'][_0xbbaf('0x41')]){_0x17633a[_0xbbaf('0x42')]=[{'all':!![]}];}return db[_0xbbaf('0x2b')][_0xbbaf('0x43')](_0x17633a);})[_0xbbaf('0x25')](function(_0xe58e97){_0x1f11e7[_0xbbaf('0x44')]=_0xe58e97;return _0x1f11e7;})[_0xbbaf('0x25')](respondWithFilteredResult(_0x4477db,_0x17633a))[_0xbbaf('0x45')](handleError(_0x4477db,null));};exports[_0xbbaf('0x46')]=function(_0x30837a,_0x907f7e){var _0x32a5f8={'raw':!![],'where':{'id':_0x30837a['params']['id']}},_0x421a4b={};_0x421a4b[_0xbbaf('0x30')]=_[_0xbbaf('0x32')](db['FaxApplication'][_0xbbaf('0x2c')]);_0x421a4b['query']=_['keys'](_0x30837a[_0xbbaf('0x31')]);_0x421a4b[_0xbbaf('0x33')]=_[_0xbbaf('0x34')](_0x421a4b[_0xbbaf('0x30')],_0x421a4b[_0xbbaf('0x31')]);_0x32a5f8[_0xbbaf('0x36')]=_[_0xbbaf('0x34')](_0x421a4b[_0xbbaf('0x30')],qs[_0xbbaf('0x35')](_0x30837a['query'][_0xbbaf('0x35')]));_0x32a5f8[_0xbbaf('0x36')]=_0x32a5f8[_0xbbaf('0x36')]['length']?_0x32a5f8[_0xbbaf('0x36')]:_0x421a4b[_0xbbaf('0x30')];if(_0x30837a[_0xbbaf('0x31')]['includeAll']){_0x32a5f8[_0xbbaf('0x42')]=[{'all':!![]}];}_0x32a5f8=_[_0xbbaf('0x40')]({},_0x32a5f8,_0x30837a['options']);return db['FaxApplication'][_0xbbaf('0x47')](_0x32a5f8)[_0xbbaf('0x25')](handleEntityNotFound(_0x907f7e,null))['then'](respondWithResult(_0x907f7e,null))['catch'](handleError(_0x907f7e,null));};exports[_0xbbaf('0x48')]=function(_0x2beacc,_0x5c9a4e){return db[_0xbbaf('0x2b')][_0xbbaf('0x48')](_0x2beacc[_0xbbaf('0x49')],{})[_0xbbaf('0x25')](respondWithResult(_0x5c9a4e,0xc9))['catch'](handleError(_0x5c9a4e,null));};exports[_0xbbaf('0x24')]=function(_0x4a778e,_0x362da9){if(_0x4a778e['body']['id']){delete _0x4a778e['body']['id'];}return db['FaxApplication'][_0xbbaf('0x47')]({'where':{'id':_0x4a778e['params']['id']}})[_0xbbaf('0x25')](handleEntityNotFound(_0x362da9,null))[_0xbbaf('0x25')](saveUpdates(_0x4a778e[_0xbbaf('0x49')],null))[_0xbbaf('0x25')](respondWithResult(_0x362da9,null))['catch'](handleError(_0x362da9,null));};exports[_0xbbaf('0x4a')]=function(_0x3fd52a,_0x277d62){return db[_0xbbaf('0x2b')][_0xbbaf('0x47')]({'where':{'id':_0x3fd52a[_0xbbaf('0x4b')]['id']}})[_0xbbaf('0x25')](handleEntityNotFound(_0x277d62,null))['then'](removeEntity(_0x277d62,null))[_0xbbaf('0x45')](handleError(_0x277d62,null));};