Built motion from commit b5413ace.|2.6.9
[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 _0x34c4=['../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','json','offset','undefined','limit','count','reject','update','destroy','then','end','error','stack','name','send','index','map','ChatTransferReport','fieldName','type','model','query','keys','filters','attributes','fields','nolimit','order','sort','pick','filter','where','VIRTUAL','merge','options','include','findAll','rows','catch','show','rawAttributes','intersection','length','includeAll','find','create','body','params','describe','eml-format','rimraf','request-promise','moment','bluebird','util','path','sox','to-csv','ejs','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/logger','api'];(function(_0x49a731,_0x3435e9){var _0x5346eb=function(_0x6d65b){while(--_0x6d65b){_0x49a731['push'](_0x49a731['shift']());}};_0x5346eb(++_0x3435e9);}(_0x34c4,0x7e));var _0x434c=function(_0x36f1f9,_0x249b34){_0x36f1f9=_0x36f1f9-0x0;var _0x31f644=_0x34c4[_0x36f1f9];return _0x31f644;};'use strict';var emlformat=require(_0x434c('0x0'));var rimraf=require(_0x434c('0x1'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0x434c('0x2'));var moment=require(_0x434c('0x3'));var BPromise=require(_0x434c('0x4'));var Mustache=require('mustache');var util=require(_0x434c('0x5'));var path=require(_0x434c('0x6'));var sox=require(_0x434c('0x7'));var csv=require(_0x434c('0x8'));var ejs=require(_0x434c('0x9'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require('lodash');var squel=require('squel');var crypto=require(_0x434c('0xa'));var jsforce=require(_0x434c('0xb'));var deskjs=require(_0x434c('0xc'));var toCsv=require(_0x434c('0x8'));var querystring=require(_0x434c('0xd'));var Papa=require(_0x434c('0xe'));var Redis=require(_0x434c('0xf'));var authService=require(_0x434c('0x10'));var qs=require('../../components/parsers/qs');var as=require(_0x434c('0x11'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x434c('0x12'))(_0x434c('0x13'));var utils=require(_0x434c('0x14'));var config=require(_0x434c('0x15'));var licenseUtil=require('../../config/license/util');var db=require(_0x434c('0x16'))['db'];function respondWithStatusCode(_0x2013a1,_0x2932f2){_0x2932f2=_0x2932f2||0xcc;return function(_0x4bf8b7){if(_0x4bf8b7){return _0x2013a1[_0x434c('0x17')](_0x2932f2);}return _0x2013a1[_0x434c('0x18')](_0x2932f2)['end']();};}function respondWithResult(_0x39530c,_0x460695){_0x460695=_0x460695||0xc8;return function(_0x59e538){if(_0x59e538){return _0x39530c[_0x434c('0x18')](_0x460695)[_0x434c('0x19')](_0x59e538);}};}function respondWithFilteredResult(_0x1c9fa0,_0x4cb65e){return function(_0x4f4d7a){if(_0x4f4d7a){var _0x2b71dd=typeof _0x4cb65e[_0x434c('0x1a')]===_0x434c('0x1b')&&typeof _0x4cb65e[_0x434c('0x1c')]===_0x434c('0x1b');var _0x21b134=_0x4f4d7a[_0x434c('0x1d')];var _0x1fe30d=_0x2b71dd?0x0:_0x4cb65e['offset'];var _0x321b4f=_0x2b71dd?_0x4f4d7a[_0x434c('0x1d')]:_0x4cb65e[_0x434c('0x1a')]+_0x4cb65e[_0x434c('0x1c')];var _0x32bc8b;if(_0x321b4f>=_0x21b134){_0x321b4f=_0x21b134;_0x32bc8b=0xc8;}else{_0x32bc8b=0xce;}_0x1c9fa0['status'](_0x32bc8b);return _0x1c9fa0['set']('Content-Range',_0x1fe30d+'-'+_0x321b4f+'/'+_0x21b134)['json'](_0x4f4d7a);}return null;};}function patchUpdates(_0x21d1a6){return function(_0x11cabf){try{jsonpatch['apply'](_0x11cabf,_0x21d1a6,!![]);}catch(_0x262d96){return BPromise[_0x434c('0x1e')](_0x262d96);}return _0x11cabf['save']();};}function saveUpdates(_0x539c97,_0x51b54c){return function(_0x3e1f50){if(_0x3e1f50){return _0x3e1f50[_0x434c('0x1f')](_0x539c97)['then'](function(_0x2ad167){return _0x2ad167;});}return null;};}function removeEntity(_0x3c671f,_0x370c10){return function(_0x5bc7b4){if(_0x5bc7b4){return _0x5bc7b4[_0x434c('0x20')]()[_0x434c('0x21')](function(){_0x3c671f[_0x434c('0x18')](0xcc)[_0x434c('0x22')]();});}};}function handleEntityNotFound(_0x43f056,_0x310800){return function(_0x4e187d){if(!_0x4e187d){_0x43f056['sendStatus'](0x194);}return _0x4e187d;};}function handleError(_0x3f1691,_0x222f56){_0x222f56=_0x222f56||0x1f4;return function(_0x5cf470){logger[_0x434c('0x23')](_0x5cf470[_0x434c('0x24')]);if(_0x5cf470[_0x434c('0x25')]){delete _0x5cf470[_0x434c('0x25')];}_0x3f1691[_0x434c('0x18')](_0x222f56)[_0x434c('0x26')](_0x5cf470);};}exports[_0x434c('0x27')]=function(_0x578a53,_0x50c075){var _0x5a6ca9={},_0x396b29={},_0x2e721d={'count':0x0,'rows':[]};var _0x136acd=_[_0x434c('0x28')](db[_0x434c('0x29')]['rawAttributes'],function(_0x1e783b){return{'name':_0x1e783b[_0x434c('0x2a')],'type':_0x1e783b[_0x434c('0x2b')]['key']};});_0x396b29[_0x434c('0x2c')]=_[_0x434c('0x28')](_0x136acd,_0x434c('0x25'));_0x396b29[_0x434c('0x2d')]=_[_0x434c('0x2e')](_0x578a53[_0x434c('0x2d')]);_0x396b29[_0x434c('0x2f')]=_['intersection'](_0x396b29['model'],_0x396b29['query']);_0x5a6ca9[_0x434c('0x30')]=_['intersection'](_0x396b29[_0x434c('0x2c')],qs['fields'](_0x578a53[_0x434c('0x2d')][_0x434c('0x31')]));_0x5a6ca9[_0x434c('0x30')]=_0x5a6ca9[_0x434c('0x30')]['length']?_0x5a6ca9[_0x434c('0x30')]:_0x396b29[_0x434c('0x2c')];if(!_0x578a53[_0x434c('0x2d')]['hasOwnProperty'](_0x434c('0x32'))){_0x5a6ca9[_0x434c('0x1c')]=qs[_0x434c('0x1c')](_0x578a53[_0x434c('0x2d')][_0x434c('0x1c')]);_0x5a6ca9[_0x434c('0x1a')]=qs[_0x434c('0x1a')](_0x578a53[_0x434c('0x2d')][_0x434c('0x1a')]);}_0x5a6ca9[_0x434c('0x33')]=qs[_0x434c('0x34')](_0x578a53[_0x434c('0x2d')][_0x434c('0x34')]);_0x5a6ca9['where']=qs['filters'](_[_0x434c('0x35')](_0x578a53[_0x434c('0x2d')],_0x396b29[_0x434c('0x2f')]),_0x136acd);if(_0x578a53[_0x434c('0x2d')][_0x434c('0x36')]){_0x5a6ca9[_0x434c('0x37')]=_['merge'](_0x5a6ca9[_0x434c('0x37')],{'$or':_['map'](_0x136acd,function(_0x2513c5){if(_0x2513c5[_0x434c('0x2b')]!==_0x434c('0x38')){var _0x114a1a={};_0x114a1a[_0x2513c5[_0x434c('0x25')]]={'$like':'%'+_0x578a53[_0x434c('0x2d')][_0x434c('0x36')]+'%'};return _0x114a1a;}})});}_0x5a6ca9=_[_0x434c('0x39')]({},_0x5a6ca9,_0x578a53[_0x434c('0x3a')]);var _0x23e2e1={'where':_0x5a6ca9['where']};return db[_0x434c('0x29')][_0x434c('0x1d')](_0x23e2e1)[_0x434c('0x21')](function(_0x29207a){_0x2e721d[_0x434c('0x1d')]=_0x29207a;if(_0x578a53[_0x434c('0x2d')]['includeAll']){_0x5a6ca9[_0x434c('0x3b')]=[{'all':!![]}];}return db[_0x434c('0x29')][_0x434c('0x3c')](_0x5a6ca9);})[_0x434c('0x21')](function(_0x3165af){_0x2e721d[_0x434c('0x3d')]=_0x3165af;return _0x2e721d;})[_0x434c('0x21')](respondWithFilteredResult(_0x50c075,_0x5a6ca9))[_0x434c('0x3e')](handleError(_0x50c075,null));};exports[_0x434c('0x3f')]=function(_0x4fd738,_0x48f040){var _0x28ed0b={'raw':!![],'where':{'id':_0x4fd738['params']['id']}},_0x47e7de={};_0x47e7de[_0x434c('0x2c')]=_[_0x434c('0x2e')](db['ChatTransferReport'][_0x434c('0x40')]);_0x47e7de['query']=_['keys'](_0x4fd738[_0x434c('0x2d')]);_0x47e7de[_0x434c('0x2f')]=_[_0x434c('0x41')](_0x47e7de[_0x434c('0x2c')],_0x47e7de[_0x434c('0x2d')]);_0x28ed0b['attributes']=_[_0x434c('0x41')](_0x47e7de[_0x434c('0x2c')],qs[_0x434c('0x31')](_0x4fd738[_0x434c('0x2d')][_0x434c('0x31')]));_0x28ed0b[_0x434c('0x30')]=_0x28ed0b[_0x434c('0x30')][_0x434c('0x42')]?_0x28ed0b[_0x434c('0x30')]:_0x47e7de['model'];if(_0x4fd738[_0x434c('0x2d')][_0x434c('0x43')]){_0x28ed0b[_0x434c('0x3b')]=[{'all':!![]}];}_0x28ed0b=_['merge']({},_0x28ed0b,_0x4fd738[_0x434c('0x3a')]);return db['ChatTransferReport'][_0x434c('0x44')](_0x28ed0b)[_0x434c('0x21')](handleEntityNotFound(_0x48f040,null))[_0x434c('0x21')](respondWithResult(_0x48f040,null))[_0x434c('0x3e')](handleError(_0x48f040,null));};exports[_0x434c('0x45')]=function(_0x440e81,_0x54211b){return db[_0x434c('0x29')][_0x434c('0x45')](_0x440e81['body'],{})[_0x434c('0x21')](respondWithResult(_0x54211b,0xc9))[_0x434c('0x3e')](handleError(_0x54211b,null));};exports['update']=function(_0xa71041,_0x2c16fe){if(_0xa71041[_0x434c('0x46')]['id']){delete _0xa71041['body']['id'];}return db[_0x434c('0x29')][_0x434c('0x44')]({'where':{'id':_0xa71041['params']['id']}})[_0x434c('0x21')](handleEntityNotFound(_0x2c16fe,null))[_0x434c('0x21')](saveUpdates(_0xa71041[_0x434c('0x46')],null))['then'](respondWithResult(_0x2c16fe,null))['catch'](handleError(_0x2c16fe,null));};exports[_0x434c('0x20')]=function(_0x169f2b,_0x45e0f4){return db[_0x434c('0x29')]['find']({'where':{'id':_0x169f2b[_0x434c('0x47')]['id']}})['then'](handleEntityNotFound(_0x45e0f4,null))[_0x434c('0x21')](removeEntity(_0x45e0f4,null))[_0x434c('0x3e')](handleError(_0x45e0f4,null));};exports[_0x434c('0x48')]=function(_0xc0f21e,_0x1c7ca8){return db[_0x434c('0x29')]['describe']()[_0x434c('0x21')](respondWithResult(_0x1c7ca8,null))[_0x434c('0x3e')](handleError(_0x1c7ca8,null));};