Built motion from commit (unavailable).|2.4.21
[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 _0xcbf5=['destroy','error','stack','name','send','show','params','keys','rawAttributes','query','filters','intersection','model','attributes','fields','includeAll','include','ChatApplication','find','catch','body','eml-format','rimraf','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','squel','jsforce','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','end','json','count','offset','limit','set','apply','reject','save','update','then'];(function(_0x317fba,_0x5b5b38){var _0x279bc7=function(_0xd4e6d9){while(--_0xd4e6d9){_0x317fba['push'](_0x317fba['shift']());}};_0x279bc7(++_0x5b5b38);}(_0xcbf5,0x1e5));var _0x5cbf=function(_0xf34da4,_0x30c006){_0xf34da4=_0xf34da4-0x0;var _0xc8b3ef=_0xcbf5[_0xf34da4];return _0xc8b3ef;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0x5cbf('0x0'));var rimraf=require(_0x5cbf('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x5cbf('0x2'));var rp=require(_0x5cbf('0x3'));var moment=require(_0x5cbf('0x4'));var BPromise=require(_0x5cbf('0x5'));var Mustache=require(_0x5cbf('0x6'));var util=require(_0x5cbf('0x7'));var path=require(_0x5cbf('0x8'));var sox=require(_0x5cbf('0x9'));var csv=require(_0x5cbf('0xa'));var ejs=require(_0x5cbf('0xb'));var fs=require('fs');var _=require('lodash');var squel=require(_0x5cbf('0xc'));var crypto=require('crypto');var jsforce=require(_0x5cbf('0xd'));var deskjs=require(_0x5cbf('0xe'));var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require(_0x5cbf('0xf'));var Redis=require(_0x5cbf('0x10'));var authService=require(_0x5cbf('0x11'));var qs=require(_0x5cbf('0x12'));var as=require(_0x5cbf('0x13'));var hardwareService=require(_0x5cbf('0x14'));var logger=require('../../config/logger')('api');var utils=require(_0x5cbf('0x15'));var config=require(_0x5cbf('0x16'));var db=require(_0x5cbf('0x17'))['db'];function respondWithStatusCode(_0x16e151,_0x5ad170){_0x5ad170=_0x5ad170||0xcc;return function(_0x5775bf){if(_0x5775bf){return _0x16e151[_0x5cbf('0x18')](_0x5ad170);}return _0x16e151[_0x5cbf('0x19')](_0x5ad170)[_0x5cbf('0x1a')]();};}function respondWithResult(_0x1963b1,_0x11268d){_0x11268d=_0x11268d||0xc8;return function(_0x135169){if(_0x135169){return _0x1963b1['status'](_0x11268d)[_0x5cbf('0x1b')](_0x135169);}};}function respondWithFilteredResult(_0x4e4f55,_0x1141ae){return function(_0x404f19){if(_0x404f19){var _0x10a59f=_0x404f19[_0x5cbf('0x1c')],_0x277802=_0x1141ae[_0x5cbf('0x1d')],_0x275508=_0x1141ae[_0x5cbf('0x1d')]+_0x1141ae[_0x5cbf('0x1e')],_0x524093;if(_0x275508>=_0x10a59f){_0x275508=_0x10a59f;_0x524093=0xc8;}else{_0x524093=0xce;}_0x4e4f55['status'](_0x524093);return _0x4e4f55[_0x5cbf('0x1f')]('Content-Range',_0x277802+'-'+_0x275508+'/'+_0x10a59f)[_0x5cbf('0x1b')](_0x404f19);}return null;};}function patchUpdates(_0x1a5ea2){return function(_0xab5cf6){try{jsonpatch[_0x5cbf('0x20')](_0xab5cf6,_0x1a5ea2,!![]);}catch(_0x285ad0){return BPromise[_0x5cbf('0x21')](_0x285ad0);}return _0xab5cf6[_0x5cbf('0x22')]();};}function saveUpdates(_0x47616c,_0x4a7c34){return function(_0x5ea5b7){if(_0x5ea5b7){return _0x5ea5b7[_0x5cbf('0x23')](_0x47616c)[_0x5cbf('0x24')](function(_0x31be2c){return _0x31be2c;});}return null;};}function removeEntity(_0x355d26,_0x3a978c){return function(_0x565d00){if(_0x565d00){return _0x565d00[_0x5cbf('0x25')]()['then'](function(){_0x355d26['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x1f604c,_0x474aa6){return function(_0x31358f){if(!_0x31358f){_0x1f604c[_0x5cbf('0x18')](0x194);}return _0x31358f;};}function handleError(_0x5bf1e9,_0x5dcde5){_0x5dcde5=_0x5dcde5||0x1f4;return function(_0x2741ae){logger[_0x5cbf('0x26')](_0x2741ae[_0x5cbf('0x27')]);if(_0x2741ae['name']){delete _0x2741ae[_0x5cbf('0x28')];}_0x5bf1e9[_0x5cbf('0x19')](_0x5dcde5)[_0x5cbf('0x29')](_0x2741ae);};}exports[_0x5cbf('0x2a')]=function(_0x528fea,_0x5d9b4e){var _0x33cb9c={'raw':!![],'where':{'id':_0x528fea[_0x5cbf('0x2b')]['id']}},_0xe84a17={};_0xe84a17['model']=_[_0x5cbf('0x2c')](db['ChatApplication'][_0x5cbf('0x2d')]);_0xe84a17['query']=_[_0x5cbf('0x2c')](_0x528fea[_0x5cbf('0x2e')]);_0xe84a17[_0x5cbf('0x2f')]=_[_0x5cbf('0x30')](_0xe84a17[_0x5cbf('0x31')],_0xe84a17[_0x5cbf('0x2e')]);_0x33cb9c[_0x5cbf('0x32')]=_[_0x5cbf('0x30')](_0xe84a17[_0x5cbf('0x31')],qs[_0x5cbf('0x33')](_0x528fea[_0x5cbf('0x2e')][_0x5cbf('0x33')]));_0x33cb9c[_0x5cbf('0x32')]=_0x33cb9c[_0x5cbf('0x32')]['length']?_0x33cb9c['attributes']:_0xe84a17[_0x5cbf('0x31')];if(_0x528fea[_0x5cbf('0x2e')][_0x5cbf('0x34')]){_0x33cb9c[_0x5cbf('0x35')]=[{'all':!![]}];}_0x33cb9c=_['merge']({},_0x33cb9c,_0x528fea['options']);return db[_0x5cbf('0x36')][_0x5cbf('0x37')](_0x33cb9c)[_0x5cbf('0x24')](handleEntityNotFound(_0x5d9b4e,null))['then'](respondWithResult(_0x5d9b4e,null))[_0x5cbf('0x38')](handleError(_0x5d9b4e,null));};exports[_0x5cbf('0x23')]=function(_0x44376c,_0x4dbd6b){if(_0x44376c[_0x5cbf('0x39')]['id']){delete _0x44376c[_0x5cbf('0x39')]['id'];}return db[_0x5cbf('0x36')][_0x5cbf('0x37')]({'where':{'id':_0x44376c[_0x5cbf('0x2b')]['id']}})['then'](handleEntityNotFound(_0x4dbd6b,null))[_0x5cbf('0x24')](saveUpdates(_0x44376c[_0x5cbf('0x39')],null))['then'](respondWithResult(_0x4dbd6b,null))[_0x5cbf('0x38')](handleError(_0x4dbd6b,null));};exports[_0x5cbf('0x25')]=function(_0x1c1148,_0x57aa34){return db[_0x5cbf('0x36')][_0x5cbf('0x37')]({'where':{'id':_0x1c1148[_0x5cbf('0x2b')]['id']}})['then'](handleEntityNotFound(_0x57aa34,null))[_0x5cbf('0x24')](removeEntity(_0x57aa34,null))[_0x5cbf('0x38')](handleError(_0x57aa34,null));};