Built motion from commit (unavailable).|2.4.20
[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 _0xa37e=['includeAll','findAll','show','params','keys','include','find','catch','create','body','destroy','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','util','path','sox','lodash','jsforce','desk.js','to-csv','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/logger','api','../../config/utils','../../mysqldb','sendStatus','status','json','count','offset','limit','set','Content-Range','apply','reject','save','update','then','end','stack','name','send','index','map','FaxApplication','rawAttributes','fieldName','type','key','model','query','attributes','intersection','fields','length','nolimit','order','sort','where','filters','pick','filter','merge','options'];(function(_0x83a6e2,_0x255d1a){var _0x255e9f=function(_0x39f38d){while(--_0x39f38d){_0x83a6e2['push'](_0x83a6e2['shift']());}};_0x255e9f(++_0x255d1a);}(_0xa37e,0x97));var _0xea37=function(_0xef3b3a,_0x365898){_0xef3b3a=_0xef3b3a-0x0;var _0x49684b=_0xa37e[_0xef3b3a];return _0x49684b;};'use strict';var pdf=require('html-pdf');var emlformat=require('eml-format');var rimraf=require(_0xea37('0x0'));var zipdir=require(_0xea37('0x1'));var jsonpatch=require(_0xea37('0x2'));var rp=require(_0xea37('0x3'));var moment=require('moment');var BPromise=require(_0xea37('0x4'));var Mustache=require('mustache');var util=require(_0xea37('0x5'));var path=require(_0xea37('0x6'));var sox=require(_0xea37('0x7'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var _=require(_0xea37('0x8'));var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0xea37('0x9'));var deskjs=require(_0xea37('0xa'));var toCsv=require(_0xea37('0xb'));var querystring=require(_0xea37('0xc'));var Papa=require('papaparse');var Redis=require(_0xea37('0xd'));var authService=require(_0xea37('0xe'));var qs=require(_0xea37('0xf'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require(_0xea37('0x10'))(_0xea37('0x11'));var utils=require(_0xea37('0x12'));var config=require('../../config/environment');var db=require(_0xea37('0x13'))['db'];function respondWithStatusCode(_0x2a0460,_0x2a2bcd){_0x2a2bcd=_0x2a2bcd||0xcc;return function(_0x589a61){if(_0x589a61){return _0x2a0460[_0xea37('0x14')](_0x2a2bcd);}return _0x2a0460[_0xea37('0x15')](_0x2a2bcd)['end']();};}function respondWithResult(_0x41e9be,_0x556a64){_0x556a64=_0x556a64||0xc8;return function(_0xd7d4e7){if(_0xd7d4e7){return _0x41e9be['status'](_0x556a64)[_0xea37('0x16')](_0xd7d4e7);}};}function respondWithFilteredResult(_0x138ff4,_0x168e80){return function(_0x46aaf0){if(_0x46aaf0){var _0x5b38aa=_0x46aaf0[_0xea37('0x17')],_0x18e4b8=_0x168e80['offset'],_0x58f979=_0x168e80[_0xea37('0x18')]+_0x168e80[_0xea37('0x19')],_0x49604a;if(_0x58f979>=_0x5b38aa){_0x58f979=_0x5b38aa;_0x49604a=0xc8;}else{_0x49604a=0xce;}_0x138ff4['status'](_0x49604a);return _0x138ff4[_0xea37('0x1a')](_0xea37('0x1b'),_0x18e4b8+'-'+_0x58f979+'/'+_0x5b38aa)['json'](_0x46aaf0);}return null;};}function patchUpdates(_0x786ee5){return function(_0x3f5ebc){try{jsonpatch[_0xea37('0x1c')](_0x3f5ebc,_0x786ee5,!![]);}catch(_0x4063ab){return BPromise[_0xea37('0x1d')](_0x4063ab);}return _0x3f5ebc[_0xea37('0x1e')]();};}function saveUpdates(_0x121812,_0x238567){return function(_0x28ed44){if(_0x28ed44){return _0x28ed44[_0xea37('0x1f')](_0x121812)['then'](function(_0x23bb57){return _0x23bb57;});}return null;};}function removeEntity(_0x2a81f5,_0x356f04){return function(_0x536eff){if(_0x536eff){return _0x536eff['destroy']()[_0xea37('0x20')](function(){_0x2a81f5[_0xea37('0x15')](0xcc)[_0xea37('0x21')]();});}};}function handleEntityNotFound(_0x4302ca,_0x4996e9){return function(_0x25042e){if(!_0x25042e){_0x4302ca['sendStatus'](0x194);}return _0x25042e;};}function handleError(_0x5907ce,_0x5503f1){_0x5503f1=_0x5503f1||0x1f4;return function(_0x32c116){logger['error'](_0x32c116[_0xea37('0x22')]);if(_0x32c116[_0xea37('0x23')]){delete _0x32c116[_0xea37('0x23')];}_0x5907ce[_0xea37('0x15')](_0x5503f1)[_0xea37('0x24')](_0x32c116);};}exports[_0xea37('0x25')]=function(_0x49cb6c,_0x57a7cc){var _0x55880c={},_0x477e25={},_0x3e272e={'count':0x0,'rows':[]};var _0x4ffcf1=_[_0xea37('0x26')](db[_0xea37('0x27')][_0xea37('0x28')],function(_0x4e2a65){return{'name':_0x4e2a65[_0xea37('0x29')],'type':_0x4e2a65[_0xea37('0x2a')][_0xea37('0x2b')]};});_0x477e25[_0xea37('0x2c')]=_['map'](_0x4ffcf1,_0xea37('0x23'));_0x477e25['query']=_['keys'](_0x49cb6c[_0xea37('0x2d')]);_0x477e25['filters']=_['intersection'](_0x477e25['model'],_0x477e25[_0xea37('0x2d')]);_0x55880c[_0xea37('0x2e')]=_[_0xea37('0x2f')](_0x477e25[_0xea37('0x2c')],qs[_0xea37('0x30')](_0x49cb6c[_0xea37('0x2d')]['fields']));_0x55880c[_0xea37('0x2e')]=_0x55880c[_0xea37('0x2e')][_0xea37('0x31')]?_0x55880c[_0xea37('0x2e')]:_0x477e25[_0xea37('0x2c')];if(!_0x49cb6c[_0xea37('0x2d')]['hasOwnProperty'](_0xea37('0x32'))){_0x55880c['limit']=qs[_0xea37('0x19')](_0x49cb6c[_0xea37('0x2d')][_0xea37('0x19')]);_0x55880c[_0xea37('0x18')]=qs[_0xea37('0x18')](_0x49cb6c[_0xea37('0x2d')][_0xea37('0x18')]);}_0x55880c[_0xea37('0x33')]=qs['sort'](_0x49cb6c[_0xea37('0x2d')][_0xea37('0x34')]);_0x55880c[_0xea37('0x35')]=qs[_0xea37('0x36')](_[_0xea37('0x37')](_0x49cb6c[_0xea37('0x2d')],_0x477e25['filters']));if(_0x49cb6c['query']['filter']){_0x55880c[_0xea37('0x35')]=_['merge'](_0x55880c[_0xea37('0x35')],{'$or':_['map'](_0x4ffcf1,function(_0x5e91ef){if(_0x5e91ef['type']!=='VIRTUAL'){var _0x3ceede={};_0x3ceede[_0x5e91ef[_0xea37('0x23')]]={'$like':'%'+_0x49cb6c[_0xea37('0x2d')][_0xea37('0x38')]+'%'};return _0x3ceede;}})});}_0x55880c=_[_0xea37('0x39')]({},_0x55880c,_0x49cb6c[_0xea37('0x3a')]);var _0x18da6e={'where':_0x55880c[_0xea37('0x35')]};return db[_0xea37('0x27')]['count'](_0x18da6e)[_0xea37('0x20')](function(_0x565c66){_0x3e272e[_0xea37('0x17')]=_0x565c66;if(_0x49cb6c[_0xea37('0x2d')][_0xea37('0x3b')]){_0x55880c['include']=[{'all':!![]}];}return db[_0xea37('0x27')][_0xea37('0x3c')](_0x55880c);})[_0xea37('0x20')](function(_0x457b77){_0x3e272e['rows']=_0x457b77;return _0x3e272e;})[_0xea37('0x20')](respondWithFilteredResult(_0x57a7cc,_0x55880c))['catch'](handleError(_0x57a7cc,null));};exports[_0xea37('0x3d')]=function(_0x383101,_0x30c247){var _0x847051={'raw':!![],'where':{'id':_0x383101[_0xea37('0x3e')]['id']}},_0x3c1b8a={};_0x3c1b8a['model']=_[_0xea37('0x3f')](db[_0xea37('0x27')]['rawAttributes']);_0x3c1b8a[_0xea37('0x2d')]=_[_0xea37('0x3f')](_0x383101[_0xea37('0x2d')]);_0x3c1b8a[_0xea37('0x36')]=_[_0xea37('0x2f')](_0x3c1b8a[_0xea37('0x2c')],_0x3c1b8a[_0xea37('0x2d')]);_0x847051[_0xea37('0x2e')]=_[_0xea37('0x2f')](_0x3c1b8a[_0xea37('0x2c')],qs[_0xea37('0x30')](_0x383101[_0xea37('0x2d')][_0xea37('0x30')]));_0x847051[_0xea37('0x2e')]=_0x847051[_0xea37('0x2e')][_0xea37('0x31')]?_0x847051[_0xea37('0x2e')]:_0x3c1b8a['model'];if(_0x383101[_0xea37('0x2d')][_0xea37('0x3b')]){_0x847051[_0xea37('0x40')]=[{'all':!![]}];}_0x847051=_[_0xea37('0x39')]({},_0x847051,_0x383101[_0xea37('0x3a')]);return db['FaxApplication'][_0xea37('0x41')](_0x847051)[_0xea37('0x20')](handleEntityNotFound(_0x30c247,null))[_0xea37('0x20')](respondWithResult(_0x30c247,null))[_0xea37('0x42')](handleError(_0x30c247,null));};exports[_0xea37('0x43')]=function(_0x1124cf,_0x4f3222){return db[_0xea37('0x27')][_0xea37('0x43')](_0x1124cf[_0xea37('0x44')],{})[_0xea37('0x20')](respondWithResult(_0x4f3222,0xc9))[_0xea37('0x42')](handleError(_0x4f3222,null));};exports[_0xea37('0x1f')]=function(_0x2cd612,_0x3dd82b){if(_0x2cd612['body']['id']){delete _0x2cd612[_0xea37('0x44')]['id'];}return db[_0xea37('0x27')]['find']({'where':{'id':_0x2cd612[_0xea37('0x3e')]['id']}})[_0xea37('0x20')](handleEntityNotFound(_0x3dd82b,null))[_0xea37('0x20')](saveUpdates(_0x2cd612[_0xea37('0x44')],null))[_0xea37('0x20')](respondWithResult(_0x3dd82b,null))[_0xea37('0x42')](handleError(_0x3dd82b,null));};exports[_0xea37('0x45')]=function(_0x174a77,_0x483d1a){return db[_0xea37('0x27')]['find']({'where':{'id':_0x174a77[_0xea37('0x3e')]['id']}})['then'](handleEntityNotFound(_0x483d1a,null))[_0xea37('0x20')](removeEntity(_0x483d1a,null))[_0xea37('0x42')](handleError(_0x483d1a,null));};