Built motion from commit (unavailable).|2.2.0
[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 _0x4e4d=['status','count','offset','Content-Range','json','reject','save','then','error','stack','name','send','model','keys','ChatApplication','rawAttributes','query','filters','intersection','attributes','fields','includeAll','include','find','catch','body','params','destroy','html-pdf','eml-format','zip-dir','fast-json-patch','request-promise','moment','mustache','util','path','sox','to-csv','ejs','lodash','squel','jsforce','desk.js','querystring','papaparse','ioredis','../../components/parsers/qs','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus'];(function(_0x4401b7,_0x98b2f1){var _0x458b00=function(_0x5d441e){while(--_0x5d441e){_0x4401b7['push'](_0x4401b7['shift']());}};_0x458b00(++_0x98b2f1);}(_0x4e4d,0xbe));var _0xd4e4=function(_0xc0a3d3,_0x2c8d00){_0xc0a3d3=_0xc0a3d3-0x0;var _0x3386e8=_0x4e4d[_0xc0a3d3];return _0x3386e8;};'use strict';var pdf=require(_0xd4e4('0x0'));var emlformat=require(_0xd4e4('0x1'));var rimraf=require('rimraf');var zipdir=require(_0xd4e4('0x2'));var jsonpatch=require(_0xd4e4('0x3'));var rp=require(_0xd4e4('0x4'));var moment=require(_0xd4e4('0x5'));var BPromise=require('bluebird');var Mustache=require(_0xd4e4('0x6'));var util=require(_0xd4e4('0x7'));var path=require(_0xd4e4('0x8'));var sox=require(_0xd4e4('0x9'));var csv=require(_0xd4e4('0xa'));var ejs=require(_0xd4e4('0xb'));var fs=require('fs');var _=require(_0xd4e4('0xc'));var squel=require(_0xd4e4('0xd'));var crypto=require('crypto');var jsforce=require(_0xd4e4('0xe'));var deskjs=require(_0xd4e4('0xf'));var toCsv=require(_0xd4e4('0xa'));var querystring=require(_0xd4e4('0x10'));var Papa=require(_0xd4e4('0x11'));var Redis=require(_0xd4e4('0x12'));var qs=require(_0xd4e4('0x13'));var logger=require(_0xd4e4('0x14'))(_0xd4e4('0x15'));var utils=require(_0xd4e4('0x16'));var config=require(_0xd4e4('0x17'));var db=require(_0xd4e4('0x18'))['db'];function respondWithStatusCode(_0x334b6e,_0x5cc25a){_0x5cc25a=_0x5cc25a||0xcc;return function(_0x2da78f){if(_0x2da78f){return _0x334b6e[_0xd4e4('0x19')](_0x5cc25a);}return _0x334b6e[_0xd4e4('0x1a')](_0x5cc25a)['end']();};}function respondWithResult(_0x897c3e,_0x2ab369){_0x2ab369=_0x2ab369||0xc8;return function(_0xf19081){if(_0xf19081){return _0x897c3e[_0xd4e4('0x1a')](_0x2ab369)['json'](_0xf19081);}};}function respondWithFilteredResult(_0x53660e,_0x26cfa2){return function(_0x574d60){if(_0x574d60){var _0x17c1d2=_0x574d60[_0xd4e4('0x1b')],_0x3c2967=_0x26cfa2[_0xd4e4('0x1c')],_0x269d26=_0x26cfa2[_0xd4e4('0x1c')]+_0x26cfa2['limit'],_0x2c2ff2;if(_0x269d26>=_0x17c1d2){_0x269d26=_0x17c1d2;_0x2c2ff2=0xc8;}else{_0x2c2ff2=0xce;}_0x53660e[_0xd4e4('0x1a')](_0x2c2ff2);return _0x53660e['set'](_0xd4e4('0x1d'),_0x3c2967+'-'+_0x269d26+'/'+_0x17c1d2)[_0xd4e4('0x1e')](_0x574d60);}return null;};}function patchUpdates(_0x3f66b6){return function(_0x40549b){try{jsonpatch['apply'](_0x40549b,_0x3f66b6,!![]);}catch(_0x19f57b){return BPromise[_0xd4e4('0x1f')](_0x19f57b);}return _0x40549b[_0xd4e4('0x20')]();};}function saveUpdates(_0x304fd2,_0x42b521){return function(_0xf75a71){if(_0xf75a71){return _0xf75a71['update'](_0x304fd2)[_0xd4e4('0x21')](function(_0x4011df){return _0x4011df;});}return null;};}function removeEntity(_0x57e7d2,_0x4900cc){return function(_0x4f0404){if(_0x4f0404){return _0x4f0404['destroy']()[_0xd4e4('0x21')](function(){_0x57e7d2['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x12c383,_0x32a667){return function(_0x5547ab){if(!_0x5547ab){_0x12c383[_0xd4e4('0x19')](0x194);}return _0x5547ab;};}function handleError(_0x572e1c,_0xe82c42){_0xe82c42=_0xe82c42||0x1f4;return function(_0xde79f8){logger[_0xd4e4('0x22')](_0xde79f8[_0xd4e4('0x23')]);if(_0xde79f8[_0xd4e4('0x24')]){delete _0xde79f8[_0xd4e4('0x24')];}_0x572e1c['status'](_0xe82c42)[_0xd4e4('0x25')](_0xde79f8);};}exports['show']=function(_0x334ebd,_0x4b3515){var _0x2bea7e={'raw':!![],'where':{'id':_0x334ebd['params']['id']}},_0x21d43a={};_0x21d43a[_0xd4e4('0x26')]=_[_0xd4e4('0x27')](db[_0xd4e4('0x28')][_0xd4e4('0x29')]);_0x21d43a[_0xd4e4('0x2a')]=_[_0xd4e4('0x27')](_0x334ebd[_0xd4e4('0x2a')]);_0x21d43a[_0xd4e4('0x2b')]=_[_0xd4e4('0x2c')](_0x21d43a['model'],_0x21d43a[_0xd4e4('0x2a')]);_0x2bea7e[_0xd4e4('0x2d')]=_[_0xd4e4('0x2c')](_0x21d43a[_0xd4e4('0x26')],qs[_0xd4e4('0x2e')](_0x334ebd[_0xd4e4('0x2a')][_0xd4e4('0x2e')]));_0x2bea7e[_0xd4e4('0x2d')]=_0x2bea7e[_0xd4e4('0x2d')]['length']?_0x2bea7e[_0xd4e4('0x2d')]:_0x21d43a['model'];if(_0x334ebd['query'][_0xd4e4('0x2f')]){_0x2bea7e[_0xd4e4('0x30')]=[{'all':!![]}];}_0x2bea7e=_['merge']({},_0x2bea7e,_0x334ebd['options']);return db[_0xd4e4('0x28')][_0xd4e4('0x31')](_0x2bea7e)[_0xd4e4('0x21')](handleEntityNotFound(_0x4b3515,null))[_0xd4e4('0x21')](respondWithResult(_0x4b3515,null))[_0xd4e4('0x32')](handleError(_0x4b3515,null));};exports['update']=function(_0x2fd39c,_0x1d4bd3){if(_0x2fd39c[_0xd4e4('0x33')]['id']){delete _0x2fd39c[_0xd4e4('0x33')]['id'];}return db['ChatApplication']['find']({'where':{'id':_0x2fd39c[_0xd4e4('0x34')]['id']}})['then'](handleEntityNotFound(_0x1d4bd3,null))['then'](saveUpdates(_0x2fd39c['body'],null))[_0xd4e4('0x21')](respondWithResult(_0x1d4bd3,null))[_0xd4e4('0x32')](handleError(_0x1d4bd3,null));};exports[_0xd4e4('0x35')]=function(_0x2681f5,_0x1d36ba){return db[_0xd4e4('0x28')][_0xd4e4('0x31')]({'where':{'id':_0x2681f5[_0xd4e4('0x34')]['id']}})[_0xd4e4('0x21')](handleEntityNotFound(_0x1d36ba,null))['then'](removeEntity(_0x1d36ba,null))['catch'](handleError(_0x1d36ba,null));};