3d7ebc3a594132a24ad7dc5d5193b1a52e6c9a86
[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 _0x364f=['Content-Range','save','update','then','end','error','name','send','Cdr','rawAttributes','model','keys','query','intersection','attributes','fields','hasOwnProperty','nolimit','limit','order','sort','where','pick','filter','merge','type','key','VIRTUAL','field','options','includeAll','include','findAll','rows','catch','show','params','filters','length','create','body','describe','html-pdf','rimraf','zip-dir','request-promise','moment','util','path','sox','to-csv','crypto','desk.js','querystring','ioredis','../../config/logger','api','../../config/environment','sendStatus','status','json','count','offset','set'];(function(_0xfbafd6,_0x378be9){var _0x474343=function(_0x1d43ea){while(--_0x1d43ea){_0xfbafd6['push'](_0xfbafd6['shift']());}};_0x474343(++_0x378be9);}(_0x364f,0x16a));var _0xf364=function(_0x4216ba,_0x5739c5){_0x4216ba=_0x4216ba-0x0;var _0x2592ca=_0x364f[_0x4216ba];return _0x2592ca;};'use strict';var pdf=require(_0xf364('0x0'));var emlformat=require('eml-format');var rimraf=require(_0xf364('0x1'));var zipdir=require(_0xf364('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0xf364('0x3'));var moment=require(_0xf364('0x4'));var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0xf364('0x5'));var path=require(_0xf364('0x6'));var sox=require(_0xf364('0x7'));var csv=require(_0xf364('0x8'));var ejs=require('ejs');var fs=require('fs');var _=require('lodash');var squel=require('squel');var crypto=require(_0xf364('0x9'));var jsforce=require('jsforce');var deskjs=require(_0xf364('0xa'));var toCsv=require(_0xf364('0x8'));var querystring=require(_0xf364('0xb'));var Papa=require('papaparse');var Redis=require(_0xf364('0xc'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var hardwareService=require('../../config/license/hardware');var logger=require(_0xf364('0xd'))(_0xf364('0xe'));var utils=require('../../config/utils');var config=require(_0xf364('0xf'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x2b1afd,_0x41a37d){_0x41a37d=_0x41a37d||0xcc;return function(_0xb1c071){if(_0xb1c071){return _0x2b1afd[_0xf364('0x10')](_0x41a37d);}return _0x2b1afd['status'](_0x41a37d)['end']();};}function respondWithResult(_0x4eb33a,_0x5ec28f){_0x5ec28f=_0x5ec28f||0xc8;return function(_0x569b49){if(_0x569b49){return _0x4eb33a[_0xf364('0x11')](_0x5ec28f)[_0xf364('0x12')](_0x569b49);}};}function respondWithFilteredResult(_0x275fd5,_0xff6c19){return function(_0x49634d){if(_0x49634d){var _0x3f35c9=_0x49634d[_0xf364('0x13')],_0x31c81c=_0xff6c19[_0xf364('0x14')],_0x32c3b6=_0xff6c19[_0xf364('0x14')]+_0xff6c19['limit'],_0x32eb99;if(_0x32c3b6>=_0x3f35c9){_0x32c3b6=_0x3f35c9;_0x32eb99=0xc8;}else{_0x32eb99=0xce;}_0x275fd5['status'](_0x32eb99);return _0x275fd5[_0xf364('0x15')](_0xf364('0x16'),_0x31c81c+'-'+_0x32c3b6+'/'+_0x3f35c9)['json'](_0x49634d);}return null;};}function patchUpdates(_0x5f480a){return function(_0x231561){try{jsonpatch['apply'](_0x231561,_0x5f480a,!![]);}catch(_0x25dcce){return BPromise['reject'](_0x25dcce);}return _0x231561[_0xf364('0x17')]();};}function saveUpdates(_0x1c0041,_0x317dcf){return function(_0x407a28){if(_0x407a28){return _0x407a28[_0xf364('0x18')](_0x1c0041)[_0xf364('0x19')](function(_0x180184){return _0x180184;});}return null;};}function removeEntity(_0x3b59ec,_0x5f1a0e){return function(_0x47c9a3){if(_0x47c9a3){return _0x47c9a3['destroy']()['then'](function(){_0x3b59ec[_0xf364('0x11')](0xcc)[_0xf364('0x1a')]();});}};}function handleEntityNotFound(_0x3716d1,_0x44c5e9){return function(_0x205bfd){if(!_0x205bfd){_0x3716d1['sendStatus'](0x194);}return _0x205bfd;};}function handleError(_0xe30e2f,_0x1b9cde){_0x1b9cde=_0x1b9cde||0x1f4;return function(_0x19d6e7){logger[_0xf364('0x1b')](_0x19d6e7['stack']);if(_0x19d6e7[_0xf364('0x1c')]){delete _0x19d6e7['name'];}_0xe30e2f[_0xf364('0x11')](_0x1b9cde)[_0xf364('0x1d')](_0x19d6e7);};}exports['index']=function(_0x56504b,_0x1d49fb){var _0x581f87={},_0x20f3a5={},_0x578ef0={'count':0x0,'rows':[]};var _0x11632f=db[_0xf364('0x1e')][_0xf364('0x1f')];_0x20f3a5[_0xf364('0x20')]=_[_0xf364('0x21')](_0x11632f);_0x20f3a5['query']=_['keys'](_0x56504b[_0xf364('0x22')]);_0x20f3a5['filters']=_[_0xf364('0x23')](_0x20f3a5[_0xf364('0x20')],_0x20f3a5[_0xf364('0x22')]);_0x581f87[_0xf364('0x24')]=_[_0xf364('0x23')](_0x20f3a5['model'],qs[_0xf364('0x25')](_0x56504b[_0xf364('0x22')][_0xf364('0x25')]));_0x581f87['attributes']=_0x581f87[_0xf364('0x24')]['length']?_0x581f87[_0xf364('0x24')]:_0x20f3a5[_0xf364('0x20')];if(!_0x56504b[_0xf364('0x22')][_0xf364('0x26')](_0xf364('0x27'))){_0x581f87[_0xf364('0x28')]=qs[_0xf364('0x28')](_0x56504b[_0xf364('0x22')]['limit']);_0x581f87[_0xf364('0x14')]=qs[_0xf364('0x14')](_0x56504b[_0xf364('0x22')][_0xf364('0x14')]);}_0x581f87[_0xf364('0x29')]=qs[_0xf364('0x2a')](_0x56504b[_0xf364('0x22')][_0xf364('0x2a')]);_0x581f87[_0xf364('0x2b')]=qs['filters'](_[_0xf364('0x2c')](_0x56504b[_0xf364('0x22')],_0x20f3a5['filters']));if(_0x56504b[_0xf364('0x22')][_0xf364('0x2d')]){_0x581f87[_0xf364('0x2b')]=_[_0xf364('0x2e')](_0x581f87[_0xf364('0x2b')],{'$or':_['map'](_0x11632f,function(_0x30b84b){if(_0x30b84b[_0xf364('0x2f')][_0xf364('0x30')]!==_0xf364('0x31')){var _0x2712b8={};_0x2712b8[_0x30b84b[_0xf364('0x32')]]={'$like':'%'+_0x56504b[_0xf364('0x22')][_0xf364('0x2d')]+'%'};return _0x2712b8;}})});}_0x581f87=_[_0xf364('0x2e')]({},_0x581f87,_0x56504b[_0xf364('0x33')]);var _0x507832={'where':_0x581f87['where']};return db['Cdr'][_0xf364('0x13')](_0x507832)['then'](function(_0x11b275){_0x578ef0[_0xf364('0x13')]=_0x11b275;if(_0x56504b[_0xf364('0x22')][_0xf364('0x34')]){_0x581f87[_0xf364('0x35')]=[{'all':!![]}];}return db[_0xf364('0x1e')][_0xf364('0x36')](_0x581f87);})['then'](function(_0x384438){_0x578ef0[_0xf364('0x37')]=_0x384438;return _0x578ef0;})[_0xf364('0x19')](respondWithFilteredResult(_0x1d49fb,_0x581f87))[_0xf364('0x38')](handleError(_0x1d49fb,null));};exports[_0xf364('0x39')]=function(_0x1a1176,_0x43ad90){var _0x44884d={'raw':!![],'where':{'id':_0x1a1176[_0xf364('0x3a')]['id']}},_0x30cbe4={};_0x30cbe4[_0xf364('0x20')]=_[_0xf364('0x21')](db[_0xf364('0x1e')][_0xf364('0x1f')]);_0x30cbe4['query']=_[_0xf364('0x21')](_0x1a1176['query']);_0x30cbe4[_0xf364('0x3b')]=_[_0xf364('0x23')](_0x30cbe4[_0xf364('0x20')],_0x30cbe4[_0xf364('0x22')]);_0x44884d[_0xf364('0x24')]=_['intersection'](_0x30cbe4[_0xf364('0x20')],qs[_0xf364('0x25')](_0x1a1176['query']['fields']));_0x44884d[_0xf364('0x24')]=_0x44884d[_0xf364('0x24')][_0xf364('0x3c')]?_0x44884d[_0xf364('0x24')]:_0x30cbe4[_0xf364('0x20')];if(_0x1a1176[_0xf364('0x22')][_0xf364('0x34')]){_0x44884d[_0xf364('0x35')]=[{'all':!![]}];}_0x44884d=_[_0xf364('0x2e')]({},_0x44884d,_0x1a1176[_0xf364('0x33')]);return db[_0xf364('0x1e')]['find'](_0x44884d)['then'](handleEntityNotFound(_0x43ad90,null))[_0xf364('0x19')](respondWithResult(_0x43ad90,null))[_0xf364('0x38')](handleError(_0x43ad90,null));};exports[_0xf364('0x3d')]=function(_0x12d7d3,_0x5c2122){return db[_0xf364('0x1e')]['create'](_0x12d7d3[_0xf364('0x3e')],{})[_0xf364('0x19')](respondWithResult(_0x5c2122,0xc9))['catch'](handleError(_0x5c2122,null));};exports[_0xf364('0x18')]=function(_0x4160e0,_0x39ac7d){if(_0x4160e0['body']['id']){delete _0x4160e0['body']['id'];}return db[_0xf364('0x1e')]['find']({'where':{'id':_0x4160e0[_0xf364('0x3a')]['id']}})['then'](handleEntityNotFound(_0x39ac7d,null))[_0xf364('0x19')](saveUpdates(_0x4160e0[_0xf364('0x3e')],null))['then'](respondWithResult(_0x39ac7d,null))[_0xf364('0x38')](handleError(_0x39ac7d,null));};exports['destroy']=function(_0x413ccb,_0x3f1f60){return db['Cdr']['find']({'where':{'id':_0x413ccb['params']['id']}})['then'](handleEntityNotFound(_0x3f1f60,null))['then'](removeEntity(_0x3f1f60,null))[_0xf364('0x38')](handleError(_0x3f1f60,null));};exports['describe']=function(_0x14cecc,_0xb07bd3){return db[_0xf364('0x1e')][_0xf364('0x3f')]()[_0xf364('0x19')](respondWithResult(_0xb07bd3,null))[_0xf364('0x38')](handleError(_0xb07bd3,null));};