49e85d5adfaa07e4734b166e0790726fc01ee30b
[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 _0xb6c1=['rawAttributes','length','find','create','body','update','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','path','sox','ejs','fs-extra','lodash','crypto','jsforce','desk.js','querystring','papaparse','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/license/util','sendStatus','status','offset','undefined','limit','count','set','Content-Range','json','reject','save','then','destroy','end','error','stack','name','send','map','FaxApplication','fieldName','type','model','query','keys','filters','attributes','intersection','fields','hasOwnProperty','nolimit','order','sort','where','pick','merge','VIRTUAL','filter','options','includeAll','include','findAll','catch','show','params'];(function(_0x3bf83f,_0x181cac){var _0x22c4a9=function(_0xb3ff0d){while(--_0xb3ff0d){_0x3bf83f['push'](_0x3bf83f['shift']());}};_0x22c4a9(++_0x181cac);}(_0xb6c1,0xe4));var _0x1b6c=function(_0x158176,_0x2ca0bf){_0x158176=_0x158176-0x0;var _0x804444=_0xb6c1[_0x158176];return _0x804444;};'use strict';var emlformat=require(_0x1b6c('0x0'));var rimraf=require(_0x1b6c('0x1'));var zipdir=require(_0x1b6c('0x2'));var jsonpatch=require(_0x1b6c('0x3'));var rp=require(_0x1b6c('0x4'));var moment=require(_0x1b6c('0x5'));var BPromise=require(_0x1b6c('0x6'));var Mustache=require(_0x1b6c('0x7'));var util=require('util');var path=require(_0x1b6c('0x8'));var sox=require(_0x1b6c('0x9'));var csv=require('to-csv');var ejs=require(_0x1b6c('0xa'));var fs=require('fs');var fs_extra=require(_0x1b6c('0xb'));var _=require(_0x1b6c('0xc'));var squel=require('squel');var crypto=require(_0x1b6c('0xd'));var jsforce=require(_0x1b6c('0xe'));var deskjs=require(_0x1b6c('0xf'));var toCsv=require('to-csv');var querystring=require(_0x1b6c('0x10'));var Papa=require(_0x1b6c('0x11'));var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require(_0x1b6c('0x12'));var as=require(_0x1b6c('0x13'));var hardwareService=require(_0x1b6c('0x14'));var logger=require(_0x1b6c('0x15'))('api');var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require(_0x1b6c('0x16'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x241582,_0x200531){_0x200531=_0x200531||0xcc;return function(_0x5766ae){if(_0x5766ae){return _0x241582[_0x1b6c('0x17')](_0x200531);}return _0x241582[_0x1b6c('0x18')](_0x200531)['end']();};}function respondWithResult(_0x567908,_0x12f2b0){_0x12f2b0=_0x12f2b0||0xc8;return function(_0xa5cfa5){if(_0xa5cfa5){return _0x567908['status'](_0x12f2b0)['json'](_0xa5cfa5);}};}function respondWithFilteredResult(_0x5eb008,_0x4e7b0d){return function(_0x12006a){if(_0x12006a){var _0x28274b=typeof _0x4e7b0d[_0x1b6c('0x19')]===_0x1b6c('0x1a')&&typeof _0x4e7b0d[_0x1b6c('0x1b')]==='undefined';var _0x1ef5a0=_0x12006a[_0x1b6c('0x1c')];var _0x29fa0d=_0x28274b?0x0:_0x4e7b0d['offset'];var _0x317cec=_0x28274b?_0x12006a[_0x1b6c('0x1c')]:_0x4e7b0d['offset']+_0x4e7b0d[_0x1b6c('0x1b')];var _0x2a3e69;if(_0x317cec>=_0x1ef5a0){_0x317cec=_0x1ef5a0;_0x2a3e69=0xc8;}else{_0x2a3e69=0xce;}_0x5eb008[_0x1b6c('0x18')](_0x2a3e69);return _0x5eb008[_0x1b6c('0x1d')](_0x1b6c('0x1e'),_0x29fa0d+'-'+_0x317cec+'/'+_0x1ef5a0)[_0x1b6c('0x1f')](_0x12006a);}return null;};}function patchUpdates(_0x380af8){return function(_0x92d078){try{jsonpatch['apply'](_0x92d078,_0x380af8,!![]);}catch(_0x132ff1){return BPromise[_0x1b6c('0x20')](_0x132ff1);}return _0x92d078[_0x1b6c('0x21')]();};}function saveUpdates(_0x39f0eb,_0x4fd4d6){return function(_0x361037){if(_0x361037){return _0x361037['update'](_0x39f0eb)[_0x1b6c('0x22')](function(_0x5ee512){return _0x5ee512;});}return null;};}function removeEntity(_0x2b1cc3,_0x521bc9){return function(_0x4a45ad){if(_0x4a45ad){return _0x4a45ad[_0x1b6c('0x23')]()[_0x1b6c('0x22')](function(){_0x2b1cc3[_0x1b6c('0x18')](0xcc)[_0x1b6c('0x24')]();});}};}function handleEntityNotFound(_0x59c6ff,_0x56e166){return function(_0x1bb3e5){if(!_0x1bb3e5){_0x59c6ff['sendStatus'](0x194);}return _0x1bb3e5;};}function handleError(_0x3c3447,_0x585ade){_0x585ade=_0x585ade||0x1f4;return function(_0x39d5ef){logger[_0x1b6c('0x25')](_0x39d5ef[_0x1b6c('0x26')]);if(_0x39d5ef[_0x1b6c('0x27')]){delete _0x39d5ef['name'];}_0x3c3447[_0x1b6c('0x18')](_0x585ade)[_0x1b6c('0x28')](_0x39d5ef);};}exports['index']=function(_0x479dc9,_0x11a4f8){var _0x5117b2={},_0x330757={},_0x4e835a={'count':0x0,'rows':[]};var _0x1304c3=_[_0x1b6c('0x29')](db[_0x1b6c('0x2a')]['rawAttributes'],function(_0x2c3ed4){return{'name':_0x2c3ed4[_0x1b6c('0x2b')],'type':_0x2c3ed4[_0x1b6c('0x2c')]['key']};});_0x330757[_0x1b6c('0x2d')]=_[_0x1b6c('0x29')](_0x1304c3,'name');_0x330757[_0x1b6c('0x2e')]=_[_0x1b6c('0x2f')](_0x479dc9[_0x1b6c('0x2e')]);_0x330757[_0x1b6c('0x30')]=_['intersection'](_0x330757[_0x1b6c('0x2d')],_0x330757['query']);_0x5117b2[_0x1b6c('0x31')]=_[_0x1b6c('0x32')](_0x330757[_0x1b6c('0x2d')],qs[_0x1b6c('0x33')](_0x479dc9['query']['fields']));_0x5117b2['attributes']=_0x5117b2['attributes']['length']?_0x5117b2[_0x1b6c('0x31')]:_0x330757[_0x1b6c('0x2d')];if(!_0x479dc9[_0x1b6c('0x2e')][_0x1b6c('0x34')](_0x1b6c('0x35'))){_0x5117b2[_0x1b6c('0x1b')]=qs[_0x1b6c('0x1b')](_0x479dc9['query'][_0x1b6c('0x1b')]);_0x5117b2[_0x1b6c('0x19')]=qs[_0x1b6c('0x19')](_0x479dc9[_0x1b6c('0x2e')][_0x1b6c('0x19')]);}_0x5117b2[_0x1b6c('0x36')]=qs[_0x1b6c('0x37')](_0x479dc9['query'][_0x1b6c('0x37')]);_0x5117b2[_0x1b6c('0x38')]=qs[_0x1b6c('0x30')](_[_0x1b6c('0x39')](_0x479dc9[_0x1b6c('0x2e')],_0x330757[_0x1b6c('0x30')]),_0x1304c3);if(_0x479dc9[_0x1b6c('0x2e')]['filter']){_0x5117b2['where']=_[_0x1b6c('0x3a')](_0x5117b2[_0x1b6c('0x38')],{'$or':_[_0x1b6c('0x29')](_0x1304c3,function(_0xf04bba){if(_0xf04bba['type']!==_0x1b6c('0x3b')){var _0x3315ac={};_0x3315ac[_0xf04bba[_0x1b6c('0x27')]]={'$like':'%'+_0x479dc9[_0x1b6c('0x2e')][_0x1b6c('0x3c')]+'%'};return _0x3315ac;}})});}_0x5117b2=_['merge']({},_0x5117b2,_0x479dc9[_0x1b6c('0x3d')]);var _0x4b5447={'where':_0x5117b2[_0x1b6c('0x38')]};return db[_0x1b6c('0x2a')][_0x1b6c('0x1c')](_0x4b5447)['then'](function(_0x40b895){_0x4e835a[_0x1b6c('0x1c')]=_0x40b895;if(_0x479dc9[_0x1b6c('0x2e')][_0x1b6c('0x3e')]){_0x5117b2[_0x1b6c('0x3f')]=[{'all':!![]}];}return db[_0x1b6c('0x2a')][_0x1b6c('0x40')](_0x5117b2);})['then'](function(_0x4e8300){_0x4e835a['rows']=_0x4e8300;return _0x4e835a;})[_0x1b6c('0x22')](respondWithFilteredResult(_0x11a4f8,_0x5117b2))[_0x1b6c('0x41')](handleError(_0x11a4f8,null));};exports[_0x1b6c('0x42')]=function(_0x553d25,_0x452059){var _0x50f2ec={'raw':!![],'where':{'id':_0x553d25[_0x1b6c('0x43')]['id']}},_0x4cd043={};_0x4cd043[_0x1b6c('0x2d')]=_[_0x1b6c('0x2f')](db[_0x1b6c('0x2a')][_0x1b6c('0x44')]);_0x4cd043[_0x1b6c('0x2e')]=_[_0x1b6c('0x2f')](_0x553d25[_0x1b6c('0x2e')]);_0x4cd043[_0x1b6c('0x30')]=_['intersection'](_0x4cd043[_0x1b6c('0x2d')],_0x4cd043[_0x1b6c('0x2e')]);_0x50f2ec['attributes']=_['intersection'](_0x4cd043[_0x1b6c('0x2d')],qs[_0x1b6c('0x33')](_0x553d25[_0x1b6c('0x2e')][_0x1b6c('0x33')]));_0x50f2ec['attributes']=_0x50f2ec['attributes'][_0x1b6c('0x45')]?_0x50f2ec['attributes']:_0x4cd043[_0x1b6c('0x2d')];if(_0x553d25[_0x1b6c('0x2e')][_0x1b6c('0x3e')]){_0x50f2ec['include']=[{'all':!![]}];}_0x50f2ec=_[_0x1b6c('0x3a')]({},_0x50f2ec,_0x553d25[_0x1b6c('0x3d')]);return db[_0x1b6c('0x2a')][_0x1b6c('0x46')](_0x50f2ec)[_0x1b6c('0x22')](handleEntityNotFound(_0x452059,null))['then'](respondWithResult(_0x452059,null))['catch'](handleError(_0x452059,null));};exports[_0x1b6c('0x47')]=function(_0xb53533,_0x14961f){return db[_0x1b6c('0x2a')]['create'](_0xb53533[_0x1b6c('0x48')],{})[_0x1b6c('0x22')](respondWithResult(_0x14961f,0xc9))[_0x1b6c('0x41')](handleError(_0x14961f,null));};exports[_0x1b6c('0x49')]=function(_0x378d20,_0x1644f5){if(_0x378d20[_0x1b6c('0x48')]['id']){delete _0x378d20[_0x1b6c('0x48')]['id'];}return db[_0x1b6c('0x2a')][_0x1b6c('0x46')]({'where':{'id':_0x378d20['params']['id']}})[_0x1b6c('0x22')](handleEntityNotFound(_0x1644f5,null))[_0x1b6c('0x22')](saveUpdates(_0x378d20[_0x1b6c('0x48')],null))[_0x1b6c('0x22')](respondWithResult(_0x1644f5,null))[_0x1b6c('0x41')](handleError(_0x1644f5,null));};exports['destroy']=function(_0x4123cc,_0x51720a){return db[_0x1b6c('0x2a')]['find']({'where':{'id':_0x4123cc[_0x1b6c('0x43')]['id']}})[_0x1b6c('0x22')](handleEntityNotFound(_0x51720a,null))[_0x1b6c('0x22')](removeEntity(_0x51720a,null))[_0x1b6c('0x41')](handleError(_0x51720a,null));};