13b2f6813a1a3c24e2138aaac2ab25f2de8abaca
[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 _0xf452=['query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','sort','pick','filter','where','merge','includeAll','include','findAll','rows','catch','params','options','create','body','update','find','describe','html-pdf','eml-format','rimraf','request-promise','moment','bluebird','mustache','util','path','sox','ejs','squel','crypto','jsforce','desk.js','to-csv','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','end','status','json','count','offset','limit','set','Content-Range','save','then','destroy','error','stack','name','send','map','Cdr','rawAttributes','fieldName','type','key','model'];(function(_0x32ffb7,_0x4dc572){var _0x1db6a7=function(_0x534be2){while(--_0x534be2){_0x32ffb7['push'](_0x32ffb7['shift']());}};_0x1db6a7(++_0x4dc572);}(_0xf452,0x65));var _0x2f45=function(_0xc586e2,_0x5edf6d){_0xc586e2=_0xc586e2-0x0;var _0x4c7a21=_0xf452[_0xc586e2];return _0x4c7a21;};'use strict';var pdf=require(_0x2f45('0x0'));var emlformat=require(_0x2f45('0x1'));var rimraf=require(_0x2f45('0x2'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0x2f45('0x3'));var moment=require(_0x2f45('0x4'));var BPromise=require(_0x2f45('0x5'));var Mustache=require(_0x2f45('0x6'));var util=require(_0x2f45('0x7'));var path=require(_0x2f45('0x8'));var sox=require(_0x2f45('0x9'));var csv=require('to-csv');var ejs=require(_0x2f45('0xa'));var fs=require('fs');var _=require('lodash');var squel=require(_0x2f45('0xb'));var crypto=require(_0x2f45('0xc'));var jsforce=require(_0x2f45('0xd'));var deskjs=require(_0x2f45('0xe'));var toCsv=require(_0x2f45('0xf'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0x2f45('0x10'));var authService=require(_0x2f45('0x11'));var qs=require(_0x2f45('0x12'));var as=require(_0x2f45('0x13'));var hardwareService=require(_0x2f45('0x14'));var logger=require(_0x2f45('0x15'))(_0x2f45('0x16'));var utils=require(_0x2f45('0x17'));var config=require(_0x2f45('0x18'));var db=require(_0x2f45('0x19'))['db'];function respondWithStatusCode(_0xbe1f08,_0x29983d){_0x29983d=_0x29983d||0xcc;return function(_0x3fdcf2){if(_0x3fdcf2){return _0xbe1f08[_0x2f45('0x1a')](_0x29983d);}return _0xbe1f08['status'](_0x29983d)[_0x2f45('0x1b')]();};}function respondWithResult(_0x2219f0,_0x13748f){_0x13748f=_0x13748f||0xc8;return function(_0x5ece46){if(_0x5ece46){return _0x2219f0[_0x2f45('0x1c')](_0x13748f)[_0x2f45('0x1d')](_0x5ece46);}};}function respondWithFilteredResult(_0x301b31,_0xa8ea15){return function(_0x2f4daf){if(_0x2f4daf){var _0x195a77=_0x2f4daf[_0x2f45('0x1e')],_0xfa36c5=_0xa8ea15[_0x2f45('0x1f')],_0xcc0af8=_0xa8ea15[_0x2f45('0x1f')]+_0xa8ea15[_0x2f45('0x20')],_0x191d5f;if(_0xcc0af8>=_0x195a77){_0xcc0af8=_0x195a77;_0x191d5f=0xc8;}else{_0x191d5f=0xce;}_0x301b31[_0x2f45('0x1c')](_0x191d5f);return _0x301b31[_0x2f45('0x21')](_0x2f45('0x22'),_0xfa36c5+'-'+_0xcc0af8+'/'+_0x195a77)[_0x2f45('0x1d')](_0x2f4daf);}return null;};}function patchUpdates(_0x310e29){return function(_0x54d9d7){try{jsonpatch['apply'](_0x54d9d7,_0x310e29,!![]);}catch(_0x257937){return BPromise['reject'](_0x257937);}return _0x54d9d7[_0x2f45('0x23')]();};}function saveUpdates(_0x399090,_0x41ec9b){return function(_0x1c47f9){if(_0x1c47f9){return _0x1c47f9['update'](_0x399090)[_0x2f45('0x24')](function(_0x5bf8d4){return _0x5bf8d4;});}return null;};}function removeEntity(_0x3883e1,_0x3c1c70){return function(_0x24e9af){if(_0x24e9af){return _0x24e9af[_0x2f45('0x25')]()[_0x2f45('0x24')](function(){_0x3883e1[_0x2f45('0x1c')](0xcc)[_0x2f45('0x1b')]();});}};}function handleEntityNotFound(_0x4ee704,_0x23a7a5){return function(_0x1e70e4){if(!_0x1e70e4){_0x4ee704['sendStatus'](0x194);}return _0x1e70e4;};}function handleError(_0x335a14,_0x412a04){_0x412a04=_0x412a04||0x1f4;return function(_0x74bf4a){logger[_0x2f45('0x26')](_0x74bf4a[_0x2f45('0x27')]);if(_0x74bf4a['name']){delete _0x74bf4a[_0x2f45('0x28')];}_0x335a14[_0x2f45('0x1c')](_0x412a04)[_0x2f45('0x29')](_0x74bf4a);};}exports['index']=function(_0x18c2f9,_0x2e9ba8){var _0x562fc0={},_0xdf60d7={},_0x587714={'count':0x0,'rows':[]};var _0x4d6d79=_[_0x2f45('0x2a')](db[_0x2f45('0x2b')][_0x2f45('0x2c')],function(_0x5406d9){return{'name':_0x5406d9[_0x2f45('0x2d')],'type':_0x5406d9[_0x2f45('0x2e')][_0x2f45('0x2f')]};});_0xdf60d7[_0x2f45('0x30')]=_['map'](_0x4d6d79,_0x2f45('0x28'));_0xdf60d7[_0x2f45('0x31')]=_[_0x2f45('0x32')](_0x18c2f9[_0x2f45('0x31')]);_0xdf60d7[_0x2f45('0x33')]=_[_0x2f45('0x34')](_0xdf60d7[_0x2f45('0x30')],_0xdf60d7[_0x2f45('0x31')]);_0x562fc0[_0x2f45('0x35')]=_[_0x2f45('0x34')](_0xdf60d7[_0x2f45('0x30')],qs[_0x2f45('0x36')](_0x18c2f9['query'][_0x2f45('0x36')]));_0x562fc0[_0x2f45('0x35')]=_0x562fc0[_0x2f45('0x35')][_0x2f45('0x37')]?_0x562fc0['attributes']:_0xdf60d7['model'];if(!_0x18c2f9[_0x2f45('0x31')][_0x2f45('0x38')](_0x2f45('0x39'))){_0x562fc0[_0x2f45('0x20')]=qs[_0x2f45('0x20')](_0x18c2f9[_0x2f45('0x31')][_0x2f45('0x20')]);_0x562fc0[_0x2f45('0x1f')]=qs[_0x2f45('0x1f')](_0x18c2f9[_0x2f45('0x31')]['offset']);}_0x562fc0['order']=qs['sort'](_0x18c2f9[_0x2f45('0x31')][_0x2f45('0x3a')]);_0x562fc0['where']=qs['filters'](_[_0x2f45('0x3b')](_0x18c2f9[_0x2f45('0x31')],_0xdf60d7[_0x2f45('0x33')]),_0x4d6d79);if(_0x18c2f9[_0x2f45('0x31')][_0x2f45('0x3c')]){_0x562fc0[_0x2f45('0x3d')]=_[_0x2f45('0x3e')](_0x562fc0[_0x2f45('0x3d')],{'$or':_[_0x2f45('0x2a')](_0x4d6d79,function(_0x23a671){if(_0x23a671[_0x2f45('0x2e')]!=='VIRTUAL'){var _0x2ad9a2={};_0x2ad9a2[_0x23a671[_0x2f45('0x28')]]={'$like':'%'+_0x18c2f9['query']['filter']+'%'};return _0x2ad9a2;}})});}_0x562fc0=_[_0x2f45('0x3e')]({},_0x562fc0,_0x18c2f9['options']);var _0x5177bb={'where':_0x562fc0[_0x2f45('0x3d')]};return db['Cdr']['count'](_0x5177bb)[_0x2f45('0x24')](function(_0x201059){_0x587714[_0x2f45('0x1e')]=_0x201059;if(_0x18c2f9[_0x2f45('0x31')][_0x2f45('0x3f')]){_0x562fc0[_0x2f45('0x40')]=[{'all':!![]}];}return db[_0x2f45('0x2b')][_0x2f45('0x41')](_0x562fc0);})['then'](function(_0xf8ca63){_0x587714[_0x2f45('0x42')]=_0xf8ca63;return _0x587714;})['then'](respondWithFilteredResult(_0x2e9ba8,_0x562fc0))[_0x2f45('0x43')](handleError(_0x2e9ba8,null));};exports['show']=function(_0x1f33e8,_0x8f9eaa){var _0x482018={'raw':!![],'where':{'id':_0x1f33e8[_0x2f45('0x44')]['id']}},_0x95987c={};_0x95987c[_0x2f45('0x30')]=_[_0x2f45('0x32')](db[_0x2f45('0x2b')][_0x2f45('0x2c')]);_0x95987c[_0x2f45('0x31')]=_[_0x2f45('0x32')](_0x1f33e8[_0x2f45('0x31')]);_0x95987c[_0x2f45('0x33')]=_[_0x2f45('0x34')](_0x95987c['model'],_0x95987c[_0x2f45('0x31')]);_0x482018[_0x2f45('0x35')]=_[_0x2f45('0x34')](_0x95987c[_0x2f45('0x30')],qs['fields'](_0x1f33e8[_0x2f45('0x31')][_0x2f45('0x36')]));_0x482018[_0x2f45('0x35')]=_0x482018[_0x2f45('0x35')][_0x2f45('0x37')]?_0x482018[_0x2f45('0x35')]:_0x95987c['model'];if(_0x1f33e8[_0x2f45('0x31')]['includeAll']){_0x482018[_0x2f45('0x40')]=[{'all':!![]}];}_0x482018=_['merge']({},_0x482018,_0x1f33e8[_0x2f45('0x45')]);return db['Cdr']['find'](_0x482018)[_0x2f45('0x24')](handleEntityNotFound(_0x8f9eaa,null))['then'](respondWithResult(_0x8f9eaa,null))[_0x2f45('0x43')](handleError(_0x8f9eaa,null));};exports[_0x2f45('0x46')]=function(_0x3f6389,_0x2e80f4){return db[_0x2f45('0x2b')][_0x2f45('0x46')](_0x3f6389[_0x2f45('0x47')],{})[_0x2f45('0x24')](respondWithResult(_0x2e80f4,0xc9))[_0x2f45('0x43')](handleError(_0x2e80f4,null));};exports[_0x2f45('0x48')]=function(_0x589d85,_0x19d4b9){if(_0x589d85[_0x2f45('0x47')]['id']){delete _0x589d85['body']['id'];}return db['Cdr']['find']({'where':{'id':_0x589d85['params']['id']}})[_0x2f45('0x24')](handleEntityNotFound(_0x19d4b9,null))[_0x2f45('0x24')](saveUpdates(_0x589d85[_0x2f45('0x47')],null))[_0x2f45('0x24')](respondWithResult(_0x19d4b9,null))[_0x2f45('0x43')](handleError(_0x19d4b9,null));};exports[_0x2f45('0x25')]=function(_0x2c70f2,_0x2e46de){return db[_0x2f45('0x2b')][_0x2f45('0x49')]({'where':{'id':_0x2c70f2['params']['id']}})[_0x2f45('0x24')](handleEntityNotFound(_0x2e46de,null))[_0x2f45('0x24')](removeEntity(_0x2e46de,null))[_0x2f45('0x43')](handleError(_0x2e46de,null));};exports[_0x2f45('0x4a')]=function(_0x59235d,_0x394bac){return db['Cdr'][_0x2f45('0x4a')]()[_0x2f45('0x24')](respondWithResult(_0x394bac,null))[_0x2f45('0x43')](handleError(_0x394bac,null));};