82d63f77d756bdc7382582d6c43684165eb6da69
[motion2.git] / server / api / chatTransferReport / chatTransferReport.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 _0x955f=['ChatTransferReport','rawAttributes','fieldName','type','key','model','query','keys','filters','attributes','intersection','fields','length','nolimit','order','sort','where','pick','merge','VIRTUAL','filter','options','count','include','findAll','rows','catch','show','params','includeAll','find','create','body','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','sox','to-csv','ejs','lodash','squel','jsforce','desk.js','querystring','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','limit','Content-Range','apply','update','then','destroy','stack','name','index','map'];(function(_0x11f248,_0x2c19d7){var _0x4cd82e=function(_0x522f98){while(--_0x522f98){_0x11f248['push'](_0x11f248['shift']());}};_0x4cd82e(++_0x2c19d7);}(_0x955f,0xff));var _0xf955=function(_0x4f6a3f,_0xacd1da){_0x4f6a3f=_0x4f6a3f-0x0;var _0x48a047=_0x955f[_0x4f6a3f];return _0x48a047;};'use strict';var pdf=require(_0xf955('0x0'));var emlformat=require(_0xf955('0x1'));var rimraf=require(_0xf955('0x2'));var zipdir=require(_0xf955('0x3'));var jsonpatch=require(_0xf955('0x4'));var rp=require(_0xf955('0x5'));var moment=require(_0xf955('0x6'));var BPromise=require(_0xf955('0x7'));var Mustache=require(_0xf955('0x8'));var util=require(_0xf955('0x9'));var path=require('path');var sox=require(_0xf955('0xa'));var csv=require(_0xf955('0xb'));var ejs=require(_0xf955('0xc'));var fs=require('fs');var _=require(_0xf955('0xd'));var squel=require(_0xf955('0xe'));var crypto=require('crypto');var jsforce=require(_0xf955('0xf'));var deskjs=require(_0xf955('0x10'));var toCsv=require(_0xf955('0xb'));var querystring=require(_0xf955('0x11'));var Papa=require('papaparse');var Redis=require(_0xf955('0x12'));var authService=require('../../components/auth/service');var qs=require(_0xf955('0x13'));var as=require(_0xf955('0x14'));var hardwareService=require(_0xf955('0x15'));var logger=require('../../config/logger')('api');var utils=require(_0xf955('0x16'));var config=require(_0xf955('0x17'));var licenseUtil=require(_0xf955('0x18'));var db=require(_0xf955('0x19'))['db'];function respondWithStatusCode(_0x2c70f1,_0x3005a1){_0x3005a1=_0x3005a1||0xcc;return function(_0x4e85f1){if(_0x4e85f1){return _0x2c70f1[_0xf955('0x1a')](_0x3005a1);}return _0x2c70f1[_0xf955('0x1b')](_0x3005a1)[_0xf955('0x1c')]();};}function respondWithResult(_0xe4c1f5,_0xed6869){_0xed6869=_0xed6869||0xc8;return function(_0x49dc8c){if(_0x49dc8c){return _0xe4c1f5[_0xf955('0x1b')](_0xed6869)[_0xf955('0x1d')](_0x49dc8c);}};}function respondWithFilteredResult(_0x31f80f,_0x3ffd90){return function(_0x141399){if(_0x141399){var _0x4891bc=_0x141399['count'],_0x27e644=_0x3ffd90['offset'],_0x836216=_0x3ffd90[_0xf955('0x1e')]+_0x3ffd90[_0xf955('0x1f')],_0x24cb42;if(_0x836216>=_0x4891bc){_0x836216=_0x4891bc;_0x24cb42=0xc8;}else{_0x24cb42=0xce;}_0x31f80f[_0xf955('0x1b')](_0x24cb42);return _0x31f80f['set'](_0xf955('0x20'),_0x27e644+'-'+_0x836216+'/'+_0x4891bc)[_0xf955('0x1d')](_0x141399);}return null;};}function patchUpdates(_0x1c989e){return function(_0x4ee0f0){try{jsonpatch[_0xf955('0x21')](_0x4ee0f0,_0x1c989e,!![]);}catch(_0x1bba34){return BPromise['reject'](_0x1bba34);}return _0x4ee0f0['save']();};}function saveUpdates(_0x5176e7,_0x194896){return function(_0x3cc9d0){if(_0x3cc9d0){return _0x3cc9d0[_0xf955('0x22')](_0x5176e7)[_0xf955('0x23')](function(_0x10b8f9){return _0x10b8f9;});}return null;};}function removeEntity(_0x8b5f25,_0x501992){return function(_0x3aa89f){if(_0x3aa89f){return _0x3aa89f[_0xf955('0x24')]()[_0xf955('0x23')](function(){_0x8b5f25[_0xf955('0x1b')](0xcc)[_0xf955('0x1c')]();});}};}function handleEntityNotFound(_0x2e0c64,_0x35f5d5){return function(_0x111178){if(!_0x111178){_0x2e0c64[_0xf955('0x1a')](0x194);}return _0x111178;};}function handleError(_0x6f42f5,_0x2e01c8){_0x2e01c8=_0x2e01c8||0x1f4;return function(_0x24e24e){logger['error'](_0x24e24e[_0xf955('0x25')]);if(_0x24e24e[_0xf955('0x26')]){delete _0x24e24e['name'];}_0x6f42f5[_0xf955('0x1b')](_0x2e01c8)['send'](_0x24e24e);};}exports[_0xf955('0x27')]=function(_0x2cf169,_0x1517ad){var _0x33ad6c={},_0x49d60e={},_0x52fb48={'count':0x0,'rows':[]};var _0x514fbf=_[_0xf955('0x28')](db[_0xf955('0x29')][_0xf955('0x2a')],function(_0x400e28){return{'name':_0x400e28[_0xf955('0x2b')],'type':_0x400e28[_0xf955('0x2c')][_0xf955('0x2d')]};});_0x49d60e[_0xf955('0x2e')]=_[_0xf955('0x28')](_0x514fbf,'name');_0x49d60e[_0xf955('0x2f')]=_[_0xf955('0x30')](_0x2cf169[_0xf955('0x2f')]);_0x49d60e[_0xf955('0x31')]=_['intersection'](_0x49d60e[_0xf955('0x2e')],_0x49d60e[_0xf955('0x2f')]);_0x33ad6c[_0xf955('0x32')]=_[_0xf955('0x33')](_0x49d60e['model'],qs[_0xf955('0x34')](_0x2cf169[_0xf955('0x2f')][_0xf955('0x34')]));_0x33ad6c[_0xf955('0x32')]=_0x33ad6c[_0xf955('0x32')][_0xf955('0x35')]?_0x33ad6c[_0xf955('0x32')]:_0x49d60e[_0xf955('0x2e')];if(!_0x2cf169[_0xf955('0x2f')]['hasOwnProperty'](_0xf955('0x36'))){_0x33ad6c['limit']=qs[_0xf955('0x1f')](_0x2cf169[_0xf955('0x2f')]['limit']);_0x33ad6c[_0xf955('0x1e')]=qs[_0xf955('0x1e')](_0x2cf169['query'][_0xf955('0x1e')]);}_0x33ad6c[_0xf955('0x37')]=qs['sort'](_0x2cf169['query'][_0xf955('0x38')]);_0x33ad6c[_0xf955('0x39')]=qs[_0xf955('0x31')](_[_0xf955('0x3a')](_0x2cf169[_0xf955('0x2f')],_0x49d60e[_0xf955('0x31')]),_0x514fbf);if(_0x2cf169[_0xf955('0x2f')]['filter']){_0x33ad6c[_0xf955('0x39')]=_[_0xf955('0x3b')](_0x33ad6c[_0xf955('0x39')],{'$or':_[_0xf955('0x28')](_0x514fbf,function(_0x4a1671){if(_0x4a1671[_0xf955('0x2c')]!==_0xf955('0x3c')){var _0x26cc49={};_0x26cc49[_0x4a1671[_0xf955('0x26')]]={'$like':'%'+_0x2cf169[_0xf955('0x2f')][_0xf955('0x3d')]+'%'};return _0x26cc49;}})});}_0x33ad6c=_[_0xf955('0x3b')]({},_0x33ad6c,_0x2cf169[_0xf955('0x3e')]);var _0x2db42b={'where':_0x33ad6c[_0xf955('0x39')]};return db[_0xf955('0x29')][_0xf955('0x3f')](_0x2db42b)[_0xf955('0x23')](function(_0x18af15){_0x52fb48['count']=_0x18af15;if(_0x2cf169[_0xf955('0x2f')]['includeAll']){_0x33ad6c[_0xf955('0x40')]=[{'all':!![]}];}return db[_0xf955('0x29')][_0xf955('0x41')](_0x33ad6c);})[_0xf955('0x23')](function(_0x406ecb){_0x52fb48[_0xf955('0x42')]=_0x406ecb;return _0x52fb48;})[_0xf955('0x23')](respondWithFilteredResult(_0x1517ad,_0x33ad6c))[_0xf955('0x43')](handleError(_0x1517ad,null));};exports[_0xf955('0x44')]=function(_0x10afe0,_0x1e9def){var _0x482094={'raw':!![],'where':{'id':_0x10afe0[_0xf955('0x45')]['id']}},_0x30af70={};_0x30af70[_0xf955('0x2e')]=_['keys'](db[_0xf955('0x29')][_0xf955('0x2a')]);_0x30af70[_0xf955('0x2f')]=_[_0xf955('0x30')](_0x10afe0['query']);_0x30af70[_0xf955('0x31')]=_['intersection'](_0x30af70['model'],_0x30af70[_0xf955('0x2f')]);_0x482094[_0xf955('0x32')]=_['intersection'](_0x30af70[_0xf955('0x2e')],qs[_0xf955('0x34')](_0x10afe0[_0xf955('0x2f')]['fields']));_0x482094[_0xf955('0x32')]=_0x482094[_0xf955('0x32')][_0xf955('0x35')]?_0x482094[_0xf955('0x32')]:_0x30af70[_0xf955('0x2e')];if(_0x10afe0[_0xf955('0x2f')][_0xf955('0x46')]){_0x482094[_0xf955('0x40')]=[{'all':!![]}];}_0x482094=_['merge']({},_0x482094,_0x10afe0[_0xf955('0x3e')]);return db['ChatTransferReport'][_0xf955('0x47')](_0x482094)[_0xf955('0x23')](handleEntityNotFound(_0x1e9def,null))[_0xf955('0x23')](respondWithResult(_0x1e9def,null))[_0xf955('0x43')](handleError(_0x1e9def,null));};exports[_0xf955('0x48')]=function(_0x2f3774,_0x4adba0){return db[_0xf955('0x29')][_0xf955('0x48')](_0x2f3774['body'],{})[_0xf955('0x23')](respondWithResult(_0x4adba0,0xc9))[_0xf955('0x43')](handleError(_0x4adba0,null));};exports[_0xf955('0x22')]=function(_0x2f872f,_0x330f5e){if(_0x2f872f[_0xf955('0x49')]['id']){delete _0x2f872f['body']['id'];}return db[_0xf955('0x29')][_0xf955('0x47')]({'where':{'id':_0x2f872f['params']['id']}})[_0xf955('0x23')](handleEntityNotFound(_0x330f5e,null))[_0xf955('0x23')](saveUpdates(_0x2f872f[_0xf955('0x49')],null))[_0xf955('0x23')](respondWithResult(_0x330f5e,null))[_0xf955('0x43')](handleError(_0x330f5e,null));};exports[_0xf955('0x24')]=function(_0x9dc58e,_0x19c424){return db['ChatTransferReport'][_0xf955('0x47')]({'where':{'id':_0x9dc58e['params']['id']}})[_0xf955('0x23')](handleEntityNotFound(_0x19c424,null))[_0xf955('0x23')](removeEntity(_0x19c424,null))[_0xf955('0x43')](handleError(_0x19c424,null));};exports['describe']=function(_0xcd4490,_0x19b314){return db[_0xf955('0x29')]['describe']()['then'](respondWithResult(_0x19b314,null))[_0xf955('0x43')](handleError(_0x19b314,null));};