Built motion from commit (unavailable).|2.5.31
[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 _0xf0cc=['merge','VIRTUAL','options','includeAll','rows','catch','show','params','include','find','body','describe','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird','mustache','path','sox','to-csv','ejs','fs-extra','squel','crypto','jsforce','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/license/util','../../mysqldb','status','end','offset','undefined','count','limit','set','Content-Range','json','reject','save','update','destroy','then','sendStatus','error','stack','name','send','CmHopperBlack','rawAttributes','fieldName','type','key','model','map','keys','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','sort','where','pick','filter'];(function(_0xef4fc0,_0x33cc41){var _0x57dade=function(_0xe75b3e){while(--_0xe75b3e){_0xef4fc0['push'](_0xef4fc0['shift']());}};_0x57dade(++_0x33cc41);}(_0xf0cc,0xf3));var _0xcf0c=function(_0x181d72,_0x259c63){_0x181d72=_0x181d72-0x0;var _0x2d571c=_0xf0cc[_0x181d72];return _0x2d571c;};'use strict';var emlformat=require(_0xcf0c('0x0'));var rimraf=require(_0xcf0c('0x1'));var zipdir=require(_0xcf0c('0x2'));var jsonpatch=require(_0xcf0c('0x3'));var rp=require('request-promise');var moment=require(_0xcf0c('0x4'));var BPromise=require(_0xcf0c('0x5'));var Mustache=require(_0xcf0c('0x6'));var util=require('util');var path=require(_0xcf0c('0x7'));var sox=require(_0xcf0c('0x8'));var csv=require(_0xcf0c('0x9'));var ejs=require(_0xcf0c('0xa'));var fs=require('fs');var fs_extra=require(_0xcf0c('0xb'));var _=require('lodash');var squel=require(_0xcf0c('0xc'));var crypto=require(_0xcf0c('0xd'));var jsforce=require(_0xcf0c('0xe'));var deskjs=require('desk.js');var toCsv=require(_0xcf0c('0x9'));var querystring=require(_0xcf0c('0xf'));var Papa=require(_0xcf0c('0x10'));var Redis=require(_0xcf0c('0x11'));var authService=require(_0xcf0c('0x12'));var qs=require(_0xcf0c('0x13'));var as=require(_0xcf0c('0x14'));var hardwareService=require(_0xcf0c('0x15'));var logger=require('../../config/logger')(_0xcf0c('0x16'));var utils=require(_0xcf0c('0x17'));var config=require('../../config/environment');var licenseUtil=require(_0xcf0c('0x18'));var db=require(_0xcf0c('0x19'))['db'];function respondWithStatusCode(_0x3ba8fc,_0x26fde7){_0x26fde7=_0x26fde7||0xcc;return function(_0x378252){if(_0x378252){return _0x3ba8fc['sendStatus'](_0x26fde7);}return _0x3ba8fc[_0xcf0c('0x1a')](_0x26fde7)[_0xcf0c('0x1b')]();};}function respondWithResult(_0x551478,_0x1e927b){_0x1e927b=_0x1e927b||0xc8;return function(_0x2e6694){if(_0x2e6694){return _0x551478['status'](_0x1e927b)['json'](_0x2e6694);}};}function respondWithFilteredResult(_0x3f78fc,_0x3d9ffb){return function(_0xa095fa){if(_0xa095fa){var _0x2a5099=typeof _0x3d9ffb[_0xcf0c('0x1c')]===_0xcf0c('0x1d')&&typeof _0x3d9ffb['limit']===_0xcf0c('0x1d');var _0x45352a=_0xa095fa[_0xcf0c('0x1e')];var _0x451458=_0x2a5099?0x0:_0x3d9ffb['offset'];var _0x396100=_0x2a5099?_0xa095fa[_0xcf0c('0x1e')]:_0x3d9ffb[_0xcf0c('0x1c')]+_0x3d9ffb[_0xcf0c('0x1f')];var _0x50878b;if(_0x396100>=_0x45352a){_0x396100=_0x45352a;_0x50878b=0xc8;}else{_0x50878b=0xce;}_0x3f78fc[_0xcf0c('0x1a')](_0x50878b);return _0x3f78fc[_0xcf0c('0x20')](_0xcf0c('0x21'),_0x451458+'-'+_0x396100+'/'+_0x45352a)[_0xcf0c('0x22')](_0xa095fa);}return null;};}function patchUpdates(_0x33ebc1){return function(_0x821fa6){try{jsonpatch['apply'](_0x821fa6,_0x33ebc1,!![]);}catch(_0x4ba524){return BPromise[_0xcf0c('0x23')](_0x4ba524);}return _0x821fa6[_0xcf0c('0x24')]();};}function saveUpdates(_0x43ee47,_0x2e3d99){return function(_0x49631a){if(_0x49631a){return _0x49631a[_0xcf0c('0x25')](_0x43ee47)['then'](function(_0xa2de0b){return _0xa2de0b;});}return null;};}function removeEntity(_0x512edc,_0x490b93){return function(_0x360a27){if(_0x360a27){return _0x360a27[_0xcf0c('0x26')]()[_0xcf0c('0x27')](function(){_0x512edc['status'](0xcc)[_0xcf0c('0x1b')]();});}};}function handleEntityNotFound(_0xdac624,_0x314c22){return function(_0x10b156){if(!_0x10b156){_0xdac624[_0xcf0c('0x28')](0x194);}return _0x10b156;};}function handleError(_0x465dfc,_0x557096){_0x557096=_0x557096||0x1f4;return function(_0x480f60){logger[_0xcf0c('0x29')](_0x480f60[_0xcf0c('0x2a')]);if(_0x480f60[_0xcf0c('0x2b')]){delete _0x480f60[_0xcf0c('0x2b')];}_0x465dfc[_0xcf0c('0x1a')](_0x557096)[_0xcf0c('0x2c')](_0x480f60);};}exports['index']=function(_0x419501,_0x4e3551){var _0x2c6f7a={},_0x1d67de={},_0x49b94c={'count':0x0,'rows':[]};var _0x2e3b7d=_['map'](db[_0xcf0c('0x2d')][_0xcf0c('0x2e')],function(_0x543f9b){return{'name':_0x543f9b[_0xcf0c('0x2f')],'type':_0x543f9b[_0xcf0c('0x30')][_0xcf0c('0x31')]};});_0x1d67de[_0xcf0c('0x32')]=_[_0xcf0c('0x33')](_0x2e3b7d,_0xcf0c('0x2b'));_0x1d67de['query']=_[_0xcf0c('0x34')](_0x419501[_0xcf0c('0x35')]);_0x1d67de[_0xcf0c('0x36')]=_[_0xcf0c('0x37')](_0x1d67de['model'],_0x1d67de[_0xcf0c('0x35')]);_0x2c6f7a[_0xcf0c('0x38')]=_[_0xcf0c('0x37')](_0x1d67de[_0xcf0c('0x32')],qs['fields'](_0x419501[_0xcf0c('0x35')][_0xcf0c('0x39')]));_0x2c6f7a[_0xcf0c('0x38')]=_0x2c6f7a[_0xcf0c('0x38')][_0xcf0c('0x3a')]?_0x2c6f7a[_0xcf0c('0x38')]:_0x1d67de[_0xcf0c('0x32')];if(!_0x419501[_0xcf0c('0x35')][_0xcf0c('0x3b')](_0xcf0c('0x3c'))){_0x2c6f7a[_0xcf0c('0x1f')]=qs[_0xcf0c('0x1f')](_0x419501['query'][_0xcf0c('0x1f')]);_0x2c6f7a[_0xcf0c('0x1c')]=qs[_0xcf0c('0x1c')](_0x419501[_0xcf0c('0x35')][_0xcf0c('0x1c')]);}_0x2c6f7a['order']=qs[_0xcf0c('0x3d')](_0x419501[_0xcf0c('0x35')]['sort']);_0x2c6f7a[_0xcf0c('0x3e')]=qs['filters'](_[_0xcf0c('0x3f')](_0x419501[_0xcf0c('0x35')],_0x1d67de['filters']),_0x2e3b7d);if(_0x419501[_0xcf0c('0x35')][_0xcf0c('0x40')]){_0x2c6f7a[_0xcf0c('0x3e')]=_[_0xcf0c('0x41')](_0x2c6f7a[_0xcf0c('0x3e')],{'$or':_['map'](_0x2e3b7d,function(_0x1a32c1){if(_0x1a32c1[_0xcf0c('0x30')]!==_0xcf0c('0x42')){var _0x5cab69={};_0x5cab69[_0x1a32c1[_0xcf0c('0x2b')]]={'$like':'%'+_0x419501[_0xcf0c('0x35')][_0xcf0c('0x40')]+'%'};return _0x5cab69;}})});}_0x2c6f7a=_[_0xcf0c('0x41')]({},_0x2c6f7a,_0x419501[_0xcf0c('0x43')]);var _0x6e125d={'where':_0x2c6f7a[_0xcf0c('0x3e')]};return db[_0xcf0c('0x2d')][_0xcf0c('0x1e')](_0x6e125d)[_0xcf0c('0x27')](function(_0x29df70){_0x49b94c['count']=_0x29df70;if(_0x419501['query'][_0xcf0c('0x44')]){_0x2c6f7a['include']=[{'all':!![]}];}return db['CmHopperBlack']['findAll'](_0x2c6f7a);})[_0xcf0c('0x27')](function(_0x13c554){_0x49b94c[_0xcf0c('0x45')]=_0x13c554;return _0x49b94c;})[_0xcf0c('0x27')](respondWithFilteredResult(_0x4e3551,_0x2c6f7a))[_0xcf0c('0x46')](handleError(_0x4e3551,null));};exports[_0xcf0c('0x47')]=function(_0x333b9b,_0x416281){var _0x8b254a={'raw':!![],'where':{'id':_0x333b9b[_0xcf0c('0x48')]['id']}},_0x146809={};_0x146809[_0xcf0c('0x32')]=_[_0xcf0c('0x34')](db[_0xcf0c('0x2d')][_0xcf0c('0x2e')]);_0x146809[_0xcf0c('0x35')]=_[_0xcf0c('0x34')](_0x333b9b[_0xcf0c('0x35')]);_0x146809[_0xcf0c('0x36')]=_[_0xcf0c('0x37')](_0x146809[_0xcf0c('0x32')],_0x146809[_0xcf0c('0x35')]);_0x8b254a[_0xcf0c('0x38')]=_[_0xcf0c('0x37')](_0x146809[_0xcf0c('0x32')],qs[_0xcf0c('0x39')](_0x333b9b[_0xcf0c('0x35')]['fields']));_0x8b254a[_0xcf0c('0x38')]=_0x8b254a[_0xcf0c('0x38')][_0xcf0c('0x3a')]?_0x8b254a['attributes']:_0x146809[_0xcf0c('0x32')];if(_0x333b9b[_0xcf0c('0x35')][_0xcf0c('0x44')]){_0x8b254a[_0xcf0c('0x49')]=[{'all':!![]}];}_0x8b254a=_[_0xcf0c('0x41')]({},_0x8b254a,_0x333b9b[_0xcf0c('0x43')]);return db[_0xcf0c('0x2d')][_0xcf0c('0x4a')](_0x8b254a)[_0xcf0c('0x27')](handleEntityNotFound(_0x416281,null))[_0xcf0c('0x27')](respondWithResult(_0x416281,null))[_0xcf0c('0x46')](handleError(_0x416281,null));};exports[_0xcf0c('0x25')]=function(_0x5e3f8a,_0x11c2f7){if(_0x5e3f8a[_0xcf0c('0x4b')]['id']){delete _0x5e3f8a[_0xcf0c('0x4b')]['id'];}return db[_0xcf0c('0x2d')]['find']({'where':{'id':_0x5e3f8a[_0xcf0c('0x48')]['id']}})[_0xcf0c('0x27')](handleEntityNotFound(_0x11c2f7,null))[_0xcf0c('0x27')](saveUpdates(_0x5e3f8a[_0xcf0c('0x4b')],null))[_0xcf0c('0x27')](respondWithResult(_0x11c2f7,null))['catch'](handleError(_0x11c2f7,null));};exports[_0xcf0c('0x26')]=function(_0x186ece,_0x38fe03){return db[_0xcf0c('0x2d')][_0xcf0c('0x4a')]({'where':{'id':_0x186ece[_0xcf0c('0x48')]['id']}})[_0xcf0c('0x27')](handleEntityNotFound(_0x38fe03,null))[_0xcf0c('0x27')](removeEntity(_0x38fe03,null))[_0xcf0c('0x46')](handleError(_0x38fe03,null));};exports[_0xcf0c('0x4c')]=function(_0x215b15,_0xe04f38){return db[_0xcf0c('0x2d')][_0xcf0c('0x4c')]()[_0xcf0c('0x27')](respondWithResult(_0xe04f38,null))['catch'](handleError(_0xe04f38,null));};