ed75f2d145a5a272aaacfb776019e77d756e2f45
[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 _0x87f1=['squel','crypto','jsforce','desk.js','querystring','ioredis','../../components/auth/service','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','end','status','json','undefined','limit','offset','count','set','Content-Range','apply','save','update','destroy','then','sendStatus','error','stack','name','merge','body','contact','message','agent','account','show','keys','ChatApplication','query','filters','intersection','model','attributes','fields','includeAll','include','options','catch','find','params','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','path','to-csv','fs-extra'];(function(_0x14c3f5,_0x5093fc){var _0x3699b1=function(_0x230ebe){while(--_0x230ebe){_0x14c3f5['push'](_0x14c3f5['shift']());}};_0x3699b1(++_0x5093fc);}(_0x87f1,0x170));var _0x187f=function(_0x287986,_0x2c9f58){_0x287986=_0x287986-0x0;var _0x3e9532=_0x87f1[_0x287986];return _0x3e9532;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x187f('0x0'));var zipdir=require(_0x187f('0x1'));var jsonpatch=require(_0x187f('0x2'));var rp=require(_0x187f('0x3'));var moment=require(_0x187f('0x4'));var BPromise=require(_0x187f('0x5'));var Mustache=require(_0x187f('0x6'));var util=require('util');var path=require(_0x187f('0x7'));var sox=require('sox');var csv=require(_0x187f('0x8'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x187f('0x9'));var _=require('lodash');var squel=require(_0x187f('0xa'));var crypto=require(_0x187f('0xb'));var jsforce=require(_0x187f('0xc'));var deskjs=require(_0x187f('0xd'));var toCsv=require(_0x187f('0x8'));var querystring=require(_0x187f('0xe'));var Papa=require('papaparse');var Redis=require(_0x187f('0xf'));var authService=require(_0x187f('0x10'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x187f('0x11'));var logger=require(_0x187f('0x12'))(_0x187f('0x13'));var utils=require(_0x187f('0x14'));var config=require(_0x187f('0x15'));var licenseUtil=require(_0x187f('0x16'));var db=require(_0x187f('0x17'))['db'];function respondWithStatusCode(_0x1298f5,_0x7f7067){_0x7f7067=_0x7f7067||0xcc;return function(_0x83b3a0){if(_0x83b3a0){return _0x1298f5['sendStatus'](_0x7f7067);}return _0x1298f5['status'](_0x7f7067)[_0x187f('0x18')]();};}function respondWithResult(_0x176fae,_0x4683fd){_0x4683fd=_0x4683fd||0xc8;return function(_0x2eee87){if(_0x2eee87){return _0x176fae[_0x187f('0x19')](_0x4683fd)[_0x187f('0x1a')](_0x2eee87);}};}function respondWithFilteredResult(_0xf3600,_0x557047){return function(_0x11c254){if(_0x11c254){var _0x4e232d=typeof _0x557047['offset']===_0x187f('0x1b')&&typeof _0x557047[_0x187f('0x1c')]==='undefined';var _0x1d30e8=_0x11c254['count'];var _0x50e6cc=_0x4e232d?0x0:_0x557047[_0x187f('0x1d')];var _0x195931=_0x4e232d?_0x11c254[_0x187f('0x1e')]:_0x557047[_0x187f('0x1d')]+_0x557047['limit'];var _0x5ecdc0;if(_0x195931>=_0x1d30e8){_0x195931=_0x1d30e8;_0x5ecdc0=0xc8;}else{_0x5ecdc0=0xce;}_0xf3600[_0x187f('0x19')](_0x5ecdc0);return _0xf3600[_0x187f('0x1f')](_0x187f('0x20'),_0x50e6cc+'-'+_0x195931+'/'+_0x1d30e8)['json'](_0x11c254);}return null;};}function patchUpdates(_0x546c4c){return function(_0x503101){try{jsonpatch[_0x187f('0x21')](_0x503101,_0x546c4c,!![]);}catch(_0x39d34d){return BPromise['reject'](_0x39d34d);}return _0x503101[_0x187f('0x22')]();};}function saveUpdates(_0xbc434c,_0x354453){return function(_0x4e069b){if(_0x4e069b){return _0x4e069b[_0x187f('0x23')](_0xbc434c)['then'](function(_0x123afe){return _0x123afe;});}return null;};}function removeEntity(_0x1ed126,_0x2a8299){return function(_0x48730e){if(_0x48730e){return _0x48730e[_0x187f('0x24')]()[_0x187f('0x25')](function(){_0x1ed126[_0x187f('0x19')](0xcc)[_0x187f('0x18')]();});}};}function handleEntityNotFound(_0x2b0e76,_0x5d036c){return function(_0x5a3426){if(!_0x5a3426){_0x2b0e76[_0x187f('0x26')](0x194);}return _0x5a3426;};}function handleError(_0x1a58eb,_0x388a58){_0x388a58=_0x388a58||0x1f4;return function(_0x372080){logger[_0x187f('0x27')](_0x372080[_0x187f('0x28')]);if(_0x372080[_0x187f('0x29')]){delete _0x372080[_0x187f('0x29')];}_0x1a58eb[_0x187f('0x19')](_0x388a58)['send'](_0x372080);};}function getMustacheRender(_0x17b3c3,_0x3ad607){return Mustache['render'](_0x17b3c3,_[_0x187f('0x2a')](_0x3ad607[_0x187f('0x2b')],{'contact':_0x3ad607[_0x187f('0x2c')],'message':_0x3ad607[_0x187f('0x2d')],'agent':_0x3ad607[_0x187f('0x2e')],'interaction':_0x3ad607['interaction'],'account':_0x3ad607[_0x187f('0x2f')]}))||'';}exports[_0x187f('0x30')]=function(_0x4943ed,_0x1feac4){var _0x3b48e9={'raw':!![],'where':{'id':_0x4943ed['params']['id']}},_0x38283f={};_0x38283f['model']=_[_0x187f('0x31')](db[_0x187f('0x32')]['rawAttributes']);_0x38283f['query']=_[_0x187f('0x31')](_0x4943ed[_0x187f('0x33')]);_0x38283f[_0x187f('0x34')]=_[_0x187f('0x35')](_0x38283f[_0x187f('0x36')],_0x38283f[_0x187f('0x33')]);_0x3b48e9[_0x187f('0x37')]=_[_0x187f('0x35')](_0x38283f[_0x187f('0x36')],qs[_0x187f('0x38')](_0x4943ed[_0x187f('0x33')][_0x187f('0x38')]));_0x3b48e9[_0x187f('0x37')]=_0x3b48e9[_0x187f('0x37')]['length']?_0x3b48e9['attributes']:_0x38283f[_0x187f('0x36')];if(_0x4943ed[_0x187f('0x33')][_0x187f('0x39')]){_0x3b48e9[_0x187f('0x3a')]=[{'all':!![]}];}_0x3b48e9=_[_0x187f('0x2a')]({},_0x3b48e9,_0x4943ed[_0x187f('0x3b')]);return db[_0x187f('0x32')]['find'](_0x3b48e9)['then'](handleEntityNotFound(_0x1feac4,null))[_0x187f('0x25')](respondWithResult(_0x1feac4,null))[_0x187f('0x3c')](handleError(_0x1feac4,null));};exports['update']=function(_0x3dbc78,_0xd8caa9){if(_0x3dbc78['body']['id']){delete _0x3dbc78[_0x187f('0x2b')]['id'];}return db[_0x187f('0x32')][_0x187f('0x3d')]({'where':{'id':_0x3dbc78[_0x187f('0x3e')]['id']}})[_0x187f('0x25')](handleEntityNotFound(_0xd8caa9,null))[_0x187f('0x25')](saveUpdates(_0x3dbc78[_0x187f('0x2b')],null))['then'](respondWithResult(_0xd8caa9,null))[_0x187f('0x3c')](handleError(_0xd8caa9,null));};exports[_0x187f('0x24')]=function(_0x3ae718,_0x48af52){return db[_0x187f('0x32')][_0x187f('0x3d')]({'where':{'id':_0x3ae718[_0x187f('0x3e')]['id']}})[_0x187f('0x25')](handleEntityNotFound(_0x48af52,null))['then'](removeEntity(_0x48af52,null))[_0x187f('0x3c')](handleError(_0x48af52,null));};