b7eae943b4188d6efe3067051f686d79581de3b3
[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 _0x2b83=['stack','name','send','index','Cdr','rawAttributes','fieldName','type','key','model','map','query','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','includeAll','include','findAll','keys','options','create','catch','body','find','params','describe','rimraf','zip-dir','request-promise','moment','bluebird','path','sox','ejs','lodash','squel','crypto','jsforce','to-csv','querystring','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util','sendStatus','end','status','undefined','count','offset','limit','set','json','apply','reject','save','update','destroy','then','error'];(function(_0x4bca3f,_0x1a31e4){var _0x26f293=function(_0x3f353b){while(--_0x3f353b){_0x4bca3f['push'](_0x4bca3f['shift']());}};_0x26f293(++_0x1a31e4);}(_0x2b83,0x1d3));var _0x32b8=function(_0x19403b,_0x33103c){_0x19403b=_0x19403b-0x0;var _0xc0cf67=_0x2b83[_0x19403b];return _0xc0cf67;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x32b8('0x0'));var zipdir=require(_0x32b8('0x1'));var jsonpatch=require('fast-json-patch');var rp=require(_0x32b8('0x2'));var moment=require(_0x32b8('0x3'));var BPromise=require(_0x32b8('0x4'));var Mustache=require('mustache');var util=require('util');var path=require(_0x32b8('0x5'));var sox=require(_0x32b8('0x6'));var csv=require('to-csv');var ejs=require(_0x32b8('0x7'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x32b8('0x8'));var squel=require(_0x32b8('0x9'));var crypto=require(_0x32b8('0xa'));var jsforce=require(_0x32b8('0xb'));var deskjs=require('desk.js');var toCsv=require(_0x32b8('0xc'));var querystring=require(_0x32b8('0xd'));var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0x32b8('0xe'));var qs=require('../../components/parsers/qs');var as=require(_0x32b8('0xf'));var hardwareService=require(_0x32b8('0x10'));var logger=require(_0x32b8('0x11'))(_0x32b8('0x12'));var utils=require('../../config/utils');var config=require(_0x32b8('0x13'));var licenseUtil=require(_0x32b8('0x14'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x49c337,_0x30d00a){_0x30d00a=_0x30d00a||0xcc;return function(_0x5a0ef2){if(_0x5a0ef2){return _0x49c337[_0x32b8('0x15')](_0x30d00a);}return _0x49c337['status'](_0x30d00a)[_0x32b8('0x16')]();};}function respondWithResult(_0x6b533e,_0x3b0fac){_0x3b0fac=_0x3b0fac||0xc8;return function(_0xdf56fb){if(_0xdf56fb){return _0x6b533e[_0x32b8('0x17')](_0x3b0fac)['json'](_0xdf56fb);}};}function respondWithFilteredResult(_0x4c8fc9,_0x5e7b4f){return function(_0x5e49d1){if(_0x5e49d1){var _0x4e0d7a=typeof _0x5e7b4f['offset']===_0x32b8('0x18')&&typeof _0x5e7b4f['limit']==='undefined';var _0x2828fc=_0x5e49d1[_0x32b8('0x19')];var _0x2ba4eb=_0x4e0d7a?0x0:_0x5e7b4f[_0x32b8('0x1a')];var _0x599bc3=_0x4e0d7a?_0x5e49d1['count']:_0x5e7b4f['offset']+_0x5e7b4f[_0x32b8('0x1b')];var _0x2ffea2;if(_0x599bc3>=_0x2828fc){_0x599bc3=_0x2828fc;_0x2ffea2=0xc8;}else{_0x2ffea2=0xce;}_0x4c8fc9[_0x32b8('0x17')](_0x2ffea2);return _0x4c8fc9[_0x32b8('0x1c')]('Content-Range',_0x2ba4eb+'-'+_0x599bc3+'/'+_0x2828fc)[_0x32b8('0x1d')](_0x5e49d1);}return null;};}function patchUpdates(_0x3ddc5f){return function(_0xb51551){try{jsonpatch[_0x32b8('0x1e')](_0xb51551,_0x3ddc5f,!![]);}catch(_0xb9dd1d){return BPromise[_0x32b8('0x1f')](_0xb9dd1d);}return _0xb51551[_0x32b8('0x20')]();};}function saveUpdates(_0xcd4b26,_0x52347c){return function(_0x567055){if(_0x567055){return _0x567055[_0x32b8('0x21')](_0xcd4b26)['then'](function(_0x1ec58d){return _0x1ec58d;});}return null;};}function removeEntity(_0x4bc4a8,_0x1a4c2b){return function(_0x21ee32){if(_0x21ee32){return _0x21ee32[_0x32b8('0x22')]()[_0x32b8('0x23')](function(){_0x4bc4a8[_0x32b8('0x17')](0xcc)['end']();});}};}function handleEntityNotFound(_0x4e1360,_0x25a917){return function(_0x3eea54){if(!_0x3eea54){_0x4e1360[_0x32b8('0x15')](0x194);}return _0x3eea54;};}function handleError(_0x23e195,_0x29988d){_0x29988d=_0x29988d||0x1f4;return function(_0x57a6a3){logger[_0x32b8('0x24')](_0x57a6a3[_0x32b8('0x25')]);if(_0x57a6a3[_0x32b8('0x26')]){delete _0x57a6a3[_0x32b8('0x26')];}_0x23e195[_0x32b8('0x17')](_0x29988d)[_0x32b8('0x27')](_0x57a6a3);};}exports[_0x32b8('0x28')]=function(_0x39ce15,_0x3fa029){var _0xa225ec={},_0x3e0548={},_0x2bc3ce={'count':0x0,'rows':[]};var _0x1fcba2=_['map'](db[_0x32b8('0x29')][_0x32b8('0x2a')],function(_0x383b0e){return{'name':_0x383b0e[_0x32b8('0x2b')],'type':_0x383b0e[_0x32b8('0x2c')][_0x32b8('0x2d')]};});_0x3e0548[_0x32b8('0x2e')]=_[_0x32b8('0x2f')](_0x1fcba2,_0x32b8('0x26'));_0x3e0548[_0x32b8('0x30')]=_['keys'](_0x39ce15[_0x32b8('0x30')]);_0x3e0548[_0x32b8('0x31')]=_[_0x32b8('0x32')](_0x3e0548[_0x32b8('0x2e')],_0x3e0548['query']);_0xa225ec['attributes']=_[_0x32b8('0x32')](_0x3e0548[_0x32b8('0x2e')],qs[_0x32b8('0x33')](_0x39ce15[_0x32b8('0x30')]['fields']));_0xa225ec[_0x32b8('0x34')]=_0xa225ec[_0x32b8('0x34')][_0x32b8('0x35')]?_0xa225ec[_0x32b8('0x34')]:_0x3e0548[_0x32b8('0x2e')];if(!_0x39ce15[_0x32b8('0x30')][_0x32b8('0x36')](_0x32b8('0x37'))){_0xa225ec['limit']=qs[_0x32b8('0x1b')](_0x39ce15['query'][_0x32b8('0x1b')]);_0xa225ec[_0x32b8('0x1a')]=qs[_0x32b8('0x1a')](_0x39ce15[_0x32b8('0x30')][_0x32b8('0x1a')]);}_0xa225ec[_0x32b8('0x38')]=qs['sort'](_0x39ce15[_0x32b8('0x30')][_0x32b8('0x39')]);_0xa225ec[_0x32b8('0x3a')]=qs['filters'](_[_0x32b8('0x3b')](_0x39ce15['query'],_0x3e0548[_0x32b8('0x31')]),_0x1fcba2);if(_0x39ce15[_0x32b8('0x30')][_0x32b8('0x3c')]){_0xa225ec[_0x32b8('0x3a')]=_['merge'](_0xa225ec[_0x32b8('0x3a')],{'$or':_[_0x32b8('0x2f')](_0x1fcba2,function(_0x2d586f){if(_0x2d586f['type']!=='VIRTUAL'){var _0xa8115e={};_0xa8115e[_0x2d586f[_0x32b8('0x26')]]={'$like':'%'+_0x39ce15[_0x32b8('0x30')]['filter']+'%'};return _0xa8115e;}})});}_0xa225ec=_['merge']({},_0xa225ec,_0x39ce15['options']);var _0x1aa6ef={'where':_0xa225ec[_0x32b8('0x3a')]};return db[_0x32b8('0x29')]['count'](_0x1aa6ef)[_0x32b8('0x23')](function(_0x14c109){_0x2bc3ce[_0x32b8('0x19')]=_0x14c109;if(_0x39ce15[_0x32b8('0x30')][_0x32b8('0x3d')]){_0xa225ec[_0x32b8('0x3e')]=[{'all':!![]}];}return db[_0x32b8('0x29')][_0x32b8('0x3f')](_0xa225ec);})['then'](function(_0x39ec33){_0x2bc3ce['rows']=_0x39ec33;return _0x2bc3ce;})['then'](respondWithFilteredResult(_0x3fa029,_0xa225ec))['catch'](handleError(_0x3fa029,null));};exports['show']=function(_0x2d9003,_0x50e6e3){var _0x2a3968={'raw':!![],'where':{'id':_0x2d9003['params']['id']}},_0x52709b={};_0x52709b[_0x32b8('0x2e')]=_[_0x32b8('0x40')](db[_0x32b8('0x29')]['rawAttributes']);_0x52709b[_0x32b8('0x30')]=_[_0x32b8('0x40')](_0x2d9003[_0x32b8('0x30')]);_0x52709b['filters']=_['intersection'](_0x52709b[_0x32b8('0x2e')],_0x52709b['query']);_0x2a3968[_0x32b8('0x34')]=_['intersection'](_0x52709b[_0x32b8('0x2e')],qs['fields'](_0x2d9003[_0x32b8('0x30')][_0x32b8('0x33')]));_0x2a3968[_0x32b8('0x34')]=_0x2a3968[_0x32b8('0x34')]['length']?_0x2a3968['attributes']:_0x52709b[_0x32b8('0x2e')];if(_0x2d9003[_0x32b8('0x30')][_0x32b8('0x3d')]){_0x2a3968['include']=[{'all':!![]}];}_0x2a3968=_['merge']({},_0x2a3968,_0x2d9003[_0x32b8('0x41')]);return db[_0x32b8('0x29')]['find'](_0x2a3968)[_0x32b8('0x23')](handleEntityNotFound(_0x50e6e3,null))['then'](respondWithResult(_0x50e6e3,null))['catch'](handleError(_0x50e6e3,null));};exports['create']=function(_0x250ebf,_0x2d2624){return db[_0x32b8('0x29')][_0x32b8('0x42')](_0x250ebf['body'],{})[_0x32b8('0x23')](respondWithResult(_0x2d2624,0xc9))[_0x32b8('0x43')](handleError(_0x2d2624,null));};exports[_0x32b8('0x21')]=function(_0x29a413,_0x1a5bd4){if(_0x29a413[_0x32b8('0x44')]['id']){delete _0x29a413[_0x32b8('0x44')]['id'];}return db['Cdr'][_0x32b8('0x45')]({'where':{'id':_0x29a413[_0x32b8('0x46')]['id']}})[_0x32b8('0x23')](handleEntityNotFound(_0x1a5bd4,null))[_0x32b8('0x23')](saveUpdates(_0x29a413[_0x32b8('0x44')],null))[_0x32b8('0x23')](respondWithResult(_0x1a5bd4,null))[_0x32b8('0x43')](handleError(_0x1a5bd4,null));};exports[_0x32b8('0x22')]=function(_0x68210a,_0x5b8ca9){return db['Cdr'][_0x32b8('0x45')]({'where':{'id':_0x68210a[_0x32b8('0x46')]['id']}})[_0x32b8('0x23')](handleEntityNotFound(_0x5b8ca9,null))[_0x32b8('0x23')](removeEntity(_0x5b8ca9,null))[_0x32b8('0x43')](handleError(_0x5b8ca9,null));};exports[_0x32b8('0x47')]=function(_0x4f7c6f,_0xde4f61){return db[_0x32b8('0x29')][_0x32b8('0x47')]()[_0x32b8('0x23')](respondWithResult(_0xde4f61,null))['catch'](handleError(_0xde4f61,null));};