Built motion from commit (unavailable).|2.5.14
[motion2.git] / server / api / cdr / cdr.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 _0xf266=['../../mysqldb','sendStatus','status','json','count','offset','limit','set','reject','update','then','destroy','stack','name','map','Cdr','rawAttributes','fieldName','key','model','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','pick','filter','where','merge','type','options','findAll','rows','catch','show','params','keys','includeAll','include','find','create','body','describe','html-pdf','eml-format','zip-dir','request-promise','moment','bluebird','mustache','util','sox','to-csv','ejs','lodash','squel','crypto','jsforce','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment'];(function(_0x1df3c9,_0x2f0860){var _0x2aa118=function(_0x505c81){while(--_0x505c81){_0x1df3c9['push'](_0x1df3c9['shift']());}};_0x2aa118(++_0x2f0860);}(_0xf266,0x108));var _0x6f26=function(_0x125ff8,_0x41925f){_0x125ff8=_0x125ff8-0x0;var _0x2d9ef=_0xf266[_0x125ff8];return _0x2d9ef;};'use strict';var pdf=require(_0x6f26('0x0'));var emlformat=require(_0x6f26('0x1'));var rimraf=require('rimraf');var zipdir=require(_0x6f26('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0x6f26('0x3'));var moment=require(_0x6f26('0x4'));var BPromise=require(_0x6f26('0x5'));var Mustache=require(_0x6f26('0x6'));var util=require(_0x6f26('0x7'));var path=require('path');var sox=require(_0x6f26('0x8'));var csv=require(_0x6f26('0x9'));var ejs=require(_0x6f26('0xa'));var fs=require('fs');var _=require(_0x6f26('0xb'));var squel=require(_0x6f26('0xc'));var crypto=require(_0x6f26('0xd'));var jsforce=require(_0x6f26('0xe'));var deskjs=require('desk.js');var toCsv=require(_0x6f26('0x9'));var querystring=require(_0x6f26('0xf'));var Papa=require(_0x6f26('0x10'));var Redis=require(_0x6f26('0x11'));var authService=require(_0x6f26('0x12'));var qs=require('../../components/parsers/qs');var as=require(_0x6f26('0x13'));var hardwareService=require(_0x6f26('0x14'));var logger=require('../../config/logger')(_0x6f26('0x15'));var utils=require(_0x6f26('0x16'));var config=require(_0x6f26('0x17'));var licenseUtil=require('../../config/license/util');var db=require(_0x6f26('0x18'))['db'];function respondWithStatusCode(_0x1fcb89,_0xe7e73f){_0xe7e73f=_0xe7e73f||0xcc;return function(_0x45e183){if(_0x45e183){return _0x1fcb89[_0x6f26('0x19')](_0xe7e73f);}return _0x1fcb89[_0x6f26('0x1a')](_0xe7e73f)['end']();};}function respondWithResult(_0xfb590e,_0x3760ce){_0x3760ce=_0x3760ce||0xc8;return function(_0x364371){if(_0x364371){return _0xfb590e[_0x6f26('0x1a')](_0x3760ce)[_0x6f26('0x1b')](_0x364371);}};}function respondWithFilteredResult(_0x57c6d2,_0x7d208d){return function(_0x21156c){if(_0x21156c){var _0x22129f=_0x21156c[_0x6f26('0x1c')],_0x37d639=_0x7d208d['offset'],_0x323b72=_0x7d208d[_0x6f26('0x1d')]+_0x7d208d[_0x6f26('0x1e')],_0x251ad5;if(_0x323b72>=_0x22129f){_0x323b72=_0x22129f;_0x251ad5=0xc8;}else{_0x251ad5=0xce;}_0x57c6d2[_0x6f26('0x1a')](_0x251ad5);return _0x57c6d2[_0x6f26('0x1f')]('Content-Range',_0x37d639+'-'+_0x323b72+'/'+_0x22129f)[_0x6f26('0x1b')](_0x21156c);}return null;};}function patchUpdates(_0x3649ee){return function(_0x36ad11){try{jsonpatch['apply'](_0x36ad11,_0x3649ee,!![]);}catch(_0x4c40a0){return BPromise[_0x6f26('0x20')](_0x4c40a0);}return _0x36ad11['save']();};}function saveUpdates(_0x1a6fc4,_0x7053eb){return function(_0x4ff12c){if(_0x4ff12c){return _0x4ff12c[_0x6f26('0x21')](_0x1a6fc4)[_0x6f26('0x22')](function(_0x254099){return _0x254099;});}return null;};}function removeEntity(_0x33d763,_0x423e68){return function(_0xe7c248){if(_0xe7c248){return _0xe7c248[_0x6f26('0x23')]()[_0x6f26('0x22')](function(){_0x33d763[_0x6f26('0x1a')](0xcc)['end']();});}};}function handleEntityNotFound(_0x148a75,_0x1f096a){return function(_0x1c603e){if(!_0x1c603e){_0x148a75[_0x6f26('0x19')](0x194);}return _0x1c603e;};}function handleError(_0x5ab5d3,_0x18e46c){_0x18e46c=_0x18e46c||0x1f4;return function(_0x2878f6){logger['error'](_0x2878f6[_0x6f26('0x24')]);if(_0x2878f6['name']){delete _0x2878f6[_0x6f26('0x25')];}_0x5ab5d3[_0x6f26('0x1a')](_0x18e46c)['send'](_0x2878f6);};}exports['index']=function(_0x53d10e,_0x39a2ae){var _0x2acdf7={},_0x18134f={},_0x142715={'count':0x0,'rows':[]};var _0x10587e=_[_0x6f26('0x26')](db[_0x6f26('0x27')][_0x6f26('0x28')],function(_0x2db578){return{'name':_0x2db578[_0x6f26('0x29')],'type':_0x2db578['type'][_0x6f26('0x2a')]};});_0x18134f[_0x6f26('0x2b')]=_[_0x6f26('0x26')](_0x10587e,_0x6f26('0x25'));_0x18134f['query']=_['keys'](_0x53d10e[_0x6f26('0x2c')]);_0x18134f[_0x6f26('0x2d')]=_[_0x6f26('0x2e')](_0x18134f[_0x6f26('0x2b')],_0x18134f[_0x6f26('0x2c')]);_0x2acdf7[_0x6f26('0x2f')]=_['intersection'](_0x18134f[_0x6f26('0x2b')],qs[_0x6f26('0x30')](_0x53d10e[_0x6f26('0x2c')][_0x6f26('0x30')]));_0x2acdf7[_0x6f26('0x2f')]=_0x2acdf7[_0x6f26('0x2f')][_0x6f26('0x31')]?_0x2acdf7[_0x6f26('0x2f')]:_0x18134f[_0x6f26('0x2b')];if(!_0x53d10e[_0x6f26('0x2c')][_0x6f26('0x32')](_0x6f26('0x33'))){_0x2acdf7[_0x6f26('0x1e')]=qs[_0x6f26('0x1e')](_0x53d10e[_0x6f26('0x2c')][_0x6f26('0x1e')]);_0x2acdf7['offset']=qs[_0x6f26('0x1d')](_0x53d10e[_0x6f26('0x2c')]['offset']);}_0x2acdf7[_0x6f26('0x34')]=qs['sort'](_0x53d10e[_0x6f26('0x2c')][_0x6f26('0x35')]);_0x2acdf7['where']=qs[_0x6f26('0x2d')](_[_0x6f26('0x36')](_0x53d10e[_0x6f26('0x2c')],_0x18134f[_0x6f26('0x2d')]),_0x10587e);if(_0x53d10e[_0x6f26('0x2c')][_0x6f26('0x37')]){_0x2acdf7[_0x6f26('0x38')]=_[_0x6f26('0x39')](_0x2acdf7[_0x6f26('0x38')],{'$or':_[_0x6f26('0x26')](_0x10587e,function(_0x12f1a5){if(_0x12f1a5[_0x6f26('0x3a')]!=='VIRTUAL'){var _0x5068dd={};_0x5068dd[_0x12f1a5['name']]={'$like':'%'+_0x53d10e['query']['filter']+'%'};return _0x5068dd;}})});}_0x2acdf7=_['merge']({},_0x2acdf7,_0x53d10e[_0x6f26('0x3b')]);var _0x524d57={'where':_0x2acdf7[_0x6f26('0x38')]};return db['Cdr']['count'](_0x524d57)[_0x6f26('0x22')](function(_0x1b424e){_0x142715[_0x6f26('0x1c')]=_0x1b424e;if(_0x53d10e['query']['includeAll']){_0x2acdf7['include']=[{'all':!![]}];}return db['Cdr'][_0x6f26('0x3c')](_0x2acdf7);})[_0x6f26('0x22')](function(_0x2b9f0b){_0x142715[_0x6f26('0x3d')]=_0x2b9f0b;return _0x142715;})[_0x6f26('0x22')](respondWithFilteredResult(_0x39a2ae,_0x2acdf7))[_0x6f26('0x3e')](handleError(_0x39a2ae,null));};exports[_0x6f26('0x3f')]=function(_0x41d72,_0x266a31){var _0x9dfce9={'raw':!![],'where':{'id':_0x41d72[_0x6f26('0x40')]['id']}},_0x49466d={};_0x49466d['model']=_[_0x6f26('0x41')](db[_0x6f26('0x27')][_0x6f26('0x28')]);_0x49466d[_0x6f26('0x2c')]=_[_0x6f26('0x41')](_0x41d72[_0x6f26('0x2c')]);_0x49466d[_0x6f26('0x2d')]=_[_0x6f26('0x2e')](_0x49466d[_0x6f26('0x2b')],_0x49466d[_0x6f26('0x2c')]);_0x9dfce9[_0x6f26('0x2f')]=_[_0x6f26('0x2e')](_0x49466d['model'],qs['fields'](_0x41d72['query'][_0x6f26('0x30')]));_0x9dfce9[_0x6f26('0x2f')]=_0x9dfce9['attributes']['length']?_0x9dfce9['attributes']:_0x49466d['model'];if(_0x41d72[_0x6f26('0x2c')][_0x6f26('0x42')]){_0x9dfce9[_0x6f26('0x43')]=[{'all':!![]}];}_0x9dfce9=_[_0x6f26('0x39')]({},_0x9dfce9,_0x41d72['options']);return db[_0x6f26('0x27')][_0x6f26('0x44')](_0x9dfce9)[_0x6f26('0x22')](handleEntityNotFound(_0x266a31,null))[_0x6f26('0x22')](respondWithResult(_0x266a31,null))[_0x6f26('0x3e')](handleError(_0x266a31,null));};exports[_0x6f26('0x45')]=function(_0x7cd6a,_0x26c58e){return db[_0x6f26('0x27')]['create'](_0x7cd6a[_0x6f26('0x46')],{})['then'](respondWithResult(_0x26c58e,0xc9))[_0x6f26('0x3e')](handleError(_0x26c58e,null));};exports[_0x6f26('0x21')]=function(_0x536469,_0x1c5e98){if(_0x536469['body']['id']){delete _0x536469['body']['id'];}return db[_0x6f26('0x27')][_0x6f26('0x44')]({'where':{'id':_0x536469[_0x6f26('0x40')]['id']}})[_0x6f26('0x22')](handleEntityNotFound(_0x1c5e98,null))['then'](saveUpdates(_0x536469['body'],null))[_0x6f26('0x22')](respondWithResult(_0x1c5e98,null))['catch'](handleError(_0x1c5e98,null));};exports[_0x6f26('0x23')]=function(_0x4e45ed,_0x254f83){return db['Cdr']['find']({'where':{'id':_0x4e45ed[_0x6f26('0x40')]['id']}})[_0x6f26('0x22')](handleEntityNotFound(_0x254f83,null))[_0x6f26('0x22')](removeEntity(_0x254f83,null))[_0x6f26('0x3e')](handleError(_0x254f83,null));};exports[_0x6f26('0x47')]=function(_0x12d864,_0x1f2522){return db[_0x6f26('0x27')][_0x6f26('0x47')]()[_0x6f26('0x22')](respondWithResult(_0x1f2522,null))[_0x6f26('0x3e')](handleError(_0x1f2522,null));};