78dc038af57c0db20d1deaecdffa7a31b5a3b2d0
[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 _0xf6fb=['jsforce','querystring','papaparse','ioredis','../../components/auth/service','../../config/license/hardware','../../config/logger','api','../../config/environment','../../mysqldb','sendStatus','status','end','json','offset','undefined','count','limit','apply','save','update','destroy','then','stack','name','send','show','model','keys','rawAttributes','query','filters','intersection','attributes','fields','length','includeAll','include','merge','options','find','body','ChatApplication','params','catch','zip-dir','fast-json-patch','moment','bluebird','util','sox','to-csv','ejs','fs-extra','lodash','squel','crypto'];(function(_0x118749,_0x30d2dd){var _0x5af77b=function(_0x2ba6b3){while(--_0x2ba6b3){_0x118749['push'](_0x118749['shift']());}};_0x5af77b(++_0x30d2dd);}(_0xf6fb,0x111));var _0xbf6f=function(_0x1af11c,_0x3123eb){_0x1af11c=_0x1af11c-0x0;var _0xa3fb6e=_0xf6fb[_0x1af11c];return _0xa3fb6e;};'use strict';var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require(_0xbf6f('0x0'));var jsonpatch=require(_0xbf6f('0x1'));var rp=require('request-promise');var moment=require(_0xbf6f('0x2'));var BPromise=require(_0xbf6f('0x3'));var Mustache=require('mustache');var util=require(_0xbf6f('0x4'));var path=require('path');var sox=require(_0xbf6f('0x5'));var csv=require(_0xbf6f('0x6'));var ejs=require(_0xbf6f('0x7'));var fs=require('fs');var fs_extra=require(_0xbf6f('0x8'));var _=require(_0xbf6f('0x9'));var squel=require(_0xbf6f('0xa'));var crypto=require(_0xbf6f('0xb'));var jsforce=require(_0xbf6f('0xc'));var deskjs=require('desk.js');var toCsv=require(_0xbf6f('0x6'));var querystring=require(_0xbf6f('0xd'));var Papa=require(_0xbf6f('0xe'));var Redis=require(_0xbf6f('0xf'));var authService=require(_0xbf6f('0x10'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xbf6f('0x11'));var logger=require(_0xbf6f('0x12'))(_0xbf6f('0x13'));var utils=require('../../config/utils');var config=require(_0xbf6f('0x14'));var licenseUtil=require('../../config/license/util');var db=require(_0xbf6f('0x15'))['db'];function respondWithStatusCode(_0x7b939f,_0x3a5c09){_0x3a5c09=_0x3a5c09||0xcc;return function(_0x50c054){if(_0x50c054){return _0x7b939f[_0xbf6f('0x16')](_0x3a5c09);}return _0x7b939f[_0xbf6f('0x17')](_0x3a5c09)[_0xbf6f('0x18')]();};}function respondWithResult(_0x6f8fee,_0xce557a){_0xce557a=_0xce557a||0xc8;return function(_0x1dd2f1){if(_0x1dd2f1){return _0x6f8fee['status'](_0xce557a)[_0xbf6f('0x19')](_0x1dd2f1);}};}function respondWithFilteredResult(_0x3f1c33,_0x473d32){return function(_0x40ad56){if(_0x40ad56){var _0x270ec6=typeof _0x473d32[_0xbf6f('0x1a')]===_0xbf6f('0x1b')&&typeof _0x473d32['limit']==='undefined';var _0x734fe8=_0x40ad56[_0xbf6f('0x1c')];var _0x21b485=_0x270ec6?0x0:_0x473d32['offset'];var _0x56b4da=_0x270ec6?_0x40ad56[_0xbf6f('0x1c')]:_0x473d32[_0xbf6f('0x1a')]+_0x473d32[_0xbf6f('0x1d')];var _0x22e1e9;if(_0x56b4da>=_0x734fe8){_0x56b4da=_0x734fe8;_0x22e1e9=0xc8;}else{_0x22e1e9=0xce;}_0x3f1c33[_0xbf6f('0x17')](_0x22e1e9);return _0x3f1c33['set']('Content-Range',_0x21b485+'-'+_0x56b4da+'/'+_0x734fe8)[_0xbf6f('0x19')](_0x40ad56);}return null;};}function patchUpdates(_0x5985ac){return function(_0x3bd472){try{jsonpatch[_0xbf6f('0x1e')](_0x3bd472,_0x5985ac,!![]);}catch(_0x3cc13c){return BPromise['reject'](_0x3cc13c);}return _0x3bd472[_0xbf6f('0x1f')]();};}function saveUpdates(_0x21b547,_0x3a0087){return function(_0x528bf0){if(_0x528bf0){return _0x528bf0[_0xbf6f('0x20')](_0x21b547)['then'](function(_0x2af16f){return _0x2af16f;});}return null;};}function removeEntity(_0xb9e8bc,_0xba4b6a){return function(_0x49979a){if(_0x49979a){return _0x49979a[_0xbf6f('0x21')]()[_0xbf6f('0x22')](function(){_0xb9e8bc[_0xbf6f('0x17')](0xcc)[_0xbf6f('0x18')]();});}};}function handleEntityNotFound(_0x44d47f,_0x442f60){return function(_0x59c3d6){if(!_0x59c3d6){_0x44d47f[_0xbf6f('0x16')](0x194);}return _0x59c3d6;};}function handleError(_0xf6108a,_0x4c7e8d){_0x4c7e8d=_0x4c7e8d||0x1f4;return function(_0x506302){logger['error'](_0x506302[_0xbf6f('0x23')]);if(_0x506302['name']){delete _0x506302[_0xbf6f('0x24')];}_0xf6108a[_0xbf6f('0x17')](_0x4c7e8d)[_0xbf6f('0x25')](_0x506302);};}exports[_0xbf6f('0x26')]=function(_0xb440e8,_0x237b67){var _0x1aefcc={'raw':!![],'where':{'id':_0xb440e8['params']['id']}},_0x58c120={};_0x58c120[_0xbf6f('0x27')]=_[_0xbf6f('0x28')](db['ChatApplication'][_0xbf6f('0x29')]);_0x58c120['query']=_[_0xbf6f('0x28')](_0xb440e8[_0xbf6f('0x2a')]);_0x58c120[_0xbf6f('0x2b')]=_[_0xbf6f('0x2c')](_0x58c120[_0xbf6f('0x27')],_0x58c120[_0xbf6f('0x2a')]);_0x1aefcc[_0xbf6f('0x2d')]=_[_0xbf6f('0x2c')](_0x58c120[_0xbf6f('0x27')],qs[_0xbf6f('0x2e')](_0xb440e8['query']['fields']));_0x1aefcc[_0xbf6f('0x2d')]=_0x1aefcc[_0xbf6f('0x2d')][_0xbf6f('0x2f')]?_0x1aefcc[_0xbf6f('0x2d')]:_0x58c120['model'];if(_0xb440e8[_0xbf6f('0x2a')][_0xbf6f('0x30')]){_0x1aefcc[_0xbf6f('0x31')]=[{'all':!![]}];}_0x1aefcc=_[_0xbf6f('0x32')]({},_0x1aefcc,_0xb440e8[_0xbf6f('0x33')]);return db['ChatApplication'][_0xbf6f('0x34')](_0x1aefcc)[_0xbf6f('0x22')](handleEntityNotFound(_0x237b67,null))[_0xbf6f('0x22')](respondWithResult(_0x237b67,null))['catch'](handleError(_0x237b67,null));};exports[_0xbf6f('0x20')]=function(_0x516a5b,_0x39ac85){if(_0x516a5b[_0xbf6f('0x35')]['id']){delete _0x516a5b[_0xbf6f('0x35')]['id'];}return db[_0xbf6f('0x36')][_0xbf6f('0x34')]({'where':{'id':_0x516a5b[_0xbf6f('0x37')]['id']}})[_0xbf6f('0x22')](handleEntityNotFound(_0x39ac85,null))[_0xbf6f('0x22')](saveUpdates(_0x516a5b[_0xbf6f('0x35')],null))[_0xbf6f('0x22')](respondWithResult(_0x39ac85,null))[_0xbf6f('0x38')](handleError(_0x39ac85,null));};exports[_0xbf6f('0x21')]=function(_0x5f0fab,_0x1afe12){return db[_0xbf6f('0x36')][_0xbf6f('0x34')]({'where':{'id':_0x5f0fab[_0xbf6f('0x37')]['id']}})[_0xbf6f('0x22')](handleEntityNotFound(_0x1afe12,null))[_0xbf6f('0x22')](removeEntity(_0x1afe12,null))[_0xbf6f('0x38')](handleError(_0x1afe12,null));};