684b9997e5dcbaaf6937a5d2b262c079befbbb7b
[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 _0xf3c6=['util','sox','to-csv','ejs','lodash','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/parsers/qs','../../config/license/hardware','../../config/logger','../../config/environment','../../mysqldb','sendStatus','status','end','offset','limit','set','Content-Range','json','apply','reject','update','then','error','send','index','map','Cdr','rawAttributes','fieldName','type','key','model','name','query','keys','filters','intersection','attributes','fields','hasOwnProperty','sort','pick','filter','where','VIRTUAL','merge','options','count','includeAll','findAll','rows','catch','params','length','include','create','body','find','destroy','describe','eml-format','zip-dir','bluebird','mustache'];(function(_0x49b950,_0x2de4fb){var _0x17985a=function(_0x2e5a21){while(--_0x2e5a21){_0x49b950['push'](_0x49b950['shift']());}};_0x17985a(++_0x2de4fb);}(_0xf3c6,0x15a));var _0x6f3c=function(_0x355f64,_0x280c54){_0x355f64=_0x355f64-0x0;var _0x1edac6=_0xf3c6[_0x355f64];return _0x1edac6;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0x6f3c('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x6f3c('0x1'));var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require('moment');var BPromise=require(_0x6f3c('0x2'));var Mustache=require(_0x6f3c('0x3'));var util=require(_0x6f3c('0x4'));var path=require('path');var sox=require(_0x6f3c('0x5'));var csv=require(_0x6f3c('0x6'));var ejs=require(_0x6f3c('0x7'));var fs=require('fs');var _=require(_0x6f3c('0x8'));var squel=require('squel');var crypto=require(_0x6f3c('0x9'));var jsforce=require(_0x6f3c('0xa'));var deskjs=require(_0x6f3c('0xb'));var toCsv=require(_0x6f3c('0x6'));var querystring=require(_0x6f3c('0xc'));var Papa=require(_0x6f3c('0xd'));var Redis=require(_0x6f3c('0xe'));var authService=require('../../components/auth/service');var qs=require(_0x6f3c('0xf'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x6f3c('0x10'));var logger=require(_0x6f3c('0x11'))('api');var utils=require('../../config/utils');var config=require(_0x6f3c('0x12'));var licenseUtil=require('../../config/license/util');var db=require(_0x6f3c('0x13'))['db'];function respondWithStatusCode(_0x29d7d2,_0x49b787){_0x49b787=_0x49b787||0xcc;return function(_0x190045){if(_0x190045){return _0x29d7d2[_0x6f3c('0x14')](_0x49b787);}return _0x29d7d2[_0x6f3c('0x15')](_0x49b787)[_0x6f3c('0x16')]();};}function respondWithResult(_0x298955,_0x24304e){_0x24304e=_0x24304e||0xc8;return function(_0x990b84){if(_0x990b84){return _0x298955['status'](_0x24304e)['json'](_0x990b84);}};}function respondWithFilteredResult(_0x13edbd,_0x3a2ae9){return function(_0x14e0b1){if(_0x14e0b1){var _0x10e713=_0x14e0b1['count'],_0x513126=_0x3a2ae9['offset'],_0x22804f=_0x3a2ae9[_0x6f3c('0x17')]+_0x3a2ae9[_0x6f3c('0x18')],_0x382b98;if(_0x22804f>=_0x10e713){_0x22804f=_0x10e713;_0x382b98=0xc8;}else{_0x382b98=0xce;}_0x13edbd[_0x6f3c('0x15')](_0x382b98);return _0x13edbd[_0x6f3c('0x19')](_0x6f3c('0x1a'),_0x513126+'-'+_0x22804f+'/'+_0x10e713)[_0x6f3c('0x1b')](_0x14e0b1);}return null;};}function patchUpdates(_0x478190){return function(_0x56c773){try{jsonpatch[_0x6f3c('0x1c')](_0x56c773,_0x478190,!![]);}catch(_0x2f4dba){return BPromise[_0x6f3c('0x1d')](_0x2f4dba);}return _0x56c773['save']();};}function saveUpdates(_0x9193c2,_0x437425){return function(_0x3ce909){if(_0x3ce909){return _0x3ce909[_0x6f3c('0x1e')](_0x9193c2)[_0x6f3c('0x1f')](function(_0x1a1e6f){return _0x1a1e6f;});}return null;};}function removeEntity(_0x5cf6b5,_0x587ac7){return function(_0x23ee32){if(_0x23ee32){return _0x23ee32['destroy']()[_0x6f3c('0x1f')](function(){_0x5cf6b5[_0x6f3c('0x15')](0xcc)[_0x6f3c('0x16')]();});}};}function handleEntityNotFound(_0x2162fe,_0x245918){return function(_0x4f5761){if(!_0x4f5761){_0x2162fe[_0x6f3c('0x14')](0x194);}return _0x4f5761;};}function handleError(_0x430f57,_0x580f38){_0x580f38=_0x580f38||0x1f4;return function(_0x1bc186){logger[_0x6f3c('0x20')](_0x1bc186['stack']);if(_0x1bc186['name']){delete _0x1bc186['name'];}_0x430f57['status'](_0x580f38)[_0x6f3c('0x21')](_0x1bc186);};}exports[_0x6f3c('0x22')]=function(_0x38a47e,_0x4fcfe3){var _0x50fd91={},_0xa398f0={},_0x5bac03={'count':0x0,'rows':[]};var _0x23b847=_[_0x6f3c('0x23')](db[_0x6f3c('0x24')][_0x6f3c('0x25')],function(_0x498f6e){return{'name':_0x498f6e[_0x6f3c('0x26')],'type':_0x498f6e[_0x6f3c('0x27')][_0x6f3c('0x28')]};});_0xa398f0[_0x6f3c('0x29')]=_[_0x6f3c('0x23')](_0x23b847,_0x6f3c('0x2a'));_0xa398f0[_0x6f3c('0x2b')]=_[_0x6f3c('0x2c')](_0x38a47e['query']);_0xa398f0[_0x6f3c('0x2d')]=_[_0x6f3c('0x2e')](_0xa398f0[_0x6f3c('0x29')],_0xa398f0[_0x6f3c('0x2b')]);_0x50fd91[_0x6f3c('0x2f')]=_[_0x6f3c('0x2e')](_0xa398f0[_0x6f3c('0x29')],qs[_0x6f3c('0x30')](_0x38a47e[_0x6f3c('0x2b')]['fields']));_0x50fd91[_0x6f3c('0x2f')]=_0x50fd91[_0x6f3c('0x2f')]['length']?_0x50fd91[_0x6f3c('0x2f')]:_0xa398f0['model'];if(!_0x38a47e['query'][_0x6f3c('0x31')]('nolimit')){_0x50fd91[_0x6f3c('0x18')]=qs['limit'](_0x38a47e[_0x6f3c('0x2b')]['limit']);_0x50fd91['offset']=qs[_0x6f3c('0x17')](_0x38a47e['query'][_0x6f3c('0x17')]);}_0x50fd91['order']=qs[_0x6f3c('0x32')](_0x38a47e[_0x6f3c('0x2b')][_0x6f3c('0x32')]);_0x50fd91['where']=qs[_0x6f3c('0x2d')](_[_0x6f3c('0x33')](_0x38a47e[_0x6f3c('0x2b')],_0xa398f0[_0x6f3c('0x2d')]),_0x23b847);if(_0x38a47e['query'][_0x6f3c('0x34')]){_0x50fd91[_0x6f3c('0x35')]=_['merge'](_0x50fd91[_0x6f3c('0x35')],{'$or':_[_0x6f3c('0x23')](_0x23b847,function(_0x1638e9){if(_0x1638e9[_0x6f3c('0x27')]!==_0x6f3c('0x36')){var _0x2c1b1b={};_0x2c1b1b[_0x1638e9[_0x6f3c('0x2a')]]={'$like':'%'+_0x38a47e['query']['filter']+'%'};return _0x2c1b1b;}})});}_0x50fd91=_[_0x6f3c('0x37')]({},_0x50fd91,_0x38a47e[_0x6f3c('0x38')]);var _0x2cf25a={'where':_0x50fd91[_0x6f3c('0x35')]};return db[_0x6f3c('0x24')][_0x6f3c('0x39')](_0x2cf25a)['then'](function(_0x328c59){_0x5bac03[_0x6f3c('0x39')]=_0x328c59;if(_0x38a47e[_0x6f3c('0x2b')][_0x6f3c('0x3a')]){_0x50fd91['include']=[{'all':!![]}];}return db[_0x6f3c('0x24')][_0x6f3c('0x3b')](_0x50fd91);})['then'](function(_0x34ca77){_0x5bac03[_0x6f3c('0x3c')]=_0x34ca77;return _0x5bac03;})[_0x6f3c('0x1f')](respondWithFilteredResult(_0x4fcfe3,_0x50fd91))[_0x6f3c('0x3d')](handleError(_0x4fcfe3,null));};exports['show']=function(_0x131b74,_0x3d8e8e){var _0x682c2b={'raw':!![],'where':{'id':_0x131b74[_0x6f3c('0x3e')]['id']}},_0x68de4={};_0x68de4[_0x6f3c('0x29')]=_[_0x6f3c('0x2c')](db[_0x6f3c('0x24')]['rawAttributes']);_0x68de4[_0x6f3c('0x2b')]=_[_0x6f3c('0x2c')](_0x131b74[_0x6f3c('0x2b')]);_0x68de4[_0x6f3c('0x2d')]=_[_0x6f3c('0x2e')](_0x68de4[_0x6f3c('0x29')],_0x68de4['query']);_0x682c2b[_0x6f3c('0x2f')]=_[_0x6f3c('0x2e')](_0x68de4[_0x6f3c('0x29')],qs[_0x6f3c('0x30')](_0x131b74['query'][_0x6f3c('0x30')]));_0x682c2b['attributes']=_0x682c2b[_0x6f3c('0x2f')][_0x6f3c('0x3f')]?_0x682c2b[_0x6f3c('0x2f')]:_0x68de4[_0x6f3c('0x29')];if(_0x131b74[_0x6f3c('0x2b')][_0x6f3c('0x3a')]){_0x682c2b[_0x6f3c('0x40')]=[{'all':!![]}];}_0x682c2b=_[_0x6f3c('0x37')]({},_0x682c2b,_0x131b74[_0x6f3c('0x38')]);return db[_0x6f3c('0x24')]['find'](_0x682c2b)[_0x6f3c('0x1f')](handleEntityNotFound(_0x3d8e8e,null))[_0x6f3c('0x1f')](respondWithResult(_0x3d8e8e,null))[_0x6f3c('0x3d')](handleError(_0x3d8e8e,null));};exports[_0x6f3c('0x41')]=function(_0x326863,_0x342b93){return db[_0x6f3c('0x24')]['create'](_0x326863[_0x6f3c('0x42')],{})[_0x6f3c('0x1f')](respondWithResult(_0x342b93,0xc9))[_0x6f3c('0x3d')](handleError(_0x342b93,null));};exports[_0x6f3c('0x1e')]=function(_0x131a52,_0x14798c){if(_0x131a52[_0x6f3c('0x42')]['id']){delete _0x131a52['body']['id'];}return db[_0x6f3c('0x24')][_0x6f3c('0x43')]({'where':{'id':_0x131a52[_0x6f3c('0x3e')]['id']}})[_0x6f3c('0x1f')](handleEntityNotFound(_0x14798c,null))[_0x6f3c('0x1f')](saveUpdates(_0x131a52[_0x6f3c('0x42')],null))[_0x6f3c('0x1f')](respondWithResult(_0x14798c,null))[_0x6f3c('0x3d')](handleError(_0x14798c,null));};exports[_0x6f3c('0x44')]=function(_0x23642f,_0x53fbed){return db[_0x6f3c('0x24')]['find']({'where':{'id':_0x23642f[_0x6f3c('0x3e')]['id']}})[_0x6f3c('0x1f')](handleEntityNotFound(_0x53fbed,null))['then'](removeEntity(_0x53fbed,null))[_0x6f3c('0x3d')](handleError(_0x53fbed,null));};exports['describe']=function(_0x5aa733,_0x34b308){return db[_0x6f3c('0x24')][_0x6f3c('0x45')]()[_0x6f3c('0x1f')](respondWithResult(_0x34b308,null))[_0x6f3c('0x3d')](handleError(_0x34b308,null));};