Built motion from commit (unavailable).|2.5.14
[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 _0xe9a9=['sort','where','pick','filter','merge','VIRTUAL','options','ChatTransferReport','includeAll','include','rows','show','params','rawAttributes','catch','create','body','find','destroy','describe','html-pdf','eml-format','rimraf','fast-json-patch','request-promise','moment','bluebird','mustache','util','sox','to-csv','squel','crypto','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','count','offset','limit','Content-Range','apply','reject','save','update','then','stack','index','map','type','key','model','name','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit'];(function(_0x41639b,_0x27bd1d){var _0xd942f9=function(_0xec8dae){while(--_0xec8dae){_0x41639b['push'](_0x41639b['shift']());}};_0xd942f9(++_0x27bd1d);}(_0xe9a9,0x190));var _0x9e9a=function(_0x437a60,_0xe17787){_0x437a60=_0x437a60-0x0;var _0x1ed7cd=_0xe9a9[_0x437a60];return _0x1ed7cd;};'use strict';var pdf=require(_0x9e9a('0x0'));var emlformat=require(_0x9e9a('0x1'));var rimraf=require(_0x9e9a('0x2'));var zipdir=require('zip-dir');var jsonpatch=require(_0x9e9a('0x3'));var rp=require(_0x9e9a('0x4'));var moment=require(_0x9e9a('0x5'));var BPromise=require(_0x9e9a('0x6'));var Mustache=require(_0x9e9a('0x7'));var util=require(_0x9e9a('0x8'));var path=require('path');var sox=require(_0x9e9a('0x9'));var csv=require(_0x9e9a('0xa'));var ejs=require('ejs');var fs=require('fs');var _=require('lodash');var squel=require(_0x9e9a('0xb'));var crypto=require(_0x9e9a('0xc'));var jsforce=require(_0x9e9a('0xd'));var deskjs=require(_0x9e9a('0xe'));var toCsv=require(_0x9e9a('0xa'));var querystring=require(_0x9e9a('0xf'));var Papa=require(_0x9e9a('0x10'));var Redis=require('ioredis');var authService=require(_0x9e9a('0x11'));var qs=require(_0x9e9a('0x12'));var as=require(_0x9e9a('0x13'));var hardwareService=require(_0x9e9a('0x14'));var logger=require(_0x9e9a('0x15'))(_0x9e9a('0x16'));var utils=require(_0x9e9a('0x17'));var config=require(_0x9e9a('0x18'));var licenseUtil=require(_0x9e9a('0x19'));var db=require(_0x9e9a('0x1a'))['db'];function respondWithStatusCode(_0xe04f24,_0x1a3d01){_0x1a3d01=_0x1a3d01||0xcc;return function(_0x502d82){if(_0x502d82){return _0xe04f24[_0x9e9a('0x1b')](_0x1a3d01);}return _0xe04f24[_0x9e9a('0x1c')](_0x1a3d01)[_0x9e9a('0x1d')]();};}function respondWithResult(_0xf31b4a,_0x2b3632){_0x2b3632=_0x2b3632||0xc8;return function(_0x49420a){if(_0x49420a){return _0xf31b4a[_0x9e9a('0x1c')](_0x2b3632)[_0x9e9a('0x1e')](_0x49420a);}};}function respondWithFilteredResult(_0xfb2849,_0x2e0d91){return function(_0x392914){if(_0x392914){var _0xff204d=_0x392914[_0x9e9a('0x1f')],_0x3fd545=_0x2e0d91[_0x9e9a('0x20')],_0x4b0e6a=_0x2e0d91[_0x9e9a('0x20')]+_0x2e0d91[_0x9e9a('0x21')],_0x330cf0;if(_0x4b0e6a>=_0xff204d){_0x4b0e6a=_0xff204d;_0x330cf0=0xc8;}else{_0x330cf0=0xce;}_0xfb2849[_0x9e9a('0x1c')](_0x330cf0);return _0xfb2849['set'](_0x9e9a('0x22'),_0x3fd545+'-'+_0x4b0e6a+'/'+_0xff204d)['json'](_0x392914);}return null;};}function patchUpdates(_0x5c40cb){return function(_0x3028e7){try{jsonpatch[_0x9e9a('0x23')](_0x3028e7,_0x5c40cb,!![]);}catch(_0x22e557){return BPromise[_0x9e9a('0x24')](_0x22e557);}return _0x3028e7[_0x9e9a('0x25')]();};}function saveUpdates(_0xc171ff,_0x81cc47){return function(_0xb6fe1f){if(_0xb6fe1f){return _0xb6fe1f[_0x9e9a('0x26')](_0xc171ff)['then'](function(_0x577c20){return _0x577c20;});}return null;};}function removeEntity(_0xa3a083,_0x4d8066){return function(_0x5acf60){if(_0x5acf60){return _0x5acf60['destroy']()[_0x9e9a('0x27')](function(){_0xa3a083[_0x9e9a('0x1c')](0xcc)[_0x9e9a('0x1d')]();});}};}function handleEntityNotFound(_0x18ae41,_0x317826){return function(_0x1f3d8b){if(!_0x1f3d8b){_0x18ae41['sendStatus'](0x194);}return _0x1f3d8b;};}function handleError(_0x41d582,_0x1d7bff){_0x1d7bff=_0x1d7bff||0x1f4;return function(_0x483ff7){logger['error'](_0x483ff7[_0x9e9a('0x28')]);if(_0x483ff7['name']){delete _0x483ff7['name'];}_0x41d582[_0x9e9a('0x1c')](_0x1d7bff)['send'](_0x483ff7);};}exports[_0x9e9a('0x29')]=function(_0x121811,_0x177d15){var _0x5c9da8={},_0x5f3531={},_0x1336b8={'count':0x0,'rows':[]};var _0x2189cf=_[_0x9e9a('0x2a')](db['ChatTransferReport']['rawAttributes'],function(_0x51899b){return{'name':_0x51899b['fieldName'],'type':_0x51899b[_0x9e9a('0x2b')][_0x9e9a('0x2c')]};});_0x5f3531[_0x9e9a('0x2d')]=_['map'](_0x2189cf,_0x9e9a('0x2e'));_0x5f3531[_0x9e9a('0x2f')]=_[_0x9e9a('0x30')](_0x121811[_0x9e9a('0x2f')]);_0x5f3531[_0x9e9a('0x31')]=_[_0x9e9a('0x32')](_0x5f3531[_0x9e9a('0x2d')],_0x5f3531[_0x9e9a('0x2f')]);_0x5c9da8[_0x9e9a('0x33')]=_[_0x9e9a('0x32')](_0x5f3531[_0x9e9a('0x2d')],qs[_0x9e9a('0x34')](_0x121811[_0x9e9a('0x2f')][_0x9e9a('0x34')]));_0x5c9da8['attributes']=_0x5c9da8[_0x9e9a('0x33')][_0x9e9a('0x35')]?_0x5c9da8['attributes']:_0x5f3531[_0x9e9a('0x2d')];if(!_0x121811[_0x9e9a('0x2f')][_0x9e9a('0x36')](_0x9e9a('0x37'))){_0x5c9da8[_0x9e9a('0x21')]=qs['limit'](_0x121811['query']['limit']);_0x5c9da8[_0x9e9a('0x20')]=qs[_0x9e9a('0x20')](_0x121811[_0x9e9a('0x2f')][_0x9e9a('0x20')]);}_0x5c9da8['order']=qs[_0x9e9a('0x38')](_0x121811[_0x9e9a('0x2f')][_0x9e9a('0x38')]);_0x5c9da8[_0x9e9a('0x39')]=qs[_0x9e9a('0x31')](_[_0x9e9a('0x3a')](_0x121811['query'],_0x5f3531[_0x9e9a('0x31')]),_0x2189cf);if(_0x121811[_0x9e9a('0x2f')][_0x9e9a('0x3b')]){_0x5c9da8[_0x9e9a('0x39')]=_[_0x9e9a('0x3c')](_0x5c9da8[_0x9e9a('0x39')],{'$or':_[_0x9e9a('0x2a')](_0x2189cf,function(_0x508040){if(_0x508040[_0x9e9a('0x2b')]!==_0x9e9a('0x3d')){var _0x4b50c2={};_0x4b50c2[_0x508040[_0x9e9a('0x2e')]]={'$like':'%'+_0x121811[_0x9e9a('0x2f')][_0x9e9a('0x3b')]+'%'};return _0x4b50c2;}})});}_0x5c9da8=_[_0x9e9a('0x3c')]({},_0x5c9da8,_0x121811[_0x9e9a('0x3e')]);var _0x101483={'where':_0x5c9da8[_0x9e9a('0x39')]};return db[_0x9e9a('0x3f')][_0x9e9a('0x1f')](_0x101483)[_0x9e9a('0x27')](function(_0x4ab6d8){_0x1336b8['count']=_0x4ab6d8;if(_0x121811['query'][_0x9e9a('0x40')]){_0x5c9da8[_0x9e9a('0x41')]=[{'all':!![]}];}return db[_0x9e9a('0x3f')]['findAll'](_0x5c9da8);})['then'](function(_0x5f3355){_0x1336b8[_0x9e9a('0x42')]=_0x5f3355;return _0x1336b8;})[_0x9e9a('0x27')](respondWithFilteredResult(_0x177d15,_0x5c9da8))['catch'](handleError(_0x177d15,null));};exports[_0x9e9a('0x43')]=function(_0x3c45c1,_0x92cbe0){var _0x30b9bd={'raw':!![],'where':{'id':_0x3c45c1[_0x9e9a('0x44')]['id']}},_0x24be86={};_0x24be86[_0x9e9a('0x2d')]=_[_0x9e9a('0x30')](db[_0x9e9a('0x3f')][_0x9e9a('0x45')]);_0x24be86[_0x9e9a('0x2f')]=_['keys'](_0x3c45c1[_0x9e9a('0x2f')]);_0x24be86[_0x9e9a('0x31')]=_[_0x9e9a('0x32')](_0x24be86['model'],_0x24be86['query']);_0x30b9bd[_0x9e9a('0x33')]=_['intersection'](_0x24be86[_0x9e9a('0x2d')],qs[_0x9e9a('0x34')](_0x3c45c1[_0x9e9a('0x2f')][_0x9e9a('0x34')]));_0x30b9bd[_0x9e9a('0x33')]=_0x30b9bd[_0x9e9a('0x33')][_0x9e9a('0x35')]?_0x30b9bd['attributes']:_0x24be86[_0x9e9a('0x2d')];if(_0x3c45c1['query'][_0x9e9a('0x40')]){_0x30b9bd[_0x9e9a('0x41')]=[{'all':!![]}];}_0x30b9bd=_[_0x9e9a('0x3c')]({},_0x30b9bd,_0x3c45c1[_0x9e9a('0x3e')]);return db['ChatTransferReport']['find'](_0x30b9bd)['then'](handleEntityNotFound(_0x92cbe0,null))[_0x9e9a('0x27')](respondWithResult(_0x92cbe0,null))[_0x9e9a('0x46')](handleError(_0x92cbe0,null));};exports[_0x9e9a('0x47')]=function(_0x9c1964,_0xaa1755){return db[_0x9e9a('0x3f')][_0x9e9a('0x47')](_0x9c1964[_0x9e9a('0x48')],{})[_0x9e9a('0x27')](respondWithResult(_0xaa1755,0xc9))['catch'](handleError(_0xaa1755,null));};exports['update']=function(_0x2b9e32,_0x11d0de){if(_0x2b9e32['body']['id']){delete _0x2b9e32['body']['id'];}return db[_0x9e9a('0x3f')][_0x9e9a('0x49')]({'where':{'id':_0x2b9e32[_0x9e9a('0x44')]['id']}})['then'](handleEntityNotFound(_0x11d0de,null))[_0x9e9a('0x27')](saveUpdates(_0x2b9e32['body'],null))[_0x9e9a('0x27')](respondWithResult(_0x11d0de,null))[_0x9e9a('0x46')](handleError(_0x11d0de,null));};exports[_0x9e9a('0x4a')]=function(_0x145d10,_0x217fd1){return db[_0x9e9a('0x3f')][_0x9e9a('0x49')]({'where':{'id':_0x145d10[_0x9e9a('0x44')]['id']}})['then'](handleEntityNotFound(_0x217fd1,null))[_0x9e9a('0x27')](removeEntity(_0x217fd1,null))['catch'](handleError(_0x217fd1,null));};exports[_0x9e9a('0x4b')]=function(_0x5d708d,_0x52ade3){return db['ChatTransferReport']['describe']()[_0x9e9a('0x27')](respondWithResult(_0x52ade3,null))[_0x9e9a('0x46')](handleError(_0x52ade3,null));};