009e1a41ed74fd49bb5a7d13dd335e5aecc091d0
[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 _0xc33f=['map','Cdr','fieldName','type','key','model','query','keys','intersection','fields','attributes','length','nolimit','order','sort','filters','pick','merge','where','VIRTUAL','filter','options','include','findAll','rows','catch','params','rawAttributes','includeAll','find','create','body','destroy','describe','html-pdf','eml-format','request-promise','moment','bluebird','mustache','util','path','sox','ejs','crypto','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../mysqldb','end','json','count','offset','limit','Content-Range','apply','reject','save','update','then','status','sendStatus','error','stack','name','send','index'];(function(_0x40a045,_0x516f0e){var _0x1a687c=function(_0x48c9fe){while(--_0x48c9fe){_0x40a045['push'](_0x40a045['shift']());}};_0x1a687c(++_0x516f0e);}(_0xc33f,0x194));var _0xfc33=function(_0x1e9c70,_0x368b6b){_0x1e9c70=_0x1e9c70-0x0;var _0x517ec3=_0xc33f[_0x1e9c70];return _0x517ec3;};'use strict';var pdf=require(_0xfc33('0x0'));var emlformat=require(_0xfc33('0x1'));var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0xfc33('0x2'));var moment=require(_0xfc33('0x3'));var BPromise=require(_0xfc33('0x4'));var Mustache=require(_0xfc33('0x5'));var util=require(_0xfc33('0x6'));var path=require(_0xfc33('0x7'));var sox=require(_0xfc33('0x8'));var csv=require('to-csv');var ejs=require(_0xfc33('0x9'));var fs=require('fs');var _=require('lodash');var squel=require('squel');var crypto=require(_0xfc33('0xa'));var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0xfc33('0xb'));var querystring=require(_0xfc33('0xc'));var Papa=require(_0xfc33('0xd'));var Redis=require(_0xfc33('0xe'));var authService=require(_0xfc33('0xf'));var qs=require('../../components/parsers/qs');var as=require(_0xfc33('0x10'));var hardwareService=require(_0xfc33('0x11'));var logger=require(_0xfc33('0x12'))('api');var utils=require(_0xfc33('0x13'));var config=require(_0xfc33('0x14'));var db=require(_0xfc33('0x15'))['db'];function respondWithStatusCode(_0x5b9714,_0x15ca1e){_0x15ca1e=_0x15ca1e||0xcc;return function(_0x367b59){if(_0x367b59){return _0x5b9714['sendStatus'](_0x15ca1e);}return _0x5b9714['status'](_0x15ca1e)[_0xfc33('0x16')]();};}function respondWithResult(_0x454bff,_0x14a6d0){_0x14a6d0=_0x14a6d0||0xc8;return function(_0x17d7dd){if(_0x17d7dd){return _0x454bff['status'](_0x14a6d0)[_0xfc33('0x17')](_0x17d7dd);}};}function respondWithFilteredResult(_0x3239cb,_0x6e2aed){return function(_0x535819){if(_0x535819){var _0x4420ff=_0x535819[_0xfc33('0x18')],_0x2f7142=_0x6e2aed[_0xfc33('0x19')],_0x221c28=_0x6e2aed['offset']+_0x6e2aed[_0xfc33('0x1a')],_0x5b4b44;if(_0x221c28>=_0x4420ff){_0x221c28=_0x4420ff;_0x5b4b44=0xc8;}else{_0x5b4b44=0xce;}_0x3239cb['status'](_0x5b4b44);return _0x3239cb['set'](_0xfc33('0x1b'),_0x2f7142+'-'+_0x221c28+'/'+_0x4420ff)['json'](_0x535819);}return null;};}function patchUpdates(_0x36abe8){return function(_0x41b9a1){try{jsonpatch[_0xfc33('0x1c')](_0x41b9a1,_0x36abe8,!![]);}catch(_0x5a3fa0){return BPromise[_0xfc33('0x1d')](_0x5a3fa0);}return _0x41b9a1[_0xfc33('0x1e')]();};}function saveUpdates(_0x25fece,_0x16a803){return function(_0x592f4f){if(_0x592f4f){return _0x592f4f[_0xfc33('0x1f')](_0x25fece)[_0xfc33('0x20')](function(_0x5e3ddb){return _0x5e3ddb;});}return null;};}function removeEntity(_0x5cd779,_0x2f1ab9){return function(_0x1d3255){if(_0x1d3255){return _0x1d3255['destroy']()[_0xfc33('0x20')](function(){_0x5cd779[_0xfc33('0x21')](0xcc)[_0xfc33('0x16')]();});}};}function handleEntityNotFound(_0x248621,_0x20b600){return function(_0x261d97){if(!_0x261d97){_0x248621[_0xfc33('0x22')](0x194);}return _0x261d97;};}function handleError(_0x9d01b8,_0x4d520b){_0x4d520b=_0x4d520b||0x1f4;return function(_0x3dd2ee){logger[_0xfc33('0x23')](_0x3dd2ee[_0xfc33('0x24')]);if(_0x3dd2ee[_0xfc33('0x25')]){delete _0x3dd2ee[_0xfc33('0x25')];}_0x9d01b8[_0xfc33('0x21')](_0x4d520b)[_0xfc33('0x26')](_0x3dd2ee);};}exports[_0xfc33('0x27')]=function(_0x56f764,_0x566fb7){var _0x5e7af6={},_0x274f85={},_0x39e0c5={'count':0x0,'rows':[]};var _0x5f5698=_[_0xfc33('0x28')](db[_0xfc33('0x29')]['rawAttributes'],function(_0x43f08e){return{'name':_0x43f08e[_0xfc33('0x2a')],'type':_0x43f08e[_0xfc33('0x2b')][_0xfc33('0x2c')]};});_0x274f85[_0xfc33('0x2d')]=_[_0xfc33('0x28')](_0x5f5698,_0xfc33('0x25'));_0x274f85[_0xfc33('0x2e')]=_[_0xfc33('0x2f')](_0x56f764[_0xfc33('0x2e')]);_0x274f85['filters']=_[_0xfc33('0x30')](_0x274f85[_0xfc33('0x2d')],_0x274f85['query']);_0x5e7af6['attributes']=_[_0xfc33('0x30')](_0x274f85[_0xfc33('0x2d')],qs[_0xfc33('0x31')](_0x56f764[_0xfc33('0x2e')][_0xfc33('0x31')]));_0x5e7af6[_0xfc33('0x32')]=_0x5e7af6[_0xfc33('0x32')][_0xfc33('0x33')]?_0x5e7af6[_0xfc33('0x32')]:_0x274f85[_0xfc33('0x2d')];if(!_0x56f764[_0xfc33('0x2e')]['hasOwnProperty'](_0xfc33('0x34'))){_0x5e7af6[_0xfc33('0x1a')]=qs['limit'](_0x56f764[_0xfc33('0x2e')][_0xfc33('0x1a')]);_0x5e7af6[_0xfc33('0x19')]=qs['offset'](_0x56f764[_0xfc33('0x2e')][_0xfc33('0x19')]);}_0x5e7af6[_0xfc33('0x35')]=qs[_0xfc33('0x36')](_0x56f764[_0xfc33('0x2e')][_0xfc33('0x36')]);_0x5e7af6['where']=qs[_0xfc33('0x37')](_[_0xfc33('0x38')](_0x56f764[_0xfc33('0x2e')],_0x274f85[_0xfc33('0x37')]),_0x5f5698);if(_0x56f764[_0xfc33('0x2e')]['filter']){_0x5e7af6['where']=_[_0xfc33('0x39')](_0x5e7af6[_0xfc33('0x3a')],{'$or':_[_0xfc33('0x28')](_0x5f5698,function(_0x3bbea6){if(_0x3bbea6['type']!==_0xfc33('0x3b')){var _0x3745e5={};_0x3745e5[_0x3bbea6['name']]={'$like':'%'+_0x56f764[_0xfc33('0x2e')][_0xfc33('0x3c')]+'%'};return _0x3745e5;}})});}_0x5e7af6=_['merge']({},_0x5e7af6,_0x56f764[_0xfc33('0x3d')]);var _0x5dca95={'where':_0x5e7af6['where']};return db[_0xfc33('0x29')][_0xfc33('0x18')](_0x5dca95)[_0xfc33('0x20')](function(_0x685aae){_0x39e0c5['count']=_0x685aae;if(_0x56f764['query']['includeAll']){_0x5e7af6[_0xfc33('0x3e')]=[{'all':!![]}];}return db[_0xfc33('0x29')][_0xfc33('0x3f')](_0x5e7af6);})[_0xfc33('0x20')](function(_0x2b7fd3){_0x39e0c5[_0xfc33('0x40')]=_0x2b7fd3;return _0x39e0c5;})[_0xfc33('0x20')](respondWithFilteredResult(_0x566fb7,_0x5e7af6))[_0xfc33('0x41')](handleError(_0x566fb7,null));};exports['show']=function(_0x152913,_0x787c75){var _0x3ca026={'raw':!![],'where':{'id':_0x152913[_0xfc33('0x42')]['id']}},_0x4e728d={};_0x4e728d[_0xfc33('0x2d')]=_['keys'](db[_0xfc33('0x29')][_0xfc33('0x43')]);_0x4e728d['query']=_[_0xfc33('0x2f')](_0x152913[_0xfc33('0x2e')]);_0x4e728d['filters']=_['intersection'](_0x4e728d[_0xfc33('0x2d')],_0x4e728d[_0xfc33('0x2e')]);_0x3ca026[_0xfc33('0x32')]=_[_0xfc33('0x30')](_0x4e728d[_0xfc33('0x2d')],qs[_0xfc33('0x31')](_0x152913[_0xfc33('0x2e')]['fields']));_0x3ca026[_0xfc33('0x32')]=_0x3ca026[_0xfc33('0x32')][_0xfc33('0x33')]?_0x3ca026[_0xfc33('0x32')]:_0x4e728d[_0xfc33('0x2d')];if(_0x152913[_0xfc33('0x2e')][_0xfc33('0x44')]){_0x3ca026[_0xfc33('0x3e')]=[{'all':!![]}];}_0x3ca026=_[_0xfc33('0x39')]({},_0x3ca026,_0x152913[_0xfc33('0x3d')]);return db[_0xfc33('0x29')][_0xfc33('0x45')](_0x3ca026)[_0xfc33('0x20')](handleEntityNotFound(_0x787c75,null))[_0xfc33('0x20')](respondWithResult(_0x787c75,null))[_0xfc33('0x41')](handleError(_0x787c75,null));};exports[_0xfc33('0x46')]=function(_0x1c8dbe,_0x1ca908){return db[_0xfc33('0x29')][_0xfc33('0x46')](_0x1c8dbe[_0xfc33('0x47')],{})[_0xfc33('0x20')](respondWithResult(_0x1ca908,0xc9))[_0xfc33('0x41')](handleError(_0x1ca908,null));};exports[_0xfc33('0x1f')]=function(_0x4f507a,_0x1c9d01){if(_0x4f507a[_0xfc33('0x47')]['id']){delete _0x4f507a[_0xfc33('0x47')]['id'];}return db[_0xfc33('0x29')]['find']({'where':{'id':_0x4f507a[_0xfc33('0x42')]['id']}})[_0xfc33('0x20')](handleEntityNotFound(_0x1c9d01,null))[_0xfc33('0x20')](saveUpdates(_0x4f507a[_0xfc33('0x47')],null))[_0xfc33('0x20')](respondWithResult(_0x1c9d01,null))[_0xfc33('0x41')](handleError(_0x1c9d01,null));};exports[_0xfc33('0x48')]=function(_0x119a93,_0x1e95cb){return db['Cdr'][_0xfc33('0x45')]({'where':{'id':_0x119a93['params']['id']}})['then'](handleEntityNotFound(_0x1e95cb,null))[_0xfc33('0x20')](removeEntity(_0x1e95cb,null))['catch'](handleError(_0x1e95cb,null));};exports['describe']=function(_0x3c73a1,_0x291fad){return db[_0xfc33('0x29')][_0xfc33('0x49')]()[_0xfc33('0x20')](respondWithResult(_0x291fad,null))[_0xfc33('0x41')](handleError(_0x291fad,null));};