773078a7ba32876b176d620c8eefe84db2f1565f
[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 _0x3f06=['map','Cdr','rawAttributes','type','key','model','query','keys','filters','intersection','attributes','fields','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','includeAll','include','findAll','catch','show','params','options','find','create','body','describe','rimraf','fast-json-patch','request-promise','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','squel','crypto','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','../../mysqldb','sendStatus','status','end','count','offset','limit','Content-Range','apply','reject','save','update','then','destroy','error','stack','name','send'];(function(_0xda6d0f,_0x35e271){var _0x244540=function(_0x30f643){while(--_0x30f643){_0xda6d0f['push'](_0xda6d0f['shift']());}};_0x244540(++_0x35e271);}(_0x3f06,0x140));var _0x63f0=function(_0x59ee6f,_0x450239){_0x59ee6f=_0x59ee6f-0x0;var _0x4c0979=_0x3f06[_0x59ee6f];return _0x4c0979;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x63f0('0x0'));var zipdir=require('zip-dir');var jsonpatch=require(_0x63f0('0x1'));var rp=require(_0x63f0('0x2'));var moment=require('moment');var BPromise=require(_0x63f0('0x3'));var Mustache=require(_0x63f0('0x4'));var util=require(_0x63f0('0x5'));var path=require(_0x63f0('0x6'));var sox=require(_0x63f0('0x7'));var csv=require(_0x63f0('0x8'));var ejs=require(_0x63f0('0x9'));var fs=require('fs');var fs_extra=require(_0x63f0('0xa'));var _=require('lodash');var squel=require(_0x63f0('0xb'));var crypto=require(_0x63f0('0xc'));var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0x63f0('0x8'));var querystring=require('querystring');var Papa=require(_0x63f0('0xd'));var Redis=require('ioredis');var authService=require(_0x63f0('0xe'));var qs=require(_0x63f0('0xf'));var as=require(_0x63f0('0x10'));var hardwareService=require(_0x63f0('0x11'));var logger=require(_0x63f0('0x12'))(_0x63f0('0x13'));var utils=require(_0x63f0('0x14'));var config=require('../../config/environment');var licenseUtil=require(_0x63f0('0x15'));var db=require(_0x63f0('0x16'))['db'];function respondWithStatusCode(_0x53e0c8,_0x175981){_0x175981=_0x175981||0xcc;return function(_0x4ead87){if(_0x4ead87){return _0x53e0c8[_0x63f0('0x17')](_0x175981);}return _0x53e0c8[_0x63f0('0x18')](_0x175981)[_0x63f0('0x19')]();};}function respondWithResult(_0x452fbb,_0x2554ee){_0x2554ee=_0x2554ee||0xc8;return function(_0x1dff77){if(_0x1dff77){return _0x452fbb[_0x63f0('0x18')](_0x2554ee)['json'](_0x1dff77);}};}function respondWithFilteredResult(_0x1c9839,_0x3fc451){return function(_0x3d98ec){if(_0x3d98ec){var _0x9706f=_0x3d98ec[_0x63f0('0x1a')],_0x45a5e4=_0x3fc451[_0x63f0('0x1b')],_0xb256b4=_0x3fc451[_0x63f0('0x1b')]+_0x3fc451[_0x63f0('0x1c')],_0x3d53bd;if(_0xb256b4>=_0x9706f){_0xb256b4=_0x9706f;_0x3d53bd=0xc8;}else{_0x3d53bd=0xce;}_0x1c9839['status'](_0x3d53bd);return _0x1c9839['set'](_0x63f0('0x1d'),_0x45a5e4+'-'+_0xb256b4+'/'+_0x9706f)['json'](_0x3d98ec);}return null;};}function patchUpdates(_0x97f747){return function(_0x524598){try{jsonpatch[_0x63f0('0x1e')](_0x524598,_0x97f747,!![]);}catch(_0x47516d){return BPromise[_0x63f0('0x1f')](_0x47516d);}return _0x524598[_0x63f0('0x20')]();};}function saveUpdates(_0x378a0a,_0x5f53c7){return function(_0x3acebe){if(_0x3acebe){return _0x3acebe[_0x63f0('0x21')](_0x378a0a)[_0x63f0('0x22')](function(_0x50516b){return _0x50516b;});}return null;};}function removeEntity(_0x8309d5,_0x5bbdc1){return function(_0x3a6d37){if(_0x3a6d37){return _0x3a6d37[_0x63f0('0x23')]()[_0x63f0('0x22')](function(){_0x8309d5['status'](0xcc)[_0x63f0('0x19')]();});}};}function handleEntityNotFound(_0x5bc916,_0x305c38){return function(_0x2cfe81){if(!_0x2cfe81){_0x5bc916[_0x63f0('0x17')](0x194);}return _0x2cfe81;};}function handleError(_0x300cb6,_0x35c3dd){_0x35c3dd=_0x35c3dd||0x1f4;return function(_0x4b3276){logger[_0x63f0('0x24')](_0x4b3276[_0x63f0('0x25')]);if(_0x4b3276['name']){delete _0x4b3276[_0x63f0('0x26')];}_0x300cb6[_0x63f0('0x18')](_0x35c3dd)[_0x63f0('0x27')](_0x4b3276);};}exports['index']=function(_0x2379e9,_0x371f66){var _0x15625c={},_0x43e115={},_0x36a5ca={'count':0x0,'rows':[]};var _0x23c612=_[_0x63f0('0x28')](db[_0x63f0('0x29')][_0x63f0('0x2a')],function(_0x43160f){return{'name':_0x43160f['fieldName'],'type':_0x43160f[_0x63f0('0x2b')][_0x63f0('0x2c')]};});_0x43e115[_0x63f0('0x2d')]=_[_0x63f0('0x28')](_0x23c612,_0x63f0('0x26'));_0x43e115[_0x63f0('0x2e')]=_[_0x63f0('0x2f')](_0x2379e9[_0x63f0('0x2e')]);_0x43e115[_0x63f0('0x30')]=_[_0x63f0('0x31')](_0x43e115[_0x63f0('0x2d')],_0x43e115['query']);_0x15625c[_0x63f0('0x32')]=_['intersection'](_0x43e115[_0x63f0('0x2d')],qs[_0x63f0('0x33')](_0x2379e9[_0x63f0('0x2e')][_0x63f0('0x33')]));_0x15625c[_0x63f0('0x32')]=_0x15625c[_0x63f0('0x32')]['length']?_0x15625c[_0x63f0('0x32')]:_0x43e115[_0x63f0('0x2d')];if(!_0x2379e9['query'][_0x63f0('0x34')](_0x63f0('0x35'))){_0x15625c[_0x63f0('0x1c')]=qs[_0x63f0('0x1c')](_0x2379e9[_0x63f0('0x2e')][_0x63f0('0x1c')]);_0x15625c[_0x63f0('0x1b')]=qs[_0x63f0('0x1b')](_0x2379e9[_0x63f0('0x2e')][_0x63f0('0x1b')]);}_0x15625c[_0x63f0('0x36')]=qs[_0x63f0('0x37')](_0x2379e9[_0x63f0('0x2e')][_0x63f0('0x37')]);_0x15625c[_0x63f0('0x38')]=qs['filters'](_[_0x63f0('0x39')](_0x2379e9[_0x63f0('0x2e')],_0x43e115[_0x63f0('0x30')]),_0x23c612);if(_0x2379e9[_0x63f0('0x2e')][_0x63f0('0x3a')]){_0x15625c['where']=_[_0x63f0('0x3b')](_0x15625c[_0x63f0('0x38')],{'$or':_['map'](_0x23c612,function(_0x18b119){if(_0x18b119[_0x63f0('0x2b')]!==_0x63f0('0x3c')){var _0x548198={};_0x548198[_0x18b119[_0x63f0('0x26')]]={'$like':'%'+_0x2379e9[_0x63f0('0x2e')][_0x63f0('0x3a')]+'%'};return _0x548198;}})});}_0x15625c=_[_0x63f0('0x3b')]({},_0x15625c,_0x2379e9['options']);var _0x18bca9={'where':_0x15625c[_0x63f0('0x38')]};return db[_0x63f0('0x29')][_0x63f0('0x1a')](_0x18bca9)['then'](function(_0x194f7b){_0x36a5ca[_0x63f0('0x1a')]=_0x194f7b;if(_0x2379e9[_0x63f0('0x2e')][_0x63f0('0x3d')]){_0x15625c[_0x63f0('0x3e')]=[{'all':!![]}];}return db[_0x63f0('0x29')][_0x63f0('0x3f')](_0x15625c);})['then'](function(_0x2e025c){_0x36a5ca['rows']=_0x2e025c;return _0x36a5ca;})[_0x63f0('0x22')](respondWithFilteredResult(_0x371f66,_0x15625c))[_0x63f0('0x40')](handleError(_0x371f66,null));};exports[_0x63f0('0x41')]=function(_0x3a284b,_0x59b8c4){var _0x64debd={'raw':!![],'where':{'id':_0x3a284b[_0x63f0('0x42')]['id']}},_0x4dc953={};_0x4dc953[_0x63f0('0x2d')]=_['keys'](db['Cdr'][_0x63f0('0x2a')]);_0x4dc953[_0x63f0('0x2e')]=_['keys'](_0x3a284b['query']);_0x4dc953[_0x63f0('0x30')]=_['intersection'](_0x4dc953[_0x63f0('0x2d')],_0x4dc953[_0x63f0('0x2e')]);_0x64debd[_0x63f0('0x32')]=_['intersection'](_0x4dc953[_0x63f0('0x2d')],qs[_0x63f0('0x33')](_0x3a284b[_0x63f0('0x2e')][_0x63f0('0x33')]));_0x64debd[_0x63f0('0x32')]=_0x64debd['attributes']['length']?_0x64debd[_0x63f0('0x32')]:_0x4dc953[_0x63f0('0x2d')];if(_0x3a284b[_0x63f0('0x2e')][_0x63f0('0x3d')]){_0x64debd['include']=[{'all':!![]}];}_0x64debd=_['merge']({},_0x64debd,_0x3a284b[_0x63f0('0x43')]);return db['Cdr'][_0x63f0('0x44')](_0x64debd)['then'](handleEntityNotFound(_0x59b8c4,null))[_0x63f0('0x22')](respondWithResult(_0x59b8c4,null))[_0x63f0('0x40')](handleError(_0x59b8c4,null));};exports[_0x63f0('0x45')]=function(_0x3c981a,_0x4ff011){return db[_0x63f0('0x29')][_0x63f0('0x45')](_0x3c981a[_0x63f0('0x46')],{})[_0x63f0('0x22')](respondWithResult(_0x4ff011,0xc9))['catch'](handleError(_0x4ff011,null));};exports[_0x63f0('0x21')]=function(_0x39094f,_0x740bf4){if(_0x39094f['body']['id']){delete _0x39094f[_0x63f0('0x46')]['id'];}return db[_0x63f0('0x29')][_0x63f0('0x44')]({'where':{'id':_0x39094f[_0x63f0('0x42')]['id']}})[_0x63f0('0x22')](handleEntityNotFound(_0x740bf4,null))[_0x63f0('0x22')](saveUpdates(_0x39094f[_0x63f0('0x46')],null))[_0x63f0('0x22')](respondWithResult(_0x740bf4,null))[_0x63f0('0x40')](handleError(_0x740bf4,null));};exports[_0x63f0('0x23')]=function(_0x4921cd,_0x45510b){return db['Cdr'][_0x63f0('0x44')]({'where':{'id':_0x4921cd['params']['id']}})[_0x63f0('0x22')](handleEntityNotFound(_0x45510b,null))[_0x63f0('0x22')](removeEntity(_0x45510b,null))['catch'](handleError(_0x45510b,null));};exports[_0x63f0('0x47')]=function(_0x564d55,_0x354f85){return db['Cdr'][_0x63f0('0x47')]()[_0x63f0('0x22')](respondWithResult(_0x354f85,null))['catch'](handleError(_0x354f85,null));};