Built motion from commit (unavailable).|2.5.31
[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 _0xfe88=['fs-extra','squel','crypto','querystring','papaparse','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','undefined','limit','offset','count','set','Content-Range','reject','save','update','then','destroy','stack','name','send','FaxApplication','rawAttributes','fieldName','type','key','model','map','query','keys','intersection','fields','attributes','length','hasOwnProperty','nolimit','order','sort','where','filters','pick','filter','VIRTUAL','merge','include','findAll','rows','catch','show','params','includeAll','options','find','create','body','eml-format','rimraf','request-promise','moment','bluebird','sox','to-csv'];(function(_0x5c7221,_0x2867ff){var _0x34ff4a=function(_0x49dfa2){while(--_0x49dfa2){_0x5c7221['push'](_0x5c7221['shift']());}};_0x34ff4a(++_0x2867ff);}(_0xfe88,0x1af));var _0x8fe8=function(_0x469a3c,_0x5ebc10){_0x469a3c=_0x469a3c-0x0;var _0x968f4=_0xfe88[_0x469a3c];return _0x968f4;};'use strict';var emlformat=require(_0x8fe8('0x0'));var rimraf=require(_0x8fe8('0x1'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0x8fe8('0x2'));var moment=require(_0x8fe8('0x3'));var BPromise=require(_0x8fe8('0x4'));var Mustache=require('mustache');var util=require('util');var path=require('path');var sox=require(_0x8fe8('0x5'));var csv=require(_0x8fe8('0x6'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x8fe8('0x7'));var _=require('lodash');var squel=require(_0x8fe8('0x8'));var crypto=require(_0x8fe8('0x9'));var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0x8fe8('0x6'));var querystring=require(_0x8fe8('0xa'));var Papa=require(_0x8fe8('0xb'));var Redis=require('ioredis');var authService=require(_0x8fe8('0xc'));var qs=require('../../components/parsers/qs');var as=require(_0x8fe8('0xd'));var hardwareService=require(_0x8fe8('0xe'));var logger=require(_0x8fe8('0xf'))(_0x8fe8('0x10'));var utils=require(_0x8fe8('0x11'));var config=require(_0x8fe8('0x12'));var licenseUtil=require(_0x8fe8('0x13'));var db=require(_0x8fe8('0x14'))['db'];function respondWithStatusCode(_0x5265fa,_0x345040){_0x345040=_0x345040||0xcc;return function(_0x5860d0){if(_0x5860d0){return _0x5265fa[_0x8fe8('0x15')](_0x345040);}return _0x5265fa[_0x8fe8('0x16')](_0x345040)[_0x8fe8('0x17')]();};}function respondWithResult(_0x5cee6c,_0x2886b6){_0x2886b6=_0x2886b6||0xc8;return function(_0x4165b0){if(_0x4165b0){return _0x5cee6c[_0x8fe8('0x16')](_0x2886b6)[_0x8fe8('0x18')](_0x4165b0);}};}function respondWithFilteredResult(_0x569935,_0x4cffc0){return function(_0x37e8ac){if(_0x37e8ac){var _0x32b10e=typeof _0x4cffc0['offset']===_0x8fe8('0x19')&&typeof _0x4cffc0[_0x8fe8('0x1a')]===_0x8fe8('0x19');var _0x562d82=_0x37e8ac['count'];var _0x4cefcb=_0x32b10e?0x0:_0x4cffc0[_0x8fe8('0x1b')];var _0x13d623=_0x32b10e?_0x37e8ac[_0x8fe8('0x1c')]:_0x4cffc0[_0x8fe8('0x1b')]+_0x4cffc0[_0x8fe8('0x1a')];var _0x34c92d;if(_0x13d623>=_0x562d82){_0x13d623=_0x562d82;_0x34c92d=0xc8;}else{_0x34c92d=0xce;}_0x569935['status'](_0x34c92d);return _0x569935[_0x8fe8('0x1d')](_0x8fe8('0x1e'),_0x4cefcb+'-'+_0x13d623+'/'+_0x562d82)[_0x8fe8('0x18')](_0x37e8ac);}return null;};}function patchUpdates(_0x56eb7a){return function(_0x9c8bf2){try{jsonpatch['apply'](_0x9c8bf2,_0x56eb7a,!![]);}catch(_0x441cb0){return BPromise[_0x8fe8('0x1f')](_0x441cb0);}return _0x9c8bf2[_0x8fe8('0x20')]();};}function saveUpdates(_0x4a270a,_0x15be0f){return function(_0x4b063a){if(_0x4b063a){return _0x4b063a[_0x8fe8('0x21')](_0x4a270a)[_0x8fe8('0x22')](function(_0x1ca097){return _0x1ca097;});}return null;};}function removeEntity(_0x15a75f,_0x2856ac){return function(_0x345b49){if(_0x345b49){return _0x345b49[_0x8fe8('0x23')]()[_0x8fe8('0x22')](function(){_0x15a75f[_0x8fe8('0x16')](0xcc)[_0x8fe8('0x17')]();});}};}function handleEntityNotFound(_0x4cfe6d,_0x55ef9b){return function(_0x2b5f1a){if(!_0x2b5f1a){_0x4cfe6d[_0x8fe8('0x15')](0x194);}return _0x2b5f1a;};}function handleError(_0x2de618,_0x585aaa){_0x585aaa=_0x585aaa||0x1f4;return function(_0x2670db){logger['error'](_0x2670db[_0x8fe8('0x24')]);if(_0x2670db[_0x8fe8('0x25')]){delete _0x2670db[_0x8fe8('0x25')];}_0x2de618[_0x8fe8('0x16')](_0x585aaa)[_0x8fe8('0x26')](_0x2670db);};}exports['index']=function(_0x402781,_0x1cd21f){var _0x5a9123={},_0x141e1b={},_0x150e08={'count':0x0,'rows':[]};var _0x4ead6e=_['map'](db[_0x8fe8('0x27')][_0x8fe8('0x28')],function(_0x2d533a){return{'name':_0x2d533a[_0x8fe8('0x29')],'type':_0x2d533a[_0x8fe8('0x2a')][_0x8fe8('0x2b')]};});_0x141e1b[_0x8fe8('0x2c')]=_[_0x8fe8('0x2d')](_0x4ead6e,_0x8fe8('0x25'));_0x141e1b[_0x8fe8('0x2e')]=_[_0x8fe8('0x2f')](_0x402781[_0x8fe8('0x2e')]);_0x141e1b['filters']=_[_0x8fe8('0x30')](_0x141e1b[_0x8fe8('0x2c')],_0x141e1b[_0x8fe8('0x2e')]);_0x5a9123['attributes']=_['intersection'](_0x141e1b[_0x8fe8('0x2c')],qs[_0x8fe8('0x31')](_0x402781[_0x8fe8('0x2e')][_0x8fe8('0x31')]));_0x5a9123[_0x8fe8('0x32')]=_0x5a9123[_0x8fe8('0x32')][_0x8fe8('0x33')]?_0x5a9123[_0x8fe8('0x32')]:_0x141e1b[_0x8fe8('0x2c')];if(!_0x402781[_0x8fe8('0x2e')][_0x8fe8('0x34')](_0x8fe8('0x35'))){_0x5a9123[_0x8fe8('0x1a')]=qs[_0x8fe8('0x1a')](_0x402781[_0x8fe8('0x2e')][_0x8fe8('0x1a')]);_0x5a9123[_0x8fe8('0x1b')]=qs[_0x8fe8('0x1b')](_0x402781[_0x8fe8('0x2e')][_0x8fe8('0x1b')]);}_0x5a9123[_0x8fe8('0x36')]=qs['sort'](_0x402781[_0x8fe8('0x2e')][_0x8fe8('0x37')]);_0x5a9123[_0x8fe8('0x38')]=qs[_0x8fe8('0x39')](_[_0x8fe8('0x3a')](_0x402781[_0x8fe8('0x2e')],_0x141e1b[_0x8fe8('0x39')]),_0x4ead6e);if(_0x402781['query'][_0x8fe8('0x3b')]){_0x5a9123[_0x8fe8('0x38')]=_['merge'](_0x5a9123['where'],{'$or':_[_0x8fe8('0x2d')](_0x4ead6e,function(_0x449678){if(_0x449678[_0x8fe8('0x2a')]!==_0x8fe8('0x3c')){var _0x10f99e={};_0x10f99e[_0x449678[_0x8fe8('0x25')]]={'$like':'%'+_0x402781[_0x8fe8('0x2e')][_0x8fe8('0x3b')]+'%'};return _0x10f99e;}})});}_0x5a9123=_[_0x8fe8('0x3d')]({},_0x5a9123,_0x402781['options']);var _0x1016a8={'where':_0x5a9123[_0x8fe8('0x38')]};return db['FaxApplication'][_0x8fe8('0x1c')](_0x1016a8)[_0x8fe8('0x22')](function(_0x2ab599){_0x150e08[_0x8fe8('0x1c')]=_0x2ab599;if(_0x402781[_0x8fe8('0x2e')]['includeAll']){_0x5a9123[_0x8fe8('0x3e')]=[{'all':!![]}];}return db[_0x8fe8('0x27')][_0x8fe8('0x3f')](_0x5a9123);})['then'](function(_0x53a402){_0x150e08[_0x8fe8('0x40')]=_0x53a402;return _0x150e08;})[_0x8fe8('0x22')](respondWithFilteredResult(_0x1cd21f,_0x5a9123))[_0x8fe8('0x41')](handleError(_0x1cd21f,null));};exports[_0x8fe8('0x42')]=function(_0x2ef2ed,_0x3ecd38){var _0x540b36={'raw':!![],'where':{'id':_0x2ef2ed[_0x8fe8('0x43')]['id']}},_0xb1fef3={};_0xb1fef3[_0x8fe8('0x2c')]=_[_0x8fe8('0x2f')](db['FaxApplication'][_0x8fe8('0x28')]);_0xb1fef3[_0x8fe8('0x2e')]=_[_0x8fe8('0x2f')](_0x2ef2ed[_0x8fe8('0x2e')]);_0xb1fef3[_0x8fe8('0x39')]=_[_0x8fe8('0x30')](_0xb1fef3['model'],_0xb1fef3[_0x8fe8('0x2e')]);_0x540b36['attributes']=_[_0x8fe8('0x30')](_0xb1fef3['model'],qs[_0x8fe8('0x31')](_0x2ef2ed[_0x8fe8('0x2e')][_0x8fe8('0x31')]));_0x540b36[_0x8fe8('0x32')]=_0x540b36[_0x8fe8('0x32')][_0x8fe8('0x33')]?_0x540b36[_0x8fe8('0x32')]:_0xb1fef3[_0x8fe8('0x2c')];if(_0x2ef2ed[_0x8fe8('0x2e')][_0x8fe8('0x44')]){_0x540b36[_0x8fe8('0x3e')]=[{'all':!![]}];}_0x540b36=_[_0x8fe8('0x3d')]({},_0x540b36,_0x2ef2ed[_0x8fe8('0x45')]);return db[_0x8fe8('0x27')][_0x8fe8('0x46')](_0x540b36)['then'](handleEntityNotFound(_0x3ecd38,null))['then'](respondWithResult(_0x3ecd38,null))['catch'](handleError(_0x3ecd38,null));};exports['create']=function(_0x4a6b58,_0x55f896){return db[_0x8fe8('0x27')][_0x8fe8('0x47')](_0x4a6b58[_0x8fe8('0x48')],{})[_0x8fe8('0x22')](respondWithResult(_0x55f896,0xc9))[_0x8fe8('0x41')](handleError(_0x55f896,null));};exports[_0x8fe8('0x21')]=function(_0x3b6529,_0x42293e){if(_0x3b6529[_0x8fe8('0x48')]['id']){delete _0x3b6529[_0x8fe8('0x48')]['id'];}return db[_0x8fe8('0x27')][_0x8fe8('0x46')]({'where':{'id':_0x3b6529[_0x8fe8('0x43')]['id']}})['then'](handleEntityNotFound(_0x42293e,null))[_0x8fe8('0x22')](saveUpdates(_0x3b6529[_0x8fe8('0x48')],null))[_0x8fe8('0x22')](respondWithResult(_0x42293e,null))[_0x8fe8('0x41')](handleError(_0x42293e,null));};exports[_0x8fe8('0x23')]=function(_0x211755,_0x3b7d01){return db['FaxApplication'][_0x8fe8('0x46')]({'where':{'id':_0x211755[_0x8fe8('0x43')]['id']}})[_0x8fe8('0x22')](handleEntityNotFound(_0x3b7d01,null))[_0x8fe8('0x22')](removeEntity(_0x3b7d01,null))[_0x8fe8('0x41')](handleError(_0x3b7d01,null));};