4f1559942aa858d44e136bbc3698235b02859c13
[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 _0xbf1a=['fields','merge','options','ChatApplication','find','then','catch','body','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','util','path','sox','fs-extra','squel','crypto','jsforce','desk.js','to-csv','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','undefined','count','offset','limit','set','Content-Range','json','reject','save','update','error','stack','name','show','params','model','keys','rawAttributes','query','attributes','intersection'];(function(_0x2fec51,_0x480819){var _0x4d2f6f=function(_0xd3f55f){while(--_0xd3f55f){_0x2fec51['push'](_0x2fec51['shift']());}};_0x4d2f6f(++_0x480819);}(_0xbf1a,0x7c));var _0xabf1=function(_0x47b415,_0x34caa4){_0x47b415=_0x47b415-0x0;var _0x59ee6c=_0xbf1a[_0x47b415];return _0x59ee6c;};'use strict';var emlformat=require(_0xabf1('0x0'));var rimraf=require(_0xabf1('0x1'));var zipdir=require(_0xabf1('0x2'));var jsonpatch=require(_0xabf1('0x3'));var rp=require(_0xabf1('0x4'));var moment=require('moment');var BPromise=require(_0xabf1('0x5'));var Mustache=require('mustache');var util=require(_0xabf1('0x6'));var path=require(_0xabf1('0x7'));var sox=require(_0xabf1('0x8'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xabf1('0x9'));var _=require('lodash');var squel=require(_0xabf1('0xa'));var crypto=require(_0xabf1('0xb'));var jsforce=require(_0xabf1('0xc'));var deskjs=require(_0xabf1('0xd'));var toCsv=require(_0xabf1('0xe'));var querystring=require(_0xabf1('0xf'));var Papa=require('papaparse');var Redis=require(_0xabf1('0x10'));var authService=require(_0xabf1('0x11'));var qs=require(_0xabf1('0x12'));var as=require(_0xabf1('0x13'));var hardwareService=require(_0xabf1('0x14'));var logger=require(_0xabf1('0x15'))('api');var utils=require(_0xabf1('0x16'));var config=require(_0xabf1('0x17'));var licenseUtil=require(_0xabf1('0x18'));var db=require(_0xabf1('0x19'))['db'];function respondWithStatusCode(_0x3e1738,_0x1186b7){_0x1186b7=_0x1186b7||0xcc;return function(_0x27ade4){if(_0x27ade4){return _0x3e1738[_0xabf1('0x1a')](_0x1186b7);}return _0x3e1738[_0xabf1('0x1b')](_0x1186b7)[_0xabf1('0x1c')]();};}function respondWithResult(_0x4cb7f7,_0x783976){_0x783976=_0x783976||0xc8;return function(_0xcbe7da){if(_0xcbe7da){return _0x4cb7f7[_0xabf1('0x1b')](_0x783976)['json'](_0xcbe7da);}};}function respondWithFilteredResult(_0x293110,_0x3dd81a){return function(_0x719d3e){if(_0x719d3e){var _0x3537e4=typeof _0x3dd81a['offset']===_0xabf1('0x1d')&&typeof _0x3dd81a['limit']===_0xabf1('0x1d');var _0x23093b=_0x719d3e[_0xabf1('0x1e')];var _0x363c21=_0x3537e4?0x0:_0x3dd81a[_0xabf1('0x1f')];var _0xd5dc16=_0x3537e4?_0x719d3e[_0xabf1('0x1e')]:_0x3dd81a[_0xabf1('0x1f')]+_0x3dd81a[_0xabf1('0x20')];var _0x18f315;if(_0xd5dc16>=_0x23093b){_0xd5dc16=_0x23093b;_0x18f315=0xc8;}else{_0x18f315=0xce;}_0x293110[_0xabf1('0x1b')](_0x18f315);return _0x293110[_0xabf1('0x21')](_0xabf1('0x22'),_0x363c21+'-'+_0xd5dc16+'/'+_0x23093b)[_0xabf1('0x23')](_0x719d3e);}return null;};}function patchUpdates(_0x367d7e){return function(_0x5a0413){try{jsonpatch['apply'](_0x5a0413,_0x367d7e,!![]);}catch(_0xa715e7){return BPromise[_0xabf1('0x24')](_0xa715e7);}return _0x5a0413[_0xabf1('0x25')]();};}function saveUpdates(_0x53e531,_0x216862){return function(_0x3fbce0){if(_0x3fbce0){return _0x3fbce0[_0xabf1('0x26')](_0x53e531)['then'](function(_0xb16c27){return _0xb16c27;});}return null;};}function removeEntity(_0x57fea6,_0x30fac8){return function(_0x551401){if(_0x551401){return _0x551401['destroy']()['then'](function(){_0x57fea6[_0xabf1('0x1b')](0xcc)[_0xabf1('0x1c')]();});}};}function handleEntityNotFound(_0x4939cd,_0x14c6f0){return function(_0x69ddb8){if(!_0x69ddb8){_0x4939cd['sendStatus'](0x194);}return _0x69ddb8;};}function handleError(_0x507a76,_0x25d432){_0x25d432=_0x25d432||0x1f4;return function(_0x175678){logger[_0xabf1('0x27')](_0x175678[_0xabf1('0x28')]);if(_0x175678[_0xabf1('0x29')]){delete _0x175678['name'];}_0x507a76[_0xabf1('0x1b')](_0x25d432)['send'](_0x175678);};}exports[_0xabf1('0x2a')]=function(_0x5ddf0d,_0xb54b63){var _0x582fbf={'raw':!![],'where':{'id':_0x5ddf0d[_0xabf1('0x2b')]['id']}},_0x45e64f={};_0x45e64f[_0xabf1('0x2c')]=_[_0xabf1('0x2d')](db['ChatApplication'][_0xabf1('0x2e')]);_0x45e64f[_0xabf1('0x2f')]=_['keys'](_0x5ddf0d[_0xabf1('0x2f')]);_0x45e64f['filters']=_['intersection'](_0x45e64f['model'],_0x45e64f[_0xabf1('0x2f')]);_0x582fbf[_0xabf1('0x30')]=_[_0xabf1('0x31')](_0x45e64f[_0xabf1('0x2c')],qs['fields'](_0x5ddf0d[_0xabf1('0x2f')][_0xabf1('0x32')]));_0x582fbf[_0xabf1('0x30')]=_0x582fbf[_0xabf1('0x30')]['length']?_0x582fbf[_0xabf1('0x30')]:_0x45e64f['model'];if(_0x5ddf0d[_0xabf1('0x2f')]['includeAll']){_0x582fbf['include']=[{'all':!![]}];}_0x582fbf=_[_0xabf1('0x33')]({},_0x582fbf,_0x5ddf0d[_0xabf1('0x34')]);return db[_0xabf1('0x35')][_0xabf1('0x36')](_0x582fbf)[_0xabf1('0x37')](handleEntityNotFound(_0xb54b63,null))[_0xabf1('0x37')](respondWithResult(_0xb54b63,null))[_0xabf1('0x38')](handleError(_0xb54b63,null));};exports[_0xabf1('0x26')]=function(_0x58f5b7,_0x1acc54){if(_0x58f5b7[_0xabf1('0x39')]['id']){delete _0x58f5b7['body']['id'];}return db['ChatApplication']['find']({'where':{'id':_0x58f5b7[_0xabf1('0x2b')]['id']}})['then'](handleEntityNotFound(_0x1acc54,null))[_0xabf1('0x37')](saveUpdates(_0x58f5b7[_0xabf1('0x39')],null))[_0xabf1('0x37')](respondWithResult(_0x1acc54,null))[_0xabf1('0x38')](handleError(_0x1acc54,null));};exports['destroy']=function(_0xd23acf,_0x49bb46){return db[_0xabf1('0x35')][_0xabf1('0x36')]({'where':{'id':_0xd23acf[_0xabf1('0x2b')]['id']}})[_0xabf1('0x37')](handleEntityNotFound(_0x49bb46,null))['then'](removeEntity(_0x49bb46,null))[_0xabf1('0x38')](handleError(_0x49bb46,null));};