Built motion from commit 85328c08.|2.5.50
[motion2.git] / server / api / cmHopperBlack / cmHopperBlack.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 _0x689f=['squel','crypto','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','undefined','offset','count','set','Content-Range','json','apply','reject','save','then','destroy','end','error','stack','name','send','map','rawAttributes','key','query','keys','filters','intersection','model','attributes','length','hasOwnProperty','nolimit','limit','sort','where','filter','merge','options','CmHopperBlack','include','findAll','catch','show','fields','find','update','body','params','describe','fast-json-patch','request-promise','mustache','path','to-csv','ejs','fs-extra'];(function(_0x32edf6,_0x699bf0){var _0x3d6297=function(_0x4ea160){while(--_0x4ea160){_0x32edf6['push'](_0x32edf6['shift']());}};_0x3d6297(++_0x699bf0);}(_0x689f,0x81));var _0xf689=function(_0x56dbe5,_0x57fa97){_0x56dbe5=_0x56dbe5-0x0;var _0x47009d=_0x689f[_0x56dbe5];return _0x47009d;};'use strict';var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require(_0xf689('0x0'));var rp=require(_0xf689('0x1'));var moment=require('moment');var BPromise=require('bluebird');var Mustache=require(_0xf689('0x2'));var util=require('util');var path=require(_0xf689('0x3'));var sox=require('sox');var csv=require(_0xf689('0x4'));var ejs=require(_0xf689('0x5'));var fs=require('fs');var fs_extra=require(_0xf689('0x6'));var _=require('lodash');var squel=require(_0xf689('0x7'));var crypto=require(_0xf689('0x8'));var jsforce=require('jsforce');var deskjs=require(_0xf689('0x9'));var toCsv=require(_0xf689('0x4'));var querystring=require('querystring');var Papa=require(_0xf689('0xa'));var Redis=require(_0xf689('0xb'));var authService=require(_0xf689('0xc'));var qs=require(_0xf689('0xd'));var as=require(_0xf689('0xe'));var hardwareService=require(_0xf689('0xf'));var logger=require(_0xf689('0x10'))('api');var utils=require(_0xf689('0x11'));var config=require(_0xf689('0x12'));var licenseUtil=require(_0xf689('0x13'));var db=require(_0xf689('0x14'))['db'];function respondWithStatusCode(_0x2c7e72,_0x462bf7){_0x462bf7=_0x462bf7||0xcc;return function(_0x1f1a54){if(_0x1f1a54){return _0x2c7e72[_0xf689('0x15')](_0x462bf7);}return _0x2c7e72[_0xf689('0x16')](_0x462bf7)['end']();};}function respondWithResult(_0x1ea3f2,_0x25f0aa){_0x25f0aa=_0x25f0aa||0xc8;return function(_0x3cd379){if(_0x3cd379){return _0x1ea3f2[_0xf689('0x16')](_0x25f0aa)['json'](_0x3cd379);}};}function respondWithFilteredResult(_0x27e485,_0x125b5e){return function(_0xd01a52){if(_0xd01a52){var _0x2f0c9f=typeof _0x125b5e['offset']===_0xf689('0x17')&&typeof _0x125b5e['limit']===_0xf689('0x17');var _0x2960c7=_0xd01a52['count'];var _0x4f730d=_0x2f0c9f?0x0:_0x125b5e[_0xf689('0x18')];var _0x195d50=_0x2f0c9f?_0xd01a52[_0xf689('0x19')]:_0x125b5e[_0xf689('0x18')]+_0x125b5e['limit'];var _0x678a5a;if(_0x195d50>=_0x2960c7){_0x195d50=_0x2960c7;_0x678a5a=0xc8;}else{_0x678a5a=0xce;}_0x27e485[_0xf689('0x16')](_0x678a5a);return _0x27e485[_0xf689('0x1a')](_0xf689('0x1b'),_0x4f730d+'-'+_0x195d50+'/'+_0x2960c7)[_0xf689('0x1c')](_0xd01a52);}return null;};}function patchUpdates(_0x33464a){return function(_0x5503ed){try{jsonpatch[_0xf689('0x1d')](_0x5503ed,_0x33464a,!![]);}catch(_0x1fbdbf){return BPromise[_0xf689('0x1e')](_0x1fbdbf);}return _0x5503ed[_0xf689('0x1f')]();};}function saveUpdates(_0x3f2f1f,_0xec4872){return function(_0x208914){if(_0x208914){return _0x208914['update'](_0x3f2f1f)[_0xf689('0x20')](function(_0x5a3058){return _0x5a3058;});}return null;};}function removeEntity(_0x4a1758,_0x578c4c){return function(_0x59b436){if(_0x59b436){return _0x59b436[_0xf689('0x21')]()[_0xf689('0x20')](function(){_0x4a1758['status'](0xcc)[_0xf689('0x22')]();});}};}function handleEntityNotFound(_0xdf14ca,_0x266960){return function(_0x59d563){if(!_0x59d563){_0xdf14ca[_0xf689('0x15')](0x194);}return _0x59d563;};}function handleError(_0x399fd6,_0x604c8e){_0x604c8e=_0x604c8e||0x1f4;return function(_0x413ea8){logger[_0xf689('0x23')](_0x413ea8[_0xf689('0x24')]);if(_0x413ea8[_0xf689('0x25')]){delete _0x413ea8[_0xf689('0x25')];}_0x399fd6[_0xf689('0x16')](_0x604c8e)[_0xf689('0x26')](_0x413ea8);};}exports['index']=function(_0x43a1f4,_0x4d68d8){var _0x4e60ed={},_0x5a3e8f={},_0xebc372={'count':0x0,'rows':[]};var _0x75f007=_[_0xf689('0x27')](db['CmHopperBlack'][_0xf689('0x28')],function(_0x539a86){return{'name':_0x539a86['fieldName'],'type':_0x539a86['type'][_0xf689('0x29')]};});_0x5a3e8f['model']=_[_0xf689('0x27')](_0x75f007,_0xf689('0x25'));_0x5a3e8f[_0xf689('0x2a')]=_[_0xf689('0x2b')](_0x43a1f4[_0xf689('0x2a')]);_0x5a3e8f[_0xf689('0x2c')]=_[_0xf689('0x2d')](_0x5a3e8f[_0xf689('0x2e')],_0x5a3e8f['query']);_0x4e60ed['attributes']=_[_0xf689('0x2d')](_0x5a3e8f['model'],qs['fields'](_0x43a1f4[_0xf689('0x2a')]['fields']));_0x4e60ed[_0xf689('0x2f')]=_0x4e60ed['attributes'][_0xf689('0x30')]?_0x4e60ed['attributes']:_0x5a3e8f['model'];if(!_0x43a1f4[_0xf689('0x2a')][_0xf689('0x31')](_0xf689('0x32'))){_0x4e60ed[_0xf689('0x33')]=qs['limit'](_0x43a1f4[_0xf689('0x2a')][_0xf689('0x33')]);_0x4e60ed['offset']=qs[_0xf689('0x18')](_0x43a1f4[_0xf689('0x2a')][_0xf689('0x18')]);}_0x4e60ed['order']=qs[_0xf689('0x34')](_0x43a1f4[_0xf689('0x2a')][_0xf689('0x34')]);_0x4e60ed[_0xf689('0x35')]=qs['filters'](_['pick'](_0x43a1f4[_0xf689('0x2a')],_0x5a3e8f['filters']),_0x75f007);if(_0x43a1f4[_0xf689('0x2a')][_0xf689('0x36')]){_0x4e60ed[_0xf689('0x35')]=_[_0xf689('0x37')](_0x4e60ed[_0xf689('0x35')],{'$or':_[_0xf689('0x27')](_0x75f007,function(_0x49575a){if(_0x49575a['type']!=='VIRTUAL'){var _0x50014f={};_0x50014f[_0x49575a['name']]={'$like':'%'+_0x43a1f4[_0xf689('0x2a')][_0xf689('0x36')]+'%'};return _0x50014f;}})});}_0x4e60ed=_['merge']({},_0x4e60ed,_0x43a1f4[_0xf689('0x38')]);var _0x2b8eb4={'where':_0x4e60ed[_0xf689('0x35')]};return db[_0xf689('0x39')][_0xf689('0x19')](_0x2b8eb4)[_0xf689('0x20')](function(_0x160a5c){_0xebc372[_0xf689('0x19')]=_0x160a5c;if(_0x43a1f4[_0xf689('0x2a')]['includeAll']){_0x4e60ed[_0xf689('0x3a')]=[{'all':!![]}];}return db[_0xf689('0x39')][_0xf689('0x3b')](_0x4e60ed);})['then'](function(_0x179849){_0xebc372['rows']=_0x179849;return _0xebc372;})['then'](respondWithFilteredResult(_0x4d68d8,_0x4e60ed))[_0xf689('0x3c')](handleError(_0x4d68d8,null));};exports[_0xf689('0x3d')]=function(_0x54bfa6,_0xfe048c){var _0x1d76c0={'raw':!![],'where':{'id':_0x54bfa6['params']['id']}},_0x448155={};_0x448155['model']=_['keys'](db[_0xf689('0x39')][_0xf689('0x28')]);_0x448155[_0xf689('0x2a')]=_[_0xf689('0x2b')](_0x54bfa6['query']);_0x448155['filters']=_['intersection'](_0x448155['model'],_0x448155['query']);_0x1d76c0[_0xf689('0x2f')]=_[_0xf689('0x2d')](_0x448155[_0xf689('0x2e')],qs[_0xf689('0x3e')](_0x54bfa6['query'][_0xf689('0x3e')]));_0x1d76c0[_0xf689('0x2f')]=_0x1d76c0[_0xf689('0x2f')][_0xf689('0x30')]?_0x1d76c0[_0xf689('0x2f')]:_0x448155['model'];if(_0x54bfa6[_0xf689('0x2a')]['includeAll']){_0x1d76c0['include']=[{'all':!![]}];}_0x1d76c0=_[_0xf689('0x37')]({},_0x1d76c0,_0x54bfa6[_0xf689('0x38')]);return db[_0xf689('0x39')][_0xf689('0x3f')](_0x1d76c0)['then'](handleEntityNotFound(_0xfe048c,null))[_0xf689('0x20')](respondWithResult(_0xfe048c,null))[_0xf689('0x3c')](handleError(_0xfe048c,null));};exports[_0xf689('0x40')]=function(_0x39f512,_0x49a0ac){if(_0x39f512[_0xf689('0x41')]['id']){delete _0x39f512[_0xf689('0x41')]['id'];}return db['CmHopperBlack']['find']({'where':{'id':_0x39f512['params']['id']}})[_0xf689('0x20')](handleEntityNotFound(_0x49a0ac,null))['then'](saveUpdates(_0x39f512[_0xf689('0x41')],null))['then'](respondWithResult(_0x49a0ac,null))[_0xf689('0x3c')](handleError(_0x49a0ac,null));};exports[_0xf689('0x21')]=function(_0x4ba793,_0x3d3240){return db[_0xf689('0x39')][_0xf689('0x3f')]({'where':{'id':_0x4ba793[_0xf689('0x42')]['id']}})[_0xf689('0x20')](handleEntityNotFound(_0x3d3240,null))[_0xf689('0x20')](removeEntity(_0x3d3240,null))[_0xf689('0x3c')](handleError(_0x3d3240,null));};exports[_0xf689('0x43')]=function(_0x24dc9f,_0x4f4719){return db[_0xf689('0x39')][_0xf689('0x43')]()[_0xf689('0x20')](respondWithResult(_0x4f4719,null))['catch'](handleError(_0x4f4719,null));};