Built motion from commit 85328c08.|2.5.50
[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 _0x0e0f=['error','stack','name','send','show','model','ChatApplication','query','keys','filters','attributes','intersection','fields','includeAll','include','options','catch','update','body','find','params','eml-format','fast-json-patch','request-promise','moment','bluebird','mustache','path','sox','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','to-csv','querystring','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/license/util','sendStatus','status','undefined','limit','offset','save','then','destroy','end'];(function(_0x4beb44,_0x45c192){var _0x150dc0=function(_0x2ed5f5){while(--_0x2ed5f5){_0x4beb44['push'](_0x4beb44['shift']());}};_0x150dc0(++_0x45c192);}(_0x0e0f,0xe5));var _0xf0e0=function(_0x446122,_0x2210aa){_0x446122=_0x446122-0x0;var _0x4410c3=_0x0e0f[_0x446122];return _0x4410c3;};'use strict';var emlformat=require(_0xf0e0('0x0'));var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require(_0xf0e0('0x1'));var rp=require(_0xf0e0('0x2'));var moment=require(_0xf0e0('0x3'));var BPromise=require(_0xf0e0('0x4'));var Mustache=require(_0xf0e0('0x5'));var util=require('util');var path=require(_0xf0e0('0x6'));var sox=require(_0xf0e0('0x7'));var csv=require('to-csv');var ejs=require(_0xf0e0('0x8'));var fs=require('fs');var fs_extra=require(_0xf0e0('0x9'));var _=require(_0xf0e0('0xa'));var squel=require(_0xf0e0('0xb'));var crypto=require(_0xf0e0('0xc'));var jsforce=require(_0xf0e0('0xd'));var deskjs=require(_0xf0e0('0xe'));var toCsv=require(_0xf0e0('0xf'));var querystring=require(_0xf0e0('0x10'));var Papa=require('papaparse');var Redis=require(_0xf0e0('0x11'));var authService=require('../../components/auth/service');var qs=require(_0xf0e0('0x12'));var as=require(_0xf0e0('0x13'));var hardwareService=require(_0xf0e0('0x14'));var logger=require('../../config/logger')('api');var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require(_0xf0e0('0x15'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x501c86,_0x24d3a9){_0x24d3a9=_0x24d3a9||0xcc;return function(_0x5bd0ab){if(_0x5bd0ab){return _0x501c86[_0xf0e0('0x16')](_0x24d3a9);}return _0x501c86[_0xf0e0('0x17')](_0x24d3a9)['end']();};}function respondWithResult(_0x552683,_0x457bfc){_0x457bfc=_0x457bfc||0xc8;return function(_0x5b3719){if(_0x5b3719){return _0x552683[_0xf0e0('0x17')](_0x457bfc)['json'](_0x5b3719);}};}function respondWithFilteredResult(_0x3357f0,_0x55e350){return function(_0x40d87b){if(_0x40d87b){var _0x186e92=typeof _0x55e350['offset']===_0xf0e0('0x18')&&typeof _0x55e350[_0xf0e0('0x19')]===_0xf0e0('0x18');var _0x36206d=_0x40d87b['count'];var _0x3d725b=_0x186e92?0x0:_0x55e350[_0xf0e0('0x1a')];var _0x5e221e=_0x186e92?_0x40d87b['count']:_0x55e350[_0xf0e0('0x1a')]+_0x55e350[_0xf0e0('0x19')];var _0x51c8c8;if(_0x5e221e>=_0x36206d){_0x5e221e=_0x36206d;_0x51c8c8=0xc8;}else{_0x51c8c8=0xce;}_0x3357f0[_0xf0e0('0x17')](_0x51c8c8);return _0x3357f0['set']('Content-Range',_0x3d725b+'-'+_0x5e221e+'/'+_0x36206d)['json'](_0x40d87b);}return null;};}function patchUpdates(_0x350649){return function(_0x3ed3f8){try{jsonpatch['apply'](_0x3ed3f8,_0x350649,!![]);}catch(_0x54e139){return BPromise['reject'](_0x54e139);}return _0x3ed3f8[_0xf0e0('0x1b')]();};}function saveUpdates(_0x52e518,_0x586ef0){return function(_0x48b789){if(_0x48b789){return _0x48b789['update'](_0x52e518)[_0xf0e0('0x1c')](function(_0x357e3a){return _0x357e3a;});}return null;};}function removeEntity(_0x1a1cdb,_0x211d1c){return function(_0x507c66){if(_0x507c66){return _0x507c66[_0xf0e0('0x1d')]()[_0xf0e0('0x1c')](function(){_0x1a1cdb['status'](0xcc)[_0xf0e0('0x1e')]();});}};}function handleEntityNotFound(_0x50cb6e,_0x379256){return function(_0x364675){if(!_0x364675){_0x50cb6e['sendStatus'](0x194);}return _0x364675;};}function handleError(_0xce3161,_0x3e7e3a){_0x3e7e3a=_0x3e7e3a||0x1f4;return function(_0x51c3e2){logger[_0xf0e0('0x1f')](_0x51c3e2[_0xf0e0('0x20')]);if(_0x51c3e2[_0xf0e0('0x21')]){delete _0x51c3e2[_0xf0e0('0x21')];}_0xce3161[_0xf0e0('0x17')](_0x3e7e3a)[_0xf0e0('0x22')](_0x51c3e2);};}exports[_0xf0e0('0x23')]=function(_0x3b4a3b,_0xfe6ec){var _0xb08e13={'raw':!![],'where':{'id':_0x3b4a3b['params']['id']}},_0x251a8b={};_0x251a8b[_0xf0e0('0x24')]=_['keys'](db[_0xf0e0('0x25')]['rawAttributes']);_0x251a8b[_0xf0e0('0x26')]=_[_0xf0e0('0x27')](_0x3b4a3b[_0xf0e0('0x26')]);_0x251a8b[_0xf0e0('0x28')]=_['intersection'](_0x251a8b[_0xf0e0('0x24')],_0x251a8b[_0xf0e0('0x26')]);_0xb08e13[_0xf0e0('0x29')]=_[_0xf0e0('0x2a')](_0x251a8b['model'],qs[_0xf0e0('0x2b')](_0x3b4a3b[_0xf0e0('0x26')][_0xf0e0('0x2b')]));_0xb08e13[_0xf0e0('0x29')]=_0xb08e13[_0xf0e0('0x29')]['length']?_0xb08e13[_0xf0e0('0x29')]:_0x251a8b[_0xf0e0('0x24')];if(_0x3b4a3b[_0xf0e0('0x26')][_0xf0e0('0x2c')]){_0xb08e13[_0xf0e0('0x2d')]=[{'all':!![]}];}_0xb08e13=_['merge']({},_0xb08e13,_0x3b4a3b[_0xf0e0('0x2e')]);return db[_0xf0e0('0x25')]['find'](_0xb08e13)[_0xf0e0('0x1c')](handleEntityNotFound(_0xfe6ec,null))[_0xf0e0('0x1c')](respondWithResult(_0xfe6ec,null))[_0xf0e0('0x2f')](handleError(_0xfe6ec,null));};exports[_0xf0e0('0x30')]=function(_0x89dbf3,_0x1105d7){if(_0x89dbf3[_0xf0e0('0x31')]['id']){delete _0x89dbf3['body']['id'];}return db[_0xf0e0('0x25')][_0xf0e0('0x32')]({'where':{'id':_0x89dbf3[_0xf0e0('0x33')]['id']}})[_0xf0e0('0x1c')](handleEntityNotFound(_0x1105d7,null))[_0xf0e0('0x1c')](saveUpdates(_0x89dbf3[_0xf0e0('0x31')],null))['then'](respondWithResult(_0x1105d7,null))['catch'](handleError(_0x1105d7,null));};exports[_0xf0e0('0x1d')]=function(_0x5addaf,_0x11113c){return db[_0xf0e0('0x25')][_0xf0e0('0x32')]({'where':{'id':_0x5addaf[_0xf0e0('0x33')]['id']}})['then'](handleEntityNotFound(_0x11113c,null))['then'](removeEntity(_0x11113c,null))[_0xf0e0('0x2f')](handleError(_0x11113c,null));};