Built motion from commit 6362bb75.|2.6.13
[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 _0x23f4=['index','map','Cdr','rawAttributes','fieldName','type','key','model','name','query','keys','filters','intersection','attributes','fields','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','options','includeAll','findAll','rows','catch','show','params','length','include','create','body','update','find','describe','rimraf','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','lodash','squel','jsforce','desk.js','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','undefined','limit','count','set','apply','save','then','destroy','error','stack','send'];(function(_0x59598a,_0x4f26d0){var _0x4b3ae8=function(_0x56df52){while(--_0x56df52){_0x59598a['push'](_0x59598a['shift']());}};_0x4b3ae8(++_0x4f26d0);}(_0x23f4,0x1ee));var _0x423f=function(_0x56df8d,_0x351412){_0x56df8d=_0x56df8d-0x0;var _0x49017e=_0x23f4[_0x56df8d];return _0x49017e;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x423f('0x0'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0x423f('0x1'));var moment=require(_0x423f('0x2'));var BPromise=require(_0x423f('0x3'));var Mustache=require(_0x423f('0x4'));var util=require(_0x423f('0x5'));var path=require(_0x423f('0x6'));var sox=require(_0x423f('0x7'));var csv=require(_0x423f('0x8'));var ejs=require(_0x423f('0x9'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x423f('0xa'));var squel=require(_0x423f('0xb'));var crypto=require('crypto');var jsforce=require(_0x423f('0xc'));var deskjs=require(_0x423f('0xd'));var toCsv=require(_0x423f('0x8'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0x423f('0xe'));var qs=require('../../components/parsers/qs');var as=require(_0x423f('0xf'));var hardwareService=require(_0x423f('0x10'));var logger=require(_0x423f('0x11'))(_0x423f('0x12'));var utils=require('../../config/utils');var config=require(_0x423f('0x13'));var licenseUtil=require(_0x423f('0x14'));var db=require(_0x423f('0x15'))['db'];function respondWithStatusCode(_0x3d4027,_0x216360){_0x216360=_0x216360||0xcc;return function(_0x5275b0){if(_0x5275b0){return _0x3d4027[_0x423f('0x16')](_0x216360);}return _0x3d4027[_0x423f('0x17')](_0x216360)[_0x423f('0x18')]();};}function respondWithResult(_0x1c894f,_0x44e1d5){_0x44e1d5=_0x44e1d5||0xc8;return function(_0x3b531d){if(_0x3b531d){return _0x1c894f[_0x423f('0x17')](_0x44e1d5)[_0x423f('0x19')](_0x3b531d);}};}function respondWithFilteredResult(_0x252e6c,_0x235c86){return function(_0x3940ea){if(_0x3940ea){var _0x276be1=typeof _0x235c86[_0x423f('0x1a')]===_0x423f('0x1b')&&typeof _0x235c86[_0x423f('0x1c')]===_0x423f('0x1b');var _0x3fd56d=_0x3940ea[_0x423f('0x1d')];var _0x26b6d1=_0x276be1?0x0:_0x235c86['offset'];var _0x99435f=_0x276be1?_0x3940ea['count']:_0x235c86['offset']+_0x235c86[_0x423f('0x1c')];var _0x4956e0;if(_0x99435f>=_0x3fd56d){_0x99435f=_0x3fd56d;_0x4956e0=0xc8;}else{_0x4956e0=0xce;}_0x252e6c[_0x423f('0x17')](_0x4956e0);return _0x252e6c[_0x423f('0x1e')]('Content-Range',_0x26b6d1+'-'+_0x99435f+'/'+_0x3fd56d)[_0x423f('0x19')](_0x3940ea);}return null;};}function patchUpdates(_0x1fc317){return function(_0x56c21e){try{jsonpatch[_0x423f('0x1f')](_0x56c21e,_0x1fc317,!![]);}catch(_0x2ebe74){return BPromise['reject'](_0x2ebe74);}return _0x56c21e[_0x423f('0x20')]();};}function saveUpdates(_0x1b4ecc,_0x568dcd){return function(_0x54f47){if(_0x54f47){return _0x54f47['update'](_0x1b4ecc)[_0x423f('0x21')](function(_0x3c942e){return _0x3c942e;});}return null;};}function removeEntity(_0x4502ab,_0x3955a0){return function(_0xb82e8d){if(_0xb82e8d){return _0xb82e8d[_0x423f('0x22')]()[_0x423f('0x21')](function(){_0x4502ab[_0x423f('0x17')](0xcc)[_0x423f('0x18')]();});}};}function handleEntityNotFound(_0x36f57f,_0x45889f){return function(_0x199196){if(!_0x199196){_0x36f57f[_0x423f('0x16')](0x194);}return _0x199196;};}function handleError(_0x1f1747,_0x4a98f2){_0x4a98f2=_0x4a98f2||0x1f4;return function(_0x3308dd){logger[_0x423f('0x23')](_0x3308dd[_0x423f('0x24')]);if(_0x3308dd['name']){delete _0x3308dd['name'];}_0x1f1747[_0x423f('0x17')](_0x4a98f2)[_0x423f('0x25')](_0x3308dd);};}exports[_0x423f('0x26')]=function(_0x4c2f21,_0x5882ed){var _0x3ca28d={},_0xbb4bce={},_0x5a838e={'count':0x0,'rows':[]};var _0x3cf4aa=_[_0x423f('0x27')](db[_0x423f('0x28')][_0x423f('0x29')],function(_0x518c1e){return{'name':_0x518c1e[_0x423f('0x2a')],'type':_0x518c1e[_0x423f('0x2b')][_0x423f('0x2c')]};});_0xbb4bce[_0x423f('0x2d')]=_['map'](_0x3cf4aa,_0x423f('0x2e'));_0xbb4bce[_0x423f('0x2f')]=_[_0x423f('0x30')](_0x4c2f21[_0x423f('0x2f')]);_0xbb4bce[_0x423f('0x31')]=_[_0x423f('0x32')](_0xbb4bce[_0x423f('0x2d')],_0xbb4bce[_0x423f('0x2f')]);_0x3ca28d[_0x423f('0x33')]=_[_0x423f('0x32')](_0xbb4bce['model'],qs[_0x423f('0x34')](_0x4c2f21[_0x423f('0x2f')][_0x423f('0x34')]));_0x3ca28d['attributes']=_0x3ca28d[_0x423f('0x33')]['length']?_0x3ca28d[_0x423f('0x33')]:_0xbb4bce[_0x423f('0x2d')];if(!_0x4c2f21[_0x423f('0x2f')][_0x423f('0x35')](_0x423f('0x36'))){_0x3ca28d['limit']=qs['limit'](_0x4c2f21[_0x423f('0x2f')][_0x423f('0x1c')]);_0x3ca28d[_0x423f('0x1a')]=qs[_0x423f('0x1a')](_0x4c2f21[_0x423f('0x2f')][_0x423f('0x1a')]);}_0x3ca28d[_0x423f('0x37')]=qs[_0x423f('0x38')](_0x4c2f21[_0x423f('0x2f')][_0x423f('0x38')]);_0x3ca28d[_0x423f('0x39')]=qs[_0x423f('0x31')](_[_0x423f('0x3a')](_0x4c2f21['query'],_0xbb4bce['filters']),_0x3cf4aa);if(_0x4c2f21[_0x423f('0x2f')][_0x423f('0x3b')]){_0x3ca28d[_0x423f('0x39')]=_[_0x423f('0x3c')](_0x3ca28d[_0x423f('0x39')],{'$or':_['map'](_0x3cf4aa,function(_0x38dcce){if(_0x38dcce[_0x423f('0x2b')]!==_0x423f('0x3d')){var _0x1d47d8={};_0x1d47d8[_0x38dcce[_0x423f('0x2e')]]={'$like':'%'+_0x4c2f21[_0x423f('0x2f')][_0x423f('0x3b')]+'%'};return _0x1d47d8;}})});}_0x3ca28d=_[_0x423f('0x3c')]({},_0x3ca28d,_0x4c2f21[_0x423f('0x3e')]);var _0x40571a={'where':_0x3ca28d['where']};return db['Cdr'][_0x423f('0x1d')](_0x40571a)[_0x423f('0x21')](function(_0x81bd62){_0x5a838e[_0x423f('0x1d')]=_0x81bd62;if(_0x4c2f21[_0x423f('0x2f')][_0x423f('0x3f')]){_0x3ca28d['include']=[{'all':!![]}];}return db[_0x423f('0x28')][_0x423f('0x40')](_0x3ca28d);})[_0x423f('0x21')](function(_0x393618){_0x5a838e[_0x423f('0x41')]=_0x393618;return _0x5a838e;})[_0x423f('0x21')](respondWithFilteredResult(_0x5882ed,_0x3ca28d))[_0x423f('0x42')](handleError(_0x5882ed,null));};exports[_0x423f('0x43')]=function(_0x518443,_0x4165e0){var _0x3bc113={'raw':!![],'where':{'id':_0x518443[_0x423f('0x44')]['id']}},_0x192ae5={};_0x192ae5[_0x423f('0x2d')]=_[_0x423f('0x30')](db[_0x423f('0x28')][_0x423f('0x29')]);_0x192ae5[_0x423f('0x2f')]=_['keys'](_0x518443[_0x423f('0x2f')]);_0x192ae5['filters']=_[_0x423f('0x32')](_0x192ae5[_0x423f('0x2d')],_0x192ae5[_0x423f('0x2f')]);_0x3bc113[_0x423f('0x33')]=_[_0x423f('0x32')](_0x192ae5[_0x423f('0x2d')],qs[_0x423f('0x34')](_0x518443[_0x423f('0x2f')][_0x423f('0x34')]));_0x3bc113[_0x423f('0x33')]=_0x3bc113[_0x423f('0x33')][_0x423f('0x45')]?_0x3bc113[_0x423f('0x33')]:_0x192ae5[_0x423f('0x2d')];if(_0x518443[_0x423f('0x2f')][_0x423f('0x3f')]){_0x3bc113[_0x423f('0x46')]=[{'all':!![]}];}_0x3bc113=_[_0x423f('0x3c')]({},_0x3bc113,_0x518443[_0x423f('0x3e')]);return db[_0x423f('0x28')]['find'](_0x3bc113)[_0x423f('0x21')](handleEntityNotFound(_0x4165e0,null))['then'](respondWithResult(_0x4165e0,null))[_0x423f('0x42')](handleError(_0x4165e0,null));};exports[_0x423f('0x47')]=function(_0x1cf881,_0x37035a){return db[_0x423f('0x28')][_0x423f('0x47')](_0x1cf881[_0x423f('0x48')],{})[_0x423f('0x21')](respondWithResult(_0x37035a,0xc9))[_0x423f('0x42')](handleError(_0x37035a,null));};exports[_0x423f('0x49')]=function(_0x31b88e,_0x2dcbec){if(_0x31b88e['body']['id']){delete _0x31b88e[_0x423f('0x48')]['id'];}return db[_0x423f('0x28')]['find']({'where':{'id':_0x31b88e[_0x423f('0x44')]['id']}})['then'](handleEntityNotFound(_0x2dcbec,null))[_0x423f('0x21')](saveUpdates(_0x31b88e['body'],null))['then'](respondWithResult(_0x2dcbec,null))[_0x423f('0x42')](handleError(_0x2dcbec,null));};exports[_0x423f('0x22')]=function(_0x1668d4,_0x4114e1){return db['Cdr'][_0x423f('0x4a')]({'where':{'id':_0x1668d4['params']['id']}})[_0x423f('0x21')](handleEntityNotFound(_0x4114e1,null))[_0x423f('0x21')](removeEntity(_0x4114e1,null))[_0x423f('0x42')](handleError(_0x4114e1,null));};exports[_0x423f('0x4b')]=function(_0x17c2b6,_0x961f0d){return db[_0x423f('0x28')][_0x423f('0x4b')]()[_0x423f('0x21')](respondWithResult(_0x961f0d,null))['catch'](handleError(_0x961f0d,null));};