2799bb610d9223dc24ac30684171e4dd8e2918d6
[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 _0xbce4=['../../config/environment','status','end','json','limit','undefined','count','offset','set','apply','reject','update','then','error','stack','name','send','index','CmHopperBlack','rawAttributes','fieldName','key','model','map','query','filters','intersection','attributes','fields','length','nolimit','sort','where','pick','filter','merge','type','VIRTUAL','options','includeAll','include','findAll','rows','catch','show','params','body','destroy','find','describe','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','mustache','sox','lodash','jsforce','desk.js','to-csv','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/utils'];(function(_0x3cd743,_0x982072){var _0x52fb72=function(_0x21c688){while(--_0x21c688){_0x3cd743['push'](_0x3cd743['shift']());}};_0x52fb72(++_0x982072);}(_0xbce4,0x76));var _0x4bce=function(_0x2976b7,_0x2a337c){_0x2976b7=_0x2976b7-0x0;var _0x501f14=_0xbce4[_0x2976b7];return _0x501f14;};'use strict';var emlformat=require(_0x4bce('0x0'));var rimraf=require(_0x4bce('0x1'));var zipdir=require(_0x4bce('0x2'));var jsonpatch=require(_0x4bce('0x3'));var rp=require(_0x4bce('0x4'));var moment=require('moment');var BPromise=require(_0x4bce('0x5'));var Mustache=require(_0x4bce('0x6'));var util=require('util');var path=require('path');var sox=require(_0x4bce('0x7'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x4bce('0x8'));var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0x4bce('0x9'));var deskjs=require(_0x4bce('0xa'));var toCsv=require(_0x4bce('0xb'));var querystring=require('querystring');var Papa=require(_0x4bce('0xc'));var Redis=require(_0x4bce('0xd'));var authService=require('../../components/auth/service');var qs=require(_0x4bce('0xe'));var as=require(_0x4bce('0xf'));var hardwareService=require(_0x4bce('0x10'));var logger=require('../../config/logger')('api');var utils=require(_0x4bce('0x11'));var config=require(_0x4bce('0x12'));var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x50d7e0,_0xb15ddd){_0xb15ddd=_0xb15ddd||0xcc;return function(_0x910d5c){if(_0x910d5c){return _0x50d7e0['sendStatus'](_0xb15ddd);}return _0x50d7e0[_0x4bce('0x13')](_0xb15ddd)[_0x4bce('0x14')]();};}function respondWithResult(_0x223bd0,_0x2d541d){_0x2d541d=_0x2d541d||0xc8;return function(_0x526614){if(_0x526614){return _0x223bd0[_0x4bce('0x13')](_0x2d541d)[_0x4bce('0x15')](_0x526614);}};}function respondWithFilteredResult(_0x4531e6,_0xc2a040){return function(_0x25d0dd){if(_0x25d0dd){var _0x55efa8=typeof _0xc2a040['offset']==='undefined'&&typeof _0xc2a040[_0x4bce('0x16')]===_0x4bce('0x17');var _0x666827=_0x25d0dd[_0x4bce('0x18')];var _0x7627ef=_0x55efa8?0x0:_0xc2a040[_0x4bce('0x19')];var _0x332cca=_0x55efa8?_0x25d0dd[_0x4bce('0x18')]:_0xc2a040[_0x4bce('0x19')]+_0xc2a040['limit'];var _0x1dee21;if(_0x332cca>=_0x666827){_0x332cca=_0x666827;_0x1dee21=0xc8;}else{_0x1dee21=0xce;}_0x4531e6['status'](_0x1dee21);return _0x4531e6[_0x4bce('0x1a')]('Content-Range',_0x7627ef+'-'+_0x332cca+'/'+_0x666827)[_0x4bce('0x15')](_0x25d0dd);}return null;};}function patchUpdates(_0x47d339){return function(_0x19a689){try{jsonpatch[_0x4bce('0x1b')](_0x19a689,_0x47d339,!![]);}catch(_0x5101d9){return BPromise[_0x4bce('0x1c')](_0x5101d9);}return _0x19a689['save']();};}function saveUpdates(_0x1c8fe5,_0x402751){return function(_0x493386){if(_0x493386){return _0x493386[_0x4bce('0x1d')](_0x1c8fe5)['then'](function(_0xd535d6){return _0xd535d6;});}return null;};}function removeEntity(_0x3056c1,_0x21675a){return function(_0x13aab1){if(_0x13aab1){return _0x13aab1['destroy']()[_0x4bce('0x1e')](function(){_0x3056c1[_0x4bce('0x13')](0xcc)['end']();});}};}function handleEntityNotFound(_0x3dab68,_0x436a1f){return function(_0x14468f){if(!_0x14468f){_0x3dab68['sendStatus'](0x194);}return _0x14468f;};}function handleError(_0x20b415,_0x252277){_0x252277=_0x252277||0x1f4;return function(_0x324c7d){logger[_0x4bce('0x1f')](_0x324c7d[_0x4bce('0x20')]);if(_0x324c7d[_0x4bce('0x21')]){delete _0x324c7d[_0x4bce('0x21')];}_0x20b415[_0x4bce('0x13')](_0x252277)[_0x4bce('0x22')](_0x324c7d);};}exports[_0x4bce('0x23')]=function(_0x1102e0,_0x3a8e18){var _0x193e2d={},_0xea3d51={},_0x393f61={'count':0x0,'rows':[]};var _0x17160c=_['map'](db[_0x4bce('0x24')][_0x4bce('0x25')],function(_0x5557f3){return{'name':_0x5557f3[_0x4bce('0x26')],'type':_0x5557f3['type'][_0x4bce('0x27')]};});_0xea3d51[_0x4bce('0x28')]=_[_0x4bce('0x29')](_0x17160c,_0x4bce('0x21'));_0xea3d51[_0x4bce('0x2a')]=_['keys'](_0x1102e0['query']);_0xea3d51[_0x4bce('0x2b')]=_[_0x4bce('0x2c')](_0xea3d51[_0x4bce('0x28')],_0xea3d51[_0x4bce('0x2a')]);_0x193e2d[_0x4bce('0x2d')]=_[_0x4bce('0x2c')](_0xea3d51[_0x4bce('0x28')],qs[_0x4bce('0x2e')](_0x1102e0[_0x4bce('0x2a')][_0x4bce('0x2e')]));_0x193e2d[_0x4bce('0x2d')]=_0x193e2d[_0x4bce('0x2d')][_0x4bce('0x2f')]?_0x193e2d[_0x4bce('0x2d')]:_0xea3d51[_0x4bce('0x28')];if(!_0x1102e0[_0x4bce('0x2a')]['hasOwnProperty'](_0x4bce('0x30'))){_0x193e2d[_0x4bce('0x16')]=qs[_0x4bce('0x16')](_0x1102e0[_0x4bce('0x2a')][_0x4bce('0x16')]);_0x193e2d[_0x4bce('0x19')]=qs[_0x4bce('0x19')](_0x1102e0['query'][_0x4bce('0x19')]);}_0x193e2d['order']=qs['sort'](_0x1102e0['query'][_0x4bce('0x31')]);_0x193e2d[_0x4bce('0x32')]=qs[_0x4bce('0x2b')](_[_0x4bce('0x33')](_0x1102e0[_0x4bce('0x2a')],_0xea3d51[_0x4bce('0x2b')]),_0x17160c);if(_0x1102e0[_0x4bce('0x2a')][_0x4bce('0x34')]){_0x193e2d[_0x4bce('0x32')]=_[_0x4bce('0x35')](_0x193e2d[_0x4bce('0x32')],{'$or':_[_0x4bce('0x29')](_0x17160c,function(_0xfdd9ef){if(_0xfdd9ef[_0x4bce('0x36')]!==_0x4bce('0x37')){var _0x550a60={};_0x550a60[_0xfdd9ef['name']]={'$like':'%'+_0x1102e0['query']['filter']+'%'};return _0x550a60;}})});}_0x193e2d=_[_0x4bce('0x35')]({},_0x193e2d,_0x1102e0[_0x4bce('0x38')]);var _0xbe2226={'where':_0x193e2d[_0x4bce('0x32')]};return db[_0x4bce('0x24')][_0x4bce('0x18')](_0xbe2226)[_0x4bce('0x1e')](function(_0x3c8594){_0x393f61[_0x4bce('0x18')]=_0x3c8594;if(_0x1102e0[_0x4bce('0x2a')][_0x4bce('0x39')]){_0x193e2d[_0x4bce('0x3a')]=[{'all':!![]}];}return db[_0x4bce('0x24')][_0x4bce('0x3b')](_0x193e2d);})[_0x4bce('0x1e')](function(_0x41041a){_0x393f61[_0x4bce('0x3c')]=_0x41041a;return _0x393f61;})[_0x4bce('0x1e')](respondWithFilteredResult(_0x3a8e18,_0x193e2d))[_0x4bce('0x3d')](handleError(_0x3a8e18,null));};exports[_0x4bce('0x3e')]=function(_0xb2653,_0x28eebf){var _0x204ea3={'raw':!![],'where':{'id':_0xb2653[_0x4bce('0x3f')]['id']}},_0xeb4d30={};_0xeb4d30[_0x4bce('0x28')]=_['keys'](db['CmHopperBlack'][_0x4bce('0x25')]);_0xeb4d30[_0x4bce('0x2a')]=_['keys'](_0xb2653[_0x4bce('0x2a')]);_0xeb4d30['filters']=_[_0x4bce('0x2c')](_0xeb4d30[_0x4bce('0x28')],_0xeb4d30[_0x4bce('0x2a')]);_0x204ea3[_0x4bce('0x2d')]=_[_0x4bce('0x2c')](_0xeb4d30[_0x4bce('0x28')],qs['fields'](_0xb2653[_0x4bce('0x2a')][_0x4bce('0x2e')]));_0x204ea3[_0x4bce('0x2d')]=_0x204ea3[_0x4bce('0x2d')][_0x4bce('0x2f')]?_0x204ea3[_0x4bce('0x2d')]:_0xeb4d30[_0x4bce('0x28')];if(_0xb2653[_0x4bce('0x2a')][_0x4bce('0x39')]){_0x204ea3[_0x4bce('0x3a')]=[{'all':!![]}];}_0x204ea3=_[_0x4bce('0x35')]({},_0x204ea3,_0xb2653[_0x4bce('0x38')]);return db[_0x4bce('0x24')]['find'](_0x204ea3)[_0x4bce('0x1e')](handleEntityNotFound(_0x28eebf,null))[_0x4bce('0x1e')](respondWithResult(_0x28eebf,null))[_0x4bce('0x3d')](handleError(_0x28eebf,null));};exports[_0x4bce('0x1d')]=function(_0xaba007,_0x3bd134){if(_0xaba007['body']['id']){delete _0xaba007[_0x4bce('0x40')]['id'];}return db['CmHopperBlack']['find']({'where':{'id':_0xaba007[_0x4bce('0x3f')]['id']}})[_0x4bce('0x1e')](handleEntityNotFound(_0x3bd134,null))[_0x4bce('0x1e')](saveUpdates(_0xaba007[_0x4bce('0x40')],null))[_0x4bce('0x1e')](respondWithResult(_0x3bd134,null))[_0x4bce('0x3d')](handleError(_0x3bd134,null));};exports[_0x4bce('0x41')]=function(_0x2674b4,_0x10001f){return db[_0x4bce('0x24')][_0x4bce('0x42')]({'where':{'id':_0x2674b4[_0x4bce('0x3f')]['id']}})[_0x4bce('0x1e')](handleEntityNotFound(_0x10001f,null))['then'](removeEntity(_0x10001f,null))[_0x4bce('0x3d')](handleError(_0x10001f,null));};exports[_0x4bce('0x43')]=function(_0x2db0ad,_0x44e206){return db[_0x4bce('0x24')]['describe']()[_0x4bce('0x1e')](respondWithResult(_0x44e206,null))[_0x4bce('0x3d')](handleError(_0x44e206,null));};