001b904bce23f6100cbb116465fa91c1b2a78b76
[motion2.git] / server / api / chatApplication / chatApplication.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 _0x3039=['offset','set','Content-Range','reject','update','then','destroy','error','stack','name','send','show','model','keys','ChatApplication','rawAttributes','query','filters','attributes','intersection','fields','length','includeAll','include','merge','catch','body','params','find','rimraf','zip-dir','request-promise','mustache','util','path','sox','to-csv','ejs','lodash','crypto','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','sendStatus','status','end','json','count'];(function(_0x284807,_0x4be925){var _0x50c774=function(_0xf56cf7){while(--_0xf56cf7){_0x284807['push'](_0x284807['shift']());}};_0x50c774(++_0x4be925);}(_0x3039,0x167));var _0x9303=function(_0x321bb2,_0x202794){_0x321bb2=_0x321bb2-0x0;var _0x9c12ed=_0x3039[_0x321bb2];return _0x9c12ed;};'use strict';var pdf=require('html-pdf');var emlformat=require('eml-format');var rimraf=require(_0x9303('0x0'));var zipdir=require(_0x9303('0x1'));var jsonpatch=require('fast-json-patch');var rp=require(_0x9303('0x2'));var moment=require('moment');var BPromise=require('bluebird');var Mustache=require(_0x9303('0x3'));var util=require(_0x9303('0x4'));var path=require(_0x9303('0x5'));var sox=require(_0x9303('0x6'));var csv=require(_0x9303('0x7'));var ejs=require(_0x9303('0x8'));var fs=require('fs');var _=require(_0x9303('0x9'));var squel=require('squel');var crypto=require(_0x9303('0xa'));var jsforce=require(_0x9303('0xb'));var deskjs=require(_0x9303('0xc'));var toCsv=require(_0x9303('0x7'));var querystring=require(_0x9303('0xd'));var Papa=require(_0x9303('0xe'));var Redis=require('ioredis');var authService=require(_0x9303('0xf'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x9303('0x10'));var logger=require(_0x9303('0x11'))(_0x9303('0x12'));var utils=require(_0x9303('0x13'));var config=require(_0x9303('0x14'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x5d89b5,_0x2c2a3a){_0x2c2a3a=_0x2c2a3a||0xcc;return function(_0x522b0d){if(_0x522b0d){return _0x5d89b5[_0x9303('0x15')](_0x2c2a3a);}return _0x5d89b5[_0x9303('0x16')](_0x2c2a3a)[_0x9303('0x17')]();};}function respondWithResult(_0x1cebe9,_0x4ae70c){_0x4ae70c=_0x4ae70c||0xc8;return function(_0x1e336a){if(_0x1e336a){return _0x1cebe9[_0x9303('0x16')](_0x4ae70c)[_0x9303('0x18')](_0x1e336a);}};}function respondWithFilteredResult(_0x4ac4e6,_0xec9453){return function(_0x168aea){if(_0x168aea){var _0x37023c=_0x168aea[_0x9303('0x19')],_0x2946e5=_0xec9453[_0x9303('0x1a')],_0xe36c15=_0xec9453[_0x9303('0x1a')]+_0xec9453['limit'],_0x1eadf0;if(_0xe36c15>=_0x37023c){_0xe36c15=_0x37023c;_0x1eadf0=0xc8;}else{_0x1eadf0=0xce;}_0x4ac4e6[_0x9303('0x16')](_0x1eadf0);return _0x4ac4e6[_0x9303('0x1b')](_0x9303('0x1c'),_0x2946e5+'-'+_0xe36c15+'/'+_0x37023c)[_0x9303('0x18')](_0x168aea);}return null;};}function patchUpdates(_0x4ac898){return function(_0x352497){try{jsonpatch['apply'](_0x352497,_0x4ac898,!![]);}catch(_0x196bda){return BPromise[_0x9303('0x1d')](_0x196bda);}return _0x352497['save']();};}function saveUpdates(_0x134791,_0x55735e){return function(_0x11f72b){if(_0x11f72b){return _0x11f72b[_0x9303('0x1e')](_0x134791)[_0x9303('0x1f')](function(_0x3db47e){return _0x3db47e;});}return null;};}function removeEntity(_0x394ed1,_0x3765ed){return function(_0x3dd2ce){if(_0x3dd2ce){return _0x3dd2ce[_0x9303('0x20')]()['then'](function(){_0x394ed1[_0x9303('0x16')](0xcc)[_0x9303('0x17')]();});}};}function handleEntityNotFound(_0x467892,_0x2b5e9a){return function(_0x4bdc15){if(!_0x4bdc15){_0x467892[_0x9303('0x15')](0x194);}return _0x4bdc15;};}function handleError(_0x2775c9,_0x3bd33c){_0x3bd33c=_0x3bd33c||0x1f4;return function(_0x28aae3){logger[_0x9303('0x21')](_0x28aae3[_0x9303('0x22')]);if(_0x28aae3[_0x9303('0x23')]){delete _0x28aae3['name'];}_0x2775c9['status'](_0x3bd33c)[_0x9303('0x24')](_0x28aae3);};}exports[_0x9303('0x25')]=function(_0x20d52b,_0x460f75){var _0x3597ef={'raw':!![],'where':{'id':_0x20d52b['params']['id']}},_0x447240={};_0x447240[_0x9303('0x26')]=_[_0x9303('0x27')](db[_0x9303('0x28')][_0x9303('0x29')]);_0x447240[_0x9303('0x2a')]=_[_0x9303('0x27')](_0x20d52b[_0x9303('0x2a')]);_0x447240[_0x9303('0x2b')]=_['intersection'](_0x447240[_0x9303('0x26')],_0x447240[_0x9303('0x2a')]);_0x3597ef[_0x9303('0x2c')]=_[_0x9303('0x2d')](_0x447240[_0x9303('0x26')],qs['fields'](_0x20d52b['query'][_0x9303('0x2e')]));_0x3597ef[_0x9303('0x2c')]=_0x3597ef[_0x9303('0x2c')][_0x9303('0x2f')]?_0x3597ef[_0x9303('0x2c')]:_0x447240[_0x9303('0x26')];if(_0x20d52b[_0x9303('0x2a')][_0x9303('0x30')]){_0x3597ef[_0x9303('0x31')]=[{'all':!![]}];}_0x3597ef=_[_0x9303('0x32')]({},_0x3597ef,_0x20d52b['options']);return db[_0x9303('0x28')]['find'](_0x3597ef)['then'](handleEntityNotFound(_0x460f75,null))[_0x9303('0x1f')](respondWithResult(_0x460f75,null))[_0x9303('0x33')](handleError(_0x460f75,null));};exports[_0x9303('0x1e')]=function(_0x307f84,_0x3bf4b9){if(_0x307f84[_0x9303('0x34')]['id']){delete _0x307f84[_0x9303('0x34')]['id'];}return db[_0x9303('0x28')]['find']({'where':{'id':_0x307f84[_0x9303('0x35')]['id']}})[_0x9303('0x1f')](handleEntityNotFound(_0x3bf4b9,null))[_0x9303('0x1f')](saveUpdates(_0x307f84[_0x9303('0x34')],null))[_0x9303('0x1f')](respondWithResult(_0x3bf4b9,null))['catch'](handleError(_0x3bf4b9,null));};exports['destroy']=function(_0x1c2664,_0x2b16cf){return db[_0x9303('0x28')][_0x9303('0x36')]({'where':{'id':_0x1c2664[_0x9303('0x35')]['id']}})['then'](handleEntityNotFound(_0x2b16cf,null))['then'](removeEntity(_0x2b16cf,null))[_0x9303('0x33')](handleError(_0x2b16cf,null));};