Built motion from commit 43538d75.|2.5.35
[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 _0xff36=['map','CmHopperBlack','rawAttributes','fieldName','type','key','model','query','filters','intersection','attributes','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','options','includeAll','include','findAll','catch','show','params','keys','fields','length','body','find','destroy','describe','eml-format','rimraf','zip-dir','bluebird','mustache','util','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','end','json','undefined','limit','count','offset','set','Content-Range','apply','reject','then','name','index'];(function(_0x544edd,_0x3bd9c2){var _0x24b881=function(_0x3b36f1){while(--_0x3b36f1){_0x544edd['push'](_0x544edd['shift']());}};_0x24b881(++_0x3bd9c2);}(_0xff36,0x1de));var _0x6ff3=function(_0x2730a1,_0x36508f){_0x2730a1=_0x2730a1-0x0;var _0x3c149b=_0xff36[_0x2730a1];return _0x3c149b;};'use strict';var emlformat=require(_0x6ff3('0x0'));var rimraf=require(_0x6ff3('0x1'));var zipdir=require(_0x6ff3('0x2'));var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require('moment');var BPromise=require(_0x6ff3('0x3'));var Mustache=require(_0x6ff3('0x4'));var util=require(_0x6ff3('0x5'));var path=require('path');var sox=require(_0x6ff3('0x6'));var csv=require(_0x6ff3('0x7'));var ejs=require(_0x6ff3('0x8'));var fs=require('fs');var fs_extra=require(_0x6ff3('0x9'));var _=require(_0x6ff3('0xa'));var squel=require(_0x6ff3('0xb'));var crypto=require(_0x6ff3('0xc'));var jsforce=require(_0x6ff3('0xd'));var deskjs=require(_0x6ff3('0xe'));var toCsv=require(_0x6ff3('0x7'));var querystring=require(_0x6ff3('0xf'));var Papa=require('papaparse');var Redis=require(_0x6ff3('0x10'));var authService=require(_0x6ff3('0x11'));var qs=require(_0x6ff3('0x12'));var as=require(_0x6ff3('0x13'));var hardwareService=require(_0x6ff3('0x14'));var logger=require('../../config/logger')(_0x6ff3('0x15'));var utils=require(_0x6ff3('0x16'));var config=require(_0x6ff3('0x17'));var licenseUtil=require('../../config/license/util');var db=require(_0x6ff3('0x18'))['db'];function respondWithStatusCode(_0x21d07f,_0x5a0f77){_0x5a0f77=_0x5a0f77||0xcc;return function(_0x382e31){if(_0x382e31){return _0x21d07f[_0x6ff3('0x19')](_0x5a0f77);}return _0x21d07f[_0x6ff3('0x1a')](_0x5a0f77)[_0x6ff3('0x1b')]();};}function respondWithResult(_0x16b8cc,_0x1cec11){_0x1cec11=_0x1cec11||0xc8;return function(_0x57e634){if(_0x57e634){return _0x16b8cc[_0x6ff3('0x1a')](_0x1cec11)[_0x6ff3('0x1c')](_0x57e634);}};}function respondWithFilteredResult(_0x359128,_0x59e3d1){return function(_0x3826a1){if(_0x3826a1){var _0x451cec=typeof _0x59e3d1['offset']===_0x6ff3('0x1d')&&typeof _0x59e3d1[_0x6ff3('0x1e')]===_0x6ff3('0x1d');var _0x4a9d21=_0x3826a1[_0x6ff3('0x1f')];var _0x411e15=_0x451cec?0x0:_0x59e3d1[_0x6ff3('0x20')];var _0x508d25=_0x451cec?_0x3826a1[_0x6ff3('0x1f')]:_0x59e3d1[_0x6ff3('0x20')]+_0x59e3d1['limit'];var _0x445cb2;if(_0x508d25>=_0x4a9d21){_0x508d25=_0x4a9d21;_0x445cb2=0xc8;}else{_0x445cb2=0xce;}_0x359128[_0x6ff3('0x1a')](_0x445cb2);return _0x359128[_0x6ff3('0x21')](_0x6ff3('0x22'),_0x411e15+'-'+_0x508d25+'/'+_0x4a9d21)['json'](_0x3826a1);}return null;};}function patchUpdates(_0x5519ea){return function(_0x5e186b){try{jsonpatch[_0x6ff3('0x23')](_0x5e186b,_0x5519ea,!![]);}catch(_0xb3044b){return BPromise[_0x6ff3('0x24')](_0xb3044b);}return _0x5e186b['save']();};}function saveUpdates(_0x14cd05,_0x58a510){return function(_0x5ecfb8){if(_0x5ecfb8){return _0x5ecfb8['update'](_0x14cd05)[_0x6ff3('0x25')](function(_0x460990){return _0x460990;});}return null;};}function removeEntity(_0x8ba282,_0x3b9369){return function(_0xfc95e3){if(_0xfc95e3){return _0xfc95e3['destroy']()[_0x6ff3('0x25')](function(){_0x8ba282['status'](0xcc)[_0x6ff3('0x1b')]();});}};}function handleEntityNotFound(_0x249e10,_0x54ce06){return function(_0x371445){if(!_0x371445){_0x249e10[_0x6ff3('0x19')](0x194);}return _0x371445;};}function handleError(_0x131c95,_0x6b51c2){_0x6b51c2=_0x6b51c2||0x1f4;return function(_0x502daf){logger['error'](_0x502daf['stack']);if(_0x502daf[_0x6ff3('0x26')]){delete _0x502daf['name'];}_0x131c95[_0x6ff3('0x1a')](_0x6b51c2)['send'](_0x502daf);};}exports[_0x6ff3('0x27')]=function(_0x3a81e3,_0x1d0552){var _0x39a3b1={},_0x49edd0={},_0x2a2f66={'count':0x0,'rows':[]};var _0xd22fb5=_[_0x6ff3('0x28')](db[_0x6ff3('0x29')][_0x6ff3('0x2a')],function(_0x1b684c){return{'name':_0x1b684c[_0x6ff3('0x2b')],'type':_0x1b684c[_0x6ff3('0x2c')][_0x6ff3('0x2d')]};});_0x49edd0[_0x6ff3('0x2e')]=_['map'](_0xd22fb5,_0x6ff3('0x26'));_0x49edd0['query']=_['keys'](_0x3a81e3[_0x6ff3('0x2f')]);_0x49edd0[_0x6ff3('0x30')]=_[_0x6ff3('0x31')](_0x49edd0['model'],_0x49edd0[_0x6ff3('0x2f')]);_0x39a3b1['attributes']=_[_0x6ff3('0x31')](_0x49edd0[_0x6ff3('0x2e')],qs['fields'](_0x3a81e3[_0x6ff3('0x2f')]['fields']));_0x39a3b1[_0x6ff3('0x32')]=_0x39a3b1['attributes']['length']?_0x39a3b1['attributes']:_0x49edd0[_0x6ff3('0x2e')];if(!_0x3a81e3[_0x6ff3('0x2f')][_0x6ff3('0x33')](_0x6ff3('0x34'))){_0x39a3b1['limit']=qs[_0x6ff3('0x1e')](_0x3a81e3['query'][_0x6ff3('0x1e')]);_0x39a3b1['offset']=qs['offset'](_0x3a81e3[_0x6ff3('0x2f')][_0x6ff3('0x20')]);}_0x39a3b1[_0x6ff3('0x35')]=qs[_0x6ff3('0x36')](_0x3a81e3['query'][_0x6ff3('0x36')]);_0x39a3b1[_0x6ff3('0x37')]=qs['filters'](_[_0x6ff3('0x38')](_0x3a81e3[_0x6ff3('0x2f')],_0x49edd0['filters']),_0xd22fb5);if(_0x3a81e3[_0x6ff3('0x2f')][_0x6ff3('0x39')]){_0x39a3b1[_0x6ff3('0x37')]=_[_0x6ff3('0x3a')](_0x39a3b1[_0x6ff3('0x37')],{'$or':_[_0x6ff3('0x28')](_0xd22fb5,function(_0x50425e){if(_0x50425e[_0x6ff3('0x2c')]!==_0x6ff3('0x3b')){var _0x492dba={};_0x492dba[_0x50425e[_0x6ff3('0x26')]]={'$like':'%'+_0x3a81e3[_0x6ff3('0x2f')][_0x6ff3('0x39')]+'%'};return _0x492dba;}})});}_0x39a3b1=_[_0x6ff3('0x3a')]({},_0x39a3b1,_0x3a81e3[_0x6ff3('0x3c')]);var _0x59e4c7={'where':_0x39a3b1[_0x6ff3('0x37')]};return db[_0x6ff3('0x29')][_0x6ff3('0x1f')](_0x59e4c7)[_0x6ff3('0x25')](function(_0xfeb39f){_0x2a2f66[_0x6ff3('0x1f')]=_0xfeb39f;if(_0x3a81e3['query'][_0x6ff3('0x3d')]){_0x39a3b1[_0x6ff3('0x3e')]=[{'all':!![]}];}return db[_0x6ff3('0x29')][_0x6ff3('0x3f')](_0x39a3b1);})[_0x6ff3('0x25')](function(_0xc6cf27){_0x2a2f66['rows']=_0xc6cf27;return _0x2a2f66;})[_0x6ff3('0x25')](respondWithFilteredResult(_0x1d0552,_0x39a3b1))[_0x6ff3('0x40')](handleError(_0x1d0552,null));};exports[_0x6ff3('0x41')]=function(_0x532095,_0x30ed9f){var _0x52ac50={'raw':!![],'where':{'id':_0x532095[_0x6ff3('0x42')]['id']}},_0x123c8b={};_0x123c8b[_0x6ff3('0x2e')]=_[_0x6ff3('0x43')](db['CmHopperBlack'][_0x6ff3('0x2a')]);_0x123c8b[_0x6ff3('0x2f')]=_[_0x6ff3('0x43')](_0x532095[_0x6ff3('0x2f')]);_0x123c8b[_0x6ff3('0x30')]=_[_0x6ff3('0x31')](_0x123c8b[_0x6ff3('0x2e')],_0x123c8b[_0x6ff3('0x2f')]);_0x52ac50['attributes']=_[_0x6ff3('0x31')](_0x123c8b[_0x6ff3('0x2e')],qs[_0x6ff3('0x44')](_0x532095[_0x6ff3('0x2f')]['fields']));_0x52ac50[_0x6ff3('0x32')]=_0x52ac50[_0x6ff3('0x32')][_0x6ff3('0x45')]?_0x52ac50[_0x6ff3('0x32')]:_0x123c8b[_0x6ff3('0x2e')];if(_0x532095[_0x6ff3('0x2f')][_0x6ff3('0x3d')]){_0x52ac50[_0x6ff3('0x3e')]=[{'all':!![]}];}_0x52ac50=_[_0x6ff3('0x3a')]({},_0x52ac50,_0x532095[_0x6ff3('0x3c')]);return db[_0x6ff3('0x29')]['find'](_0x52ac50)['then'](handleEntityNotFound(_0x30ed9f,null))[_0x6ff3('0x25')](respondWithResult(_0x30ed9f,null))[_0x6ff3('0x40')](handleError(_0x30ed9f,null));};exports['update']=function(_0x2f0906,_0x28c4ea){if(_0x2f0906[_0x6ff3('0x46')]['id']){delete _0x2f0906[_0x6ff3('0x46')]['id'];}return db[_0x6ff3('0x29')][_0x6ff3('0x47')]({'where':{'id':_0x2f0906[_0x6ff3('0x42')]['id']}})[_0x6ff3('0x25')](handleEntityNotFound(_0x28c4ea,null))[_0x6ff3('0x25')](saveUpdates(_0x2f0906[_0x6ff3('0x46')],null))[_0x6ff3('0x25')](respondWithResult(_0x28c4ea,null))['catch'](handleError(_0x28c4ea,null));};exports[_0x6ff3('0x48')]=function(_0x117373,_0x55b9d6){return db['CmHopperBlack'][_0x6ff3('0x47')]({'where':{'id':_0x117373[_0x6ff3('0x42')]['id']}})[_0x6ff3('0x25')](handleEntityNotFound(_0x55b9d6,null))[_0x6ff3('0x25')](removeEntity(_0x55b9d6,null))[_0x6ff3('0x40')](handleError(_0x55b9d6,null));};exports[_0x6ff3('0x49')]=function(_0x249170,_0x5ca316){return db[_0x6ff3('0x29')][_0x6ff3('0x49')]()['then'](respondWithResult(_0x5ca316,null))[_0x6ff3('0x40')](handleError(_0x5ca316,null));};