Built motion from commit (unavailable).|2.5.13
[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 _0xb5ae=['crypto','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','count','set','Content-Range','json','apply','reject','update','then','error','stack','name','send','index','map','ChatTransferReport','rawAttributes','type','model','query','keys','filters','intersection','fields','attributes','length','hasOwnProperty','limit','offset','order','sort','where','pick','filter','VIRTUAL','includeAll','include','rows','catch','params','merge','options','find','create','body','destroy','describe','html-pdf','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','lodash','squel'];(function(_0x3d0084,_0x35667e){var _0x257515=function(_0x23ad31){while(--_0x23ad31){_0x3d0084['push'](_0x3d0084['shift']());}};_0x257515(++_0x35667e);}(_0xb5ae,0x125));var _0xeb5a=function(_0x4a1918,_0x20e55e){_0x4a1918=_0x4a1918-0x0;var _0x47974e=_0xb5ae[_0x4a1918];return _0x47974e;};'use strict';var pdf=require(_0xeb5a('0x0'));var emlformat=require('eml-format');var rimraf=require(_0xeb5a('0x1'));var zipdir=require(_0xeb5a('0x2'));var jsonpatch=require(_0xeb5a('0x3'));var rp=require(_0xeb5a('0x4'));var moment=require(_0xeb5a('0x5'));var BPromise=require(_0xeb5a('0x6'));var Mustache=require(_0xeb5a('0x7'));var util=require(_0xeb5a('0x8'));var path=require(_0xeb5a('0x9'));var sox=require(_0xeb5a('0xa'));var csv=require(_0xeb5a('0xb'));var ejs=require(_0xeb5a('0xc'));var fs=require('fs');var _=require(_0xeb5a('0xd'));var squel=require(_0xeb5a('0xe'));var crypto=require(_0xeb5a('0xf'));var jsforce=require('jsforce');var deskjs=require(_0xeb5a('0x10'));var toCsv=require(_0xeb5a('0xb'));var querystring=require(_0xeb5a('0x11'));var Papa=require(_0xeb5a('0x12'));var Redis=require(_0xeb5a('0x13'));var authService=require(_0xeb5a('0x14'));var qs=require('../../components/parsers/qs');var as=require(_0xeb5a('0x15'));var hardwareService=require(_0xeb5a('0x16'));var logger=require(_0xeb5a('0x17'))(_0xeb5a('0x18'));var utils=require('../../config/utils');var config=require(_0xeb5a('0x19'));var licenseUtil=require(_0xeb5a('0x1a'));var db=require(_0xeb5a('0x1b'))['db'];function respondWithStatusCode(_0x33535c,_0x55b5f4){_0x55b5f4=_0x55b5f4||0xcc;return function(_0x563a74){if(_0x563a74){return _0x33535c[_0xeb5a('0x1c')](_0x55b5f4);}return _0x33535c[_0xeb5a('0x1d')](_0x55b5f4)[_0xeb5a('0x1e')]();};}function respondWithResult(_0x41db21,_0x4a8438){_0x4a8438=_0x4a8438||0xc8;return function(_0x592b63){if(_0x592b63){return _0x41db21[_0xeb5a('0x1d')](_0x4a8438)['json'](_0x592b63);}};}function respondWithFilteredResult(_0x42def8,_0x58577f){return function(_0x358389){if(_0x358389){var _0x7bd83b=_0x358389[_0xeb5a('0x1f')],_0x49dc17=_0x58577f['offset'],_0x57701c=_0x58577f['offset']+_0x58577f['limit'],_0x57dcb9;if(_0x57701c>=_0x7bd83b){_0x57701c=_0x7bd83b;_0x57dcb9=0xc8;}else{_0x57dcb9=0xce;}_0x42def8[_0xeb5a('0x1d')](_0x57dcb9);return _0x42def8[_0xeb5a('0x20')](_0xeb5a('0x21'),_0x49dc17+'-'+_0x57701c+'/'+_0x7bd83b)[_0xeb5a('0x22')](_0x358389);}return null;};}function patchUpdates(_0xd5ab95){return function(_0x1caf14){try{jsonpatch[_0xeb5a('0x23')](_0x1caf14,_0xd5ab95,!![]);}catch(_0x15ea79){return BPromise[_0xeb5a('0x24')](_0x15ea79);}return _0x1caf14['save']();};}function saveUpdates(_0x4264ec,_0x5d73af){return function(_0xfb1478){if(_0xfb1478){return _0xfb1478[_0xeb5a('0x25')](_0x4264ec)['then'](function(_0x7be296){return _0x7be296;});}return null;};}function removeEntity(_0x3495e4,_0x38ed17){return function(_0x3b62b1){if(_0x3b62b1){return _0x3b62b1['destroy']()[_0xeb5a('0x26')](function(){_0x3495e4[_0xeb5a('0x1d')](0xcc)[_0xeb5a('0x1e')]();});}};}function handleEntityNotFound(_0x33054f,_0x3bc1d2){return function(_0x581da3){if(!_0x581da3){_0x33054f[_0xeb5a('0x1c')](0x194);}return _0x581da3;};}function handleError(_0x3f5e3f,_0x3e74e7){_0x3e74e7=_0x3e74e7||0x1f4;return function(_0x23f419){logger[_0xeb5a('0x27')](_0x23f419[_0xeb5a('0x28')]);if(_0x23f419['name']){delete _0x23f419[_0xeb5a('0x29')];}_0x3f5e3f[_0xeb5a('0x1d')](_0x3e74e7)[_0xeb5a('0x2a')](_0x23f419);};}exports[_0xeb5a('0x2b')]=function(_0x1be400,_0x34e63f){var _0x3e0b66={},_0xe3b347={},_0x25b8ab={'count':0x0,'rows':[]};var _0x4c0063=_[_0xeb5a('0x2c')](db[_0xeb5a('0x2d')][_0xeb5a('0x2e')],function(_0x589847){return{'name':_0x589847['fieldName'],'type':_0x589847[_0xeb5a('0x2f')]['key']};});_0xe3b347[_0xeb5a('0x30')]=_['map'](_0x4c0063,'name');_0xe3b347[_0xeb5a('0x31')]=_[_0xeb5a('0x32')](_0x1be400[_0xeb5a('0x31')]);_0xe3b347[_0xeb5a('0x33')]=_[_0xeb5a('0x34')](_0xe3b347[_0xeb5a('0x30')],_0xe3b347[_0xeb5a('0x31')]);_0x3e0b66['attributes']=_[_0xeb5a('0x34')](_0xe3b347[_0xeb5a('0x30')],qs[_0xeb5a('0x35')](_0x1be400[_0xeb5a('0x31')][_0xeb5a('0x35')]));_0x3e0b66[_0xeb5a('0x36')]=_0x3e0b66[_0xeb5a('0x36')][_0xeb5a('0x37')]?_0x3e0b66[_0xeb5a('0x36')]:_0xe3b347[_0xeb5a('0x30')];if(!_0x1be400[_0xeb5a('0x31')][_0xeb5a('0x38')]('nolimit')){_0x3e0b66['limit']=qs[_0xeb5a('0x39')](_0x1be400[_0xeb5a('0x31')][_0xeb5a('0x39')]);_0x3e0b66[_0xeb5a('0x3a')]=qs[_0xeb5a('0x3a')](_0x1be400['query'][_0xeb5a('0x3a')]);}_0x3e0b66[_0xeb5a('0x3b')]=qs[_0xeb5a('0x3c')](_0x1be400[_0xeb5a('0x31')][_0xeb5a('0x3c')]);_0x3e0b66[_0xeb5a('0x3d')]=qs[_0xeb5a('0x33')](_[_0xeb5a('0x3e')](_0x1be400['query'],_0xe3b347[_0xeb5a('0x33')]),_0x4c0063);if(_0x1be400[_0xeb5a('0x31')][_0xeb5a('0x3f')]){_0x3e0b66[_0xeb5a('0x3d')]=_['merge'](_0x3e0b66[_0xeb5a('0x3d')],{'$or':_[_0xeb5a('0x2c')](_0x4c0063,function(_0xa1297e){if(_0xa1297e[_0xeb5a('0x2f')]!==_0xeb5a('0x40')){var _0x12851d={};_0x12851d[_0xa1297e[_0xeb5a('0x29')]]={'$like':'%'+_0x1be400[_0xeb5a('0x31')]['filter']+'%'};return _0x12851d;}})});}_0x3e0b66=_['merge']({},_0x3e0b66,_0x1be400['options']);var _0x1dccac={'where':_0x3e0b66['where']};return db[_0xeb5a('0x2d')]['count'](_0x1dccac)[_0xeb5a('0x26')](function(_0x4806e2){_0x25b8ab['count']=_0x4806e2;if(_0x1be400['query'][_0xeb5a('0x41')]){_0x3e0b66[_0xeb5a('0x42')]=[{'all':!![]}];}return db['ChatTransferReport']['findAll'](_0x3e0b66);})[_0xeb5a('0x26')](function(_0x1465f9){_0x25b8ab[_0xeb5a('0x43')]=_0x1465f9;return _0x25b8ab;})[_0xeb5a('0x26')](respondWithFilteredResult(_0x34e63f,_0x3e0b66))[_0xeb5a('0x44')](handleError(_0x34e63f,null));};exports['show']=function(_0x175742,_0x2d22a1){var _0x48f532={'raw':!![],'where':{'id':_0x175742[_0xeb5a('0x45')]['id']}},_0x124fbc={};_0x124fbc[_0xeb5a('0x30')]=_['keys'](db[_0xeb5a('0x2d')][_0xeb5a('0x2e')]);_0x124fbc[_0xeb5a('0x31')]=_['keys'](_0x175742[_0xeb5a('0x31')]);_0x124fbc[_0xeb5a('0x33')]=_['intersection'](_0x124fbc['model'],_0x124fbc['query']);_0x48f532[_0xeb5a('0x36')]=_['intersection'](_0x124fbc[_0xeb5a('0x30')],qs[_0xeb5a('0x35')](_0x175742[_0xeb5a('0x31')][_0xeb5a('0x35')]));_0x48f532[_0xeb5a('0x36')]=_0x48f532['attributes']['length']?_0x48f532['attributes']:_0x124fbc['model'];if(_0x175742[_0xeb5a('0x31')][_0xeb5a('0x41')]){_0x48f532['include']=[{'all':!![]}];}_0x48f532=_[_0xeb5a('0x46')]({},_0x48f532,_0x175742[_0xeb5a('0x47')]);return db[_0xeb5a('0x2d')][_0xeb5a('0x48')](_0x48f532)[_0xeb5a('0x26')](handleEntityNotFound(_0x2d22a1,null))[_0xeb5a('0x26')](respondWithResult(_0x2d22a1,null))[_0xeb5a('0x44')](handleError(_0x2d22a1,null));};exports[_0xeb5a('0x49')]=function(_0x56ac8a,_0x349be8){return db['ChatTransferReport']['create'](_0x56ac8a[_0xeb5a('0x4a')],{})[_0xeb5a('0x26')](respondWithResult(_0x349be8,0xc9))[_0xeb5a('0x44')](handleError(_0x349be8,null));};exports[_0xeb5a('0x25')]=function(_0x273dba,_0xee5d5e){if(_0x273dba[_0xeb5a('0x4a')]['id']){delete _0x273dba['body']['id'];}return db[_0xeb5a('0x2d')][_0xeb5a('0x48')]({'where':{'id':_0x273dba[_0xeb5a('0x45')]['id']}})[_0xeb5a('0x26')](handleEntityNotFound(_0xee5d5e,null))['then'](saveUpdates(_0x273dba[_0xeb5a('0x4a')],null))['then'](respondWithResult(_0xee5d5e,null))['catch'](handleError(_0xee5d5e,null));};exports[_0xeb5a('0x4b')]=function(_0x4c8ec6,_0xc23746){return db[_0xeb5a('0x2d')]['find']({'where':{'id':_0x4c8ec6['params']['id']}})[_0xeb5a('0x26')](handleEntityNotFound(_0xc23746,null))[_0xeb5a('0x26')](removeEntity(_0xc23746,null))['catch'](handleError(_0xc23746,null));};exports[_0xeb5a('0x4c')]=function(_0x37fb9a,_0x52b679){return db[_0xeb5a('0x2d')]['describe']()[_0xeb5a('0x26')](respondWithResult(_0x52b679,null))['catch'](handleError(_0x52b679,null));};