Built motion from commit (unavailable).|2.5.3
[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 _0xe228=['intersection','fields','attributes','length','nolimit','order','sort','where','merge','VIRTUAL','filter','options','includeAll','findAll','rows','catch','show','params','include','find','create','body','describe','html-pdf','eml-format','fast-json-patch','request-promise','moment','path','sox','to-csv','ejs','lodash','squel','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','api','../../config/utils','../../config/environment','sendStatus','end','json','count','offset','limit','status','Content-Range','reject','save','update','then','destroy','name','send','index','map','Cdr','rawAttributes','type','key','model','keys','query','filters'];(function(_0x4ae32d,_0x256489){var _0x550537=function(_0x534d63){while(--_0x534d63){_0x4ae32d['push'](_0x4ae32d['shift']());}};_0x550537(++_0x256489);}(_0xe228,0x175));var _0x8e22=function(_0x8e263b,_0x217ef7){_0x8e263b=_0x8e263b-0x0;var _0x1e6728=_0xe228[_0x8e263b];return _0x1e6728;};'use strict';var pdf=require(_0x8e22('0x0'));var emlformat=require(_0x8e22('0x1'));var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require(_0x8e22('0x2'));var rp=require(_0x8e22('0x3'));var moment=require(_0x8e22('0x4'));var BPromise=require('bluebird');var Mustache=require('mustache');var util=require('util');var path=require(_0x8e22('0x5'));var sox=require(_0x8e22('0x6'));var csv=require(_0x8e22('0x7'));var ejs=require(_0x8e22('0x8'));var fs=require('fs');var _=require(_0x8e22('0x9'));var squel=require(_0x8e22('0xa'));var crypto=require('crypto');var jsforce=require(_0x8e22('0xb'));var deskjs=require(_0x8e22('0xc'));var toCsv=require(_0x8e22('0x7'));var querystring=require(_0x8e22('0xd'));var Papa=require(_0x8e22('0xe'));var Redis=require(_0x8e22('0xf'));var authService=require(_0x8e22('0x10'));var qs=require(_0x8e22('0x11'));var as=require(_0x8e22('0x12'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0x8e22('0x13'));var utils=require(_0x8e22('0x14'));var config=require(_0x8e22('0x15'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x4732d6,_0x49eb79){_0x49eb79=_0x49eb79||0xcc;return function(_0x35a513){if(_0x35a513){return _0x4732d6[_0x8e22('0x16')](_0x49eb79);}return _0x4732d6['status'](_0x49eb79)[_0x8e22('0x17')]();};}function respondWithResult(_0x5c229d,_0x19affd){_0x19affd=_0x19affd||0xc8;return function(_0x15e982){if(_0x15e982){return _0x5c229d['status'](_0x19affd)[_0x8e22('0x18')](_0x15e982);}};}function respondWithFilteredResult(_0x4d8022,_0x2f5379){return function(_0x4a32d3){if(_0x4a32d3){var _0x48a4c3=_0x4a32d3[_0x8e22('0x19')],_0x4bc802=_0x2f5379[_0x8e22('0x1a')],_0x5dd3cb=_0x2f5379[_0x8e22('0x1a')]+_0x2f5379[_0x8e22('0x1b')],_0x2e22ba;if(_0x5dd3cb>=_0x48a4c3){_0x5dd3cb=_0x48a4c3;_0x2e22ba=0xc8;}else{_0x2e22ba=0xce;}_0x4d8022[_0x8e22('0x1c')](_0x2e22ba);return _0x4d8022['set'](_0x8e22('0x1d'),_0x4bc802+'-'+_0x5dd3cb+'/'+_0x48a4c3)['json'](_0x4a32d3);}return null;};}function patchUpdates(_0x2595ac){return function(_0x549622){try{jsonpatch['apply'](_0x549622,_0x2595ac,!![]);}catch(_0x44a54a){return BPromise[_0x8e22('0x1e')](_0x44a54a);}return _0x549622[_0x8e22('0x1f')]();};}function saveUpdates(_0x30135c,_0x3fd03e){return function(_0x2f8a57){if(_0x2f8a57){return _0x2f8a57[_0x8e22('0x20')](_0x30135c)[_0x8e22('0x21')](function(_0x3ada00){return _0x3ada00;});}return null;};}function removeEntity(_0x441eb1,_0x4410aa){return function(_0x2e98d2){if(_0x2e98d2){return _0x2e98d2[_0x8e22('0x22')]()[_0x8e22('0x21')](function(){_0x441eb1[_0x8e22('0x1c')](0xcc)[_0x8e22('0x17')]();});}};}function handleEntityNotFound(_0x1fbf3b,_0x215fc1){return function(_0x1811db){if(!_0x1811db){_0x1fbf3b['sendStatus'](0x194);}return _0x1811db;};}function handleError(_0x2fdee1,_0x392abb){_0x392abb=_0x392abb||0x1f4;return function(_0xe571cd){logger['error'](_0xe571cd['stack']);if(_0xe571cd['name']){delete _0xe571cd[_0x8e22('0x23')];}_0x2fdee1[_0x8e22('0x1c')](_0x392abb)[_0x8e22('0x24')](_0xe571cd);};}exports[_0x8e22('0x25')]=function(_0x4e8a8f,_0x54eed9){var _0x28811b={},_0x2bcba2={},_0x3c7ddb={'count':0x0,'rows':[]};var _0xa1cfbb=_[_0x8e22('0x26')](db[_0x8e22('0x27')][_0x8e22('0x28')],function(_0x1e9e21){return{'name':_0x1e9e21['fieldName'],'type':_0x1e9e21[_0x8e22('0x29')][_0x8e22('0x2a')]};});_0x2bcba2[_0x8e22('0x2b')]=_[_0x8e22('0x26')](_0xa1cfbb,_0x8e22('0x23'));_0x2bcba2['query']=_[_0x8e22('0x2c')](_0x4e8a8f[_0x8e22('0x2d')]);_0x2bcba2[_0x8e22('0x2e')]=_[_0x8e22('0x2f')](_0x2bcba2['model'],_0x2bcba2['query']);_0x28811b['attributes']=_[_0x8e22('0x2f')](_0x2bcba2[_0x8e22('0x2b')],qs[_0x8e22('0x30')](_0x4e8a8f['query'][_0x8e22('0x30')]));_0x28811b[_0x8e22('0x31')]=_0x28811b[_0x8e22('0x31')][_0x8e22('0x32')]?_0x28811b[_0x8e22('0x31')]:_0x2bcba2[_0x8e22('0x2b')];if(!_0x4e8a8f[_0x8e22('0x2d')]['hasOwnProperty'](_0x8e22('0x33'))){_0x28811b[_0x8e22('0x1b')]=qs[_0x8e22('0x1b')](_0x4e8a8f[_0x8e22('0x2d')][_0x8e22('0x1b')]);_0x28811b[_0x8e22('0x1a')]=qs[_0x8e22('0x1a')](_0x4e8a8f[_0x8e22('0x2d')]['offset']);}_0x28811b[_0x8e22('0x34')]=qs[_0x8e22('0x35')](_0x4e8a8f[_0x8e22('0x2d')]['sort']);_0x28811b[_0x8e22('0x36')]=qs['filters'](_['pick'](_0x4e8a8f[_0x8e22('0x2d')],_0x2bcba2[_0x8e22('0x2e')]),_0xa1cfbb);if(_0x4e8a8f['query']['filter']){_0x28811b[_0x8e22('0x36')]=_[_0x8e22('0x37')](_0x28811b[_0x8e22('0x36')],{'$or':_['map'](_0xa1cfbb,function(_0xab384e){if(_0xab384e[_0x8e22('0x29')]!==_0x8e22('0x38')){var _0x459094={};_0x459094[_0xab384e[_0x8e22('0x23')]]={'$like':'%'+_0x4e8a8f['query'][_0x8e22('0x39')]+'%'};return _0x459094;}})});}_0x28811b=_['merge']({},_0x28811b,_0x4e8a8f[_0x8e22('0x3a')]);var _0x280959={'where':_0x28811b[_0x8e22('0x36')]};return db[_0x8e22('0x27')][_0x8e22('0x19')](_0x280959)[_0x8e22('0x21')](function(_0x464e10){_0x3c7ddb[_0x8e22('0x19')]=_0x464e10;if(_0x4e8a8f[_0x8e22('0x2d')][_0x8e22('0x3b')]){_0x28811b['include']=[{'all':!![]}];}return db['Cdr'][_0x8e22('0x3c')](_0x28811b);})[_0x8e22('0x21')](function(_0x51e96a){_0x3c7ddb[_0x8e22('0x3d')]=_0x51e96a;return _0x3c7ddb;})[_0x8e22('0x21')](respondWithFilteredResult(_0x54eed9,_0x28811b))[_0x8e22('0x3e')](handleError(_0x54eed9,null));};exports[_0x8e22('0x3f')]=function(_0x45de17,_0x31488a){var _0x6b82b3={'raw':!![],'where':{'id':_0x45de17[_0x8e22('0x40')]['id']}},_0x1083a5={};_0x1083a5[_0x8e22('0x2b')]=_[_0x8e22('0x2c')](db['Cdr']['rawAttributes']);_0x1083a5[_0x8e22('0x2d')]=_['keys'](_0x45de17['query']);_0x1083a5[_0x8e22('0x2e')]=_[_0x8e22('0x2f')](_0x1083a5[_0x8e22('0x2b')],_0x1083a5['query']);_0x6b82b3[_0x8e22('0x31')]=_[_0x8e22('0x2f')](_0x1083a5['model'],qs[_0x8e22('0x30')](_0x45de17[_0x8e22('0x2d')][_0x8e22('0x30')]));_0x6b82b3[_0x8e22('0x31')]=_0x6b82b3[_0x8e22('0x31')][_0x8e22('0x32')]?_0x6b82b3[_0x8e22('0x31')]:_0x1083a5[_0x8e22('0x2b')];if(_0x45de17[_0x8e22('0x2d')][_0x8e22('0x3b')]){_0x6b82b3[_0x8e22('0x41')]=[{'all':!![]}];}_0x6b82b3=_[_0x8e22('0x37')]({},_0x6b82b3,_0x45de17[_0x8e22('0x3a')]);return db['Cdr'][_0x8e22('0x42')](_0x6b82b3)['then'](handleEntityNotFound(_0x31488a,null))[_0x8e22('0x21')](respondWithResult(_0x31488a,null))[_0x8e22('0x3e')](handleError(_0x31488a,null));};exports['create']=function(_0x445666,_0x29b11b){return db[_0x8e22('0x27')][_0x8e22('0x43')](_0x445666[_0x8e22('0x44')],{})[_0x8e22('0x21')](respondWithResult(_0x29b11b,0xc9))[_0x8e22('0x3e')](handleError(_0x29b11b,null));};exports[_0x8e22('0x20')]=function(_0x27932a,_0x5252f4){if(_0x27932a[_0x8e22('0x44')]['id']){delete _0x27932a['body']['id'];}return db[_0x8e22('0x27')][_0x8e22('0x42')]({'where':{'id':_0x27932a[_0x8e22('0x40')]['id']}})['then'](handleEntityNotFound(_0x5252f4,null))['then'](saveUpdates(_0x27932a[_0x8e22('0x44')],null))[_0x8e22('0x21')](respondWithResult(_0x5252f4,null))['catch'](handleError(_0x5252f4,null));};exports[_0x8e22('0x22')]=function(_0x322370,_0xf38d6f){return db[_0x8e22('0x27')][_0x8e22('0x42')]({'where':{'id':_0x322370[_0x8e22('0x40')]['id']}})['then'](handleEntityNotFound(_0xf38d6f,null))[_0x8e22('0x21')](removeEntity(_0xf38d6f,null))[_0x8e22('0x3e')](handleError(_0xf38d6f,null));};exports[_0x8e22('0x45')]=function(_0x20fd27,_0x4ca19e){return db[_0x8e22('0x27')][_0x8e22('0x45')]()[_0x8e22('0x21')](respondWithResult(_0x4ca19e,null))[_0x8e22('0x3e')](handleError(_0x4ca19e,null));};