Built motion from commit 44b1f254.|2.6.26
[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 _0x87f5=['sendStatus','status','end','json','limit','offset','count','set','Content-Range','reject','save','update','destroy','then','error','stack','name','send','index','map','fieldName','type','model','query','filters','intersection','attributes','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','options','ChatTransferReport','includeAll','include','rows','show','rawAttributes','fields','find','catch','create','body','params','describe','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','util','sox','to-csv','fs-extra','lodash','squel','jsforce','querystring','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0x87f5,0xc5));var _0x587f=function(_0x25667f,_0x57980b){_0x25667f=_0x25667f-0x0;var _0x39ad0e=_0x87f5[_0x25667f];return _0x39ad0e;};'use strict';var emlformat=require(_0x587f('0x0'));var rimraf=require(_0x587f('0x1'));var zipdir=require(_0x587f('0x2'));var jsonpatch=require(_0x587f('0x3'));var rp=require(_0x587f('0x4'));var moment=require(_0x587f('0x5'));var BPromise=require(_0x587f('0x6'));var Mustache=require('mustache');var util=require(_0x587f('0x7'));var path=require('path');var sox=require(_0x587f('0x8'));var csv=require(_0x587f('0x9'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x587f('0xa'));var _=require(_0x587f('0xb'));var squel=require(_0x587f('0xc'));var crypto=require('crypto');var jsforce=require(_0x587f('0xd'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require(_0x587f('0xe'));var Papa=require('papaparse');var Redis=require(_0x587f('0xf'));var authService=require(_0x587f('0x10'));var qs=require('../../components/parsers/qs');var as=require(_0x587f('0x11'));var hardwareService=require(_0x587f('0x12'));var logger=require('../../config/logger')(_0x587f('0x13'));var utils=require(_0x587f('0x14'));var config=require(_0x587f('0x15'));var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x50765a,_0x40f98a){_0x40f98a=_0x40f98a||0xcc;return function(_0x21eac7){if(_0x21eac7){return _0x50765a[_0x587f('0x16')](_0x40f98a);}return _0x50765a[_0x587f('0x17')](_0x40f98a)[_0x587f('0x18')]();};}function respondWithResult(_0x9af2d8,_0x5119c7){_0x5119c7=_0x5119c7||0xc8;return function(_0x96f12c){if(_0x96f12c){return _0x9af2d8[_0x587f('0x17')](_0x5119c7)[_0x587f('0x19')](_0x96f12c);}};}function respondWithFilteredResult(_0x3a9faf,_0x124bf3){return function(_0x4bf832){if(_0x4bf832){var _0x10629d=typeof _0x124bf3['offset']==='undefined'&&typeof _0x124bf3[_0x587f('0x1a')]==='undefined';var _0x2bf8c6=_0x4bf832['count'];var _0xd3c399=_0x10629d?0x0:_0x124bf3[_0x587f('0x1b')];var _0x51002b=_0x10629d?_0x4bf832[_0x587f('0x1c')]:_0x124bf3[_0x587f('0x1b')]+_0x124bf3[_0x587f('0x1a')];var _0x5cb237;if(_0x51002b>=_0x2bf8c6){_0x51002b=_0x2bf8c6;_0x5cb237=0xc8;}else{_0x5cb237=0xce;}_0x3a9faf[_0x587f('0x17')](_0x5cb237);return _0x3a9faf[_0x587f('0x1d')](_0x587f('0x1e'),_0xd3c399+'-'+_0x51002b+'/'+_0x2bf8c6)[_0x587f('0x19')](_0x4bf832);}return null;};}function patchUpdates(_0x35f5c5){return function(_0x71294f){try{jsonpatch['apply'](_0x71294f,_0x35f5c5,!![]);}catch(_0xad18d){return BPromise[_0x587f('0x1f')](_0xad18d);}return _0x71294f[_0x587f('0x20')]();};}function saveUpdates(_0x91a9c2,_0x2c5bdb){return function(_0x9ae7f8){if(_0x9ae7f8){return _0x9ae7f8[_0x587f('0x21')](_0x91a9c2)['then'](function(_0x25f2da){return _0x25f2da;});}return null;};}function removeEntity(_0x339eeb,_0x4e2a84){return function(_0x3580d4){if(_0x3580d4){return _0x3580d4[_0x587f('0x22')]()[_0x587f('0x23')](function(){_0x339eeb['status'](0xcc)[_0x587f('0x18')]();});}};}function handleEntityNotFound(_0x17c8d5,_0x459874){return function(_0x1b62d4){if(!_0x1b62d4){_0x17c8d5[_0x587f('0x16')](0x194);}return _0x1b62d4;};}function handleError(_0x55a952,_0x34b6a2){_0x34b6a2=_0x34b6a2||0x1f4;return function(_0x58ad7b){logger[_0x587f('0x24')](_0x58ad7b[_0x587f('0x25')]);if(_0x58ad7b[_0x587f('0x26')]){delete _0x58ad7b[_0x587f('0x26')];}_0x55a952[_0x587f('0x17')](_0x34b6a2)[_0x587f('0x27')](_0x58ad7b);};}exports[_0x587f('0x28')]=function(_0x57a159,_0x1bfa92){var _0x57461a={},_0x57d813={},_0x2ed6b1={'count':0x0,'rows':[]};var _0x49f2f4=_[_0x587f('0x29')](db['ChatTransferReport']['rawAttributes'],function(_0x2388cf){return{'name':_0x2388cf[_0x587f('0x2a')],'type':_0x2388cf[_0x587f('0x2b')]['key']};});_0x57d813[_0x587f('0x2c')]=_[_0x587f('0x29')](_0x49f2f4,'name');_0x57d813[_0x587f('0x2d')]=_['keys'](_0x57a159[_0x587f('0x2d')]);_0x57d813[_0x587f('0x2e')]=_[_0x587f('0x2f')](_0x57d813[_0x587f('0x2c')],_0x57d813[_0x587f('0x2d')]);_0x57461a[_0x587f('0x30')]=_[_0x587f('0x2f')](_0x57d813[_0x587f('0x2c')],qs['fields'](_0x57a159[_0x587f('0x2d')]['fields']));_0x57461a[_0x587f('0x30')]=_0x57461a[_0x587f('0x30')][_0x587f('0x31')]?_0x57461a['attributes']:_0x57d813[_0x587f('0x2c')];if(!_0x57a159[_0x587f('0x2d')][_0x587f('0x32')](_0x587f('0x33'))){_0x57461a[_0x587f('0x1a')]=qs['limit'](_0x57a159[_0x587f('0x2d')][_0x587f('0x1a')]);_0x57461a[_0x587f('0x1b')]=qs['offset'](_0x57a159[_0x587f('0x2d')]['offset']);}_0x57461a[_0x587f('0x34')]=qs[_0x587f('0x35')](_0x57a159[_0x587f('0x2d')]['sort']);_0x57461a[_0x587f('0x36')]=qs[_0x587f('0x2e')](_[_0x587f('0x37')](_0x57a159[_0x587f('0x2d')],_0x57d813[_0x587f('0x2e')]),_0x49f2f4);if(_0x57a159[_0x587f('0x2d')][_0x587f('0x38')]){_0x57461a[_0x587f('0x36')]=_[_0x587f('0x39')](_0x57461a[_0x587f('0x36')],{'$or':_[_0x587f('0x29')](_0x49f2f4,function(_0x1576e8){if(_0x1576e8['type']!==_0x587f('0x3a')){var _0x38a223={};_0x38a223[_0x1576e8[_0x587f('0x26')]]={'$like':'%'+_0x57a159[_0x587f('0x2d')]['filter']+'%'};return _0x38a223;}})});}_0x57461a=_[_0x587f('0x39')]({},_0x57461a,_0x57a159[_0x587f('0x3b')]);var _0x41e765={'where':_0x57461a['where']};return db[_0x587f('0x3c')][_0x587f('0x1c')](_0x41e765)['then'](function(_0x38c510){_0x2ed6b1[_0x587f('0x1c')]=_0x38c510;if(_0x57a159[_0x587f('0x2d')][_0x587f('0x3d')]){_0x57461a[_0x587f('0x3e')]=[{'all':!![]}];}return db['ChatTransferReport']['findAll'](_0x57461a);})[_0x587f('0x23')](function(_0x582b54){_0x2ed6b1[_0x587f('0x3f')]=_0x582b54;return _0x2ed6b1;})[_0x587f('0x23')](respondWithFilteredResult(_0x1bfa92,_0x57461a))['catch'](handleError(_0x1bfa92,null));};exports[_0x587f('0x40')]=function(_0x3cf4d0,_0x257a3e){var _0x5b52ee={'raw':!![],'where':{'id':_0x3cf4d0['params']['id']}},_0x406a5b={};_0x406a5b['model']=_['keys'](db[_0x587f('0x3c')][_0x587f('0x41')]);_0x406a5b[_0x587f('0x2d')]=_['keys'](_0x3cf4d0[_0x587f('0x2d')]);_0x406a5b[_0x587f('0x2e')]=_[_0x587f('0x2f')](_0x406a5b['model'],_0x406a5b[_0x587f('0x2d')]);_0x5b52ee['attributes']=_[_0x587f('0x2f')](_0x406a5b['model'],qs[_0x587f('0x42')](_0x3cf4d0[_0x587f('0x2d')][_0x587f('0x42')]));_0x5b52ee[_0x587f('0x30')]=_0x5b52ee[_0x587f('0x30')]['length']?_0x5b52ee[_0x587f('0x30')]:_0x406a5b[_0x587f('0x2c')];if(_0x3cf4d0[_0x587f('0x2d')][_0x587f('0x3d')]){_0x5b52ee[_0x587f('0x3e')]=[{'all':!![]}];}_0x5b52ee=_[_0x587f('0x39')]({},_0x5b52ee,_0x3cf4d0[_0x587f('0x3b')]);return db[_0x587f('0x3c')][_0x587f('0x43')](_0x5b52ee)[_0x587f('0x23')](handleEntityNotFound(_0x257a3e,null))[_0x587f('0x23')](respondWithResult(_0x257a3e,null))[_0x587f('0x44')](handleError(_0x257a3e,null));};exports[_0x587f('0x45')]=function(_0x594934,_0x360a36){return db[_0x587f('0x3c')][_0x587f('0x45')](_0x594934[_0x587f('0x46')],{})[_0x587f('0x23')](respondWithResult(_0x360a36,0xc9))['catch'](handleError(_0x360a36,null));};exports['update']=function(_0x29cded,_0x2155b6){if(_0x29cded[_0x587f('0x46')]['id']){delete _0x29cded[_0x587f('0x46')]['id'];}return db[_0x587f('0x3c')][_0x587f('0x43')]({'where':{'id':_0x29cded['params']['id']}})['then'](handleEntityNotFound(_0x2155b6,null))[_0x587f('0x23')](saveUpdates(_0x29cded[_0x587f('0x46')],null))[_0x587f('0x23')](respondWithResult(_0x2155b6,null))['catch'](handleError(_0x2155b6,null));};exports[_0x587f('0x22')]=function(_0x257960,_0x3033c1){return db['ChatTransferReport']['find']({'where':{'id':_0x257960[_0x587f('0x47')]['id']}})[_0x587f('0x23')](handleEntityNotFound(_0x3033c1,null))['then'](removeEntity(_0x3033c1,null))[_0x587f('0x44')](handleError(_0x3033c1,null));};exports[_0x587f('0x48')]=function(_0x2d7067,_0x51bdb1){return db[_0x587f('0x3c')][_0x587f('0x48')]()[_0x587f('0x23')](respondWithResult(_0x51bdb1,null))['catch'](handleError(_0x51bdb1,null));};