Built motion from commit 9d0783e6.|2.6.13
[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 _0x6e16=['to-csv','ejs','fs-extra','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/license/util','../../mysqldb','sendStatus','end','status','undefined','limit','count','offset','set','json','apply','reject','save','update','then','destroy','error','stack','name','show','params','model','keys','ChatApplication','rawAttributes','query','filters','intersection','attributes','fields','length','includeAll','include','options','catch','body','find','zip-dir','request-promise','bluebird','mustache','path'];(function(_0x1c0280,_0xeef5a3){var _0x45f8a0=function(_0x590d3b){while(--_0x590d3b){_0x1c0280['push'](_0x1c0280['shift']());}};_0x45f8a0(++_0xeef5a3);}(_0x6e16,0x1d3));var _0x66e1=function(_0x12c5ab,_0x5cb466){_0x12c5ab=_0x12c5ab-0x0;var _0x1248fd=_0x6e16[_0x12c5ab];return _0x1248fd;};'use strict';var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require(_0x66e1('0x0'));var jsonpatch=require('fast-json-patch');var rp=require(_0x66e1('0x1'));var moment=require('moment');var BPromise=require(_0x66e1('0x2'));var Mustache=require(_0x66e1('0x3'));var util=require('util');var path=require(_0x66e1('0x4'));var sox=require('sox');var csv=require(_0x66e1('0x5'));var ejs=require(_0x66e1('0x6'));var fs=require('fs');var fs_extra=require(_0x66e1('0x7'));var _=require('lodash');var squel=require(_0x66e1('0x8'));var crypto=require(_0x66e1('0x9'));var jsforce=require(_0x66e1('0xa'));var deskjs=require(_0x66e1('0xb'));var toCsv=require(_0x66e1('0x5'));var querystring=require(_0x66e1('0xc'));var Papa=require(_0x66e1('0xd'));var Redis=require(_0x66e1('0xe'));var authService=require(_0x66e1('0xf'));var qs=require(_0x66e1('0x10'));var as=require(_0x66e1('0x11'));var hardwareService=require(_0x66e1('0x12'));var logger=require(_0x66e1('0x13'))(_0x66e1('0x14'));var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require(_0x66e1('0x15'));var db=require(_0x66e1('0x16'))['db'];function respondWithStatusCode(_0x23e018,_0x497712){_0x497712=_0x497712||0xcc;return function(_0x58c184){if(_0x58c184){return _0x23e018[_0x66e1('0x17')](_0x497712);}return _0x23e018['status'](_0x497712)[_0x66e1('0x18')]();};}function respondWithResult(_0x3e36ff,_0x5b802b){_0x5b802b=_0x5b802b||0xc8;return function(_0x9c17f9){if(_0x9c17f9){return _0x3e36ff[_0x66e1('0x19')](_0x5b802b)['json'](_0x9c17f9);}};}function respondWithFilteredResult(_0x137f52,_0x12ca0b){return function(_0x18e2ab){if(_0x18e2ab){var _0x3a68b3=typeof _0x12ca0b['offset']===_0x66e1('0x1a')&&typeof _0x12ca0b[_0x66e1('0x1b')]===_0x66e1('0x1a');var _0x28e236=_0x18e2ab[_0x66e1('0x1c')];var _0x4f3276=_0x3a68b3?0x0:_0x12ca0b['offset'];var _0x2b5585=_0x3a68b3?_0x18e2ab['count']:_0x12ca0b[_0x66e1('0x1d')]+_0x12ca0b[_0x66e1('0x1b')];var _0x260e87;if(_0x2b5585>=_0x28e236){_0x2b5585=_0x28e236;_0x260e87=0xc8;}else{_0x260e87=0xce;}_0x137f52[_0x66e1('0x19')](_0x260e87);return _0x137f52[_0x66e1('0x1e')]('Content-Range',_0x4f3276+'-'+_0x2b5585+'/'+_0x28e236)[_0x66e1('0x1f')](_0x18e2ab);}return null;};}function patchUpdates(_0x23c6ce){return function(_0xe2822e){try{jsonpatch[_0x66e1('0x20')](_0xe2822e,_0x23c6ce,!![]);}catch(_0x28f6cf){return BPromise[_0x66e1('0x21')](_0x28f6cf);}return _0xe2822e[_0x66e1('0x22')]();};}function saveUpdates(_0x38cf5b,_0x11232c){return function(_0x350b81){if(_0x350b81){return _0x350b81[_0x66e1('0x23')](_0x38cf5b)[_0x66e1('0x24')](function(_0x43686e){return _0x43686e;});}return null;};}function removeEntity(_0x2ea42d,_0x756840){return function(_0x11b7f0){if(_0x11b7f0){return _0x11b7f0[_0x66e1('0x25')]()['then'](function(){_0x2ea42d[_0x66e1('0x19')](0xcc)['end']();});}};}function handleEntityNotFound(_0x203919,_0x414c30){return function(_0x181a7b){if(!_0x181a7b){_0x203919[_0x66e1('0x17')](0x194);}return _0x181a7b;};}function handleError(_0x1e0dfe,_0x4f500e){_0x4f500e=_0x4f500e||0x1f4;return function(_0x5c416d){logger[_0x66e1('0x26')](_0x5c416d[_0x66e1('0x27')]);if(_0x5c416d['name']){delete _0x5c416d[_0x66e1('0x28')];}_0x1e0dfe['status'](_0x4f500e)['send'](_0x5c416d);};}exports[_0x66e1('0x29')]=function(_0x3fcc99,_0xdd2360){var _0x2720af={'raw':!![],'where':{'id':_0x3fcc99[_0x66e1('0x2a')]['id']}},_0x218902={};_0x218902[_0x66e1('0x2b')]=_[_0x66e1('0x2c')](db[_0x66e1('0x2d')][_0x66e1('0x2e')]);_0x218902[_0x66e1('0x2f')]=_[_0x66e1('0x2c')](_0x3fcc99['query']);_0x218902[_0x66e1('0x30')]=_[_0x66e1('0x31')](_0x218902['model'],_0x218902[_0x66e1('0x2f')]);_0x2720af[_0x66e1('0x32')]=_[_0x66e1('0x31')](_0x218902[_0x66e1('0x2b')],qs['fields'](_0x3fcc99[_0x66e1('0x2f')][_0x66e1('0x33')]));_0x2720af[_0x66e1('0x32')]=_0x2720af['attributes'][_0x66e1('0x34')]?_0x2720af['attributes']:_0x218902['model'];if(_0x3fcc99['query'][_0x66e1('0x35')]){_0x2720af[_0x66e1('0x36')]=[{'all':!![]}];}_0x2720af=_['merge']({},_0x2720af,_0x3fcc99[_0x66e1('0x37')]);return db[_0x66e1('0x2d')]['find'](_0x2720af)['then'](handleEntityNotFound(_0xdd2360,null))[_0x66e1('0x24')](respondWithResult(_0xdd2360,null))[_0x66e1('0x38')](handleError(_0xdd2360,null));};exports[_0x66e1('0x23')]=function(_0x4a91b9,_0x364053){if(_0x4a91b9[_0x66e1('0x39')]['id']){delete _0x4a91b9[_0x66e1('0x39')]['id'];}return db[_0x66e1('0x2d')]['find']({'where':{'id':_0x4a91b9[_0x66e1('0x2a')]['id']}})[_0x66e1('0x24')](handleEntityNotFound(_0x364053,null))[_0x66e1('0x24')](saveUpdates(_0x4a91b9[_0x66e1('0x39')],null))[_0x66e1('0x24')](respondWithResult(_0x364053,null))[_0x66e1('0x38')](handleError(_0x364053,null));};exports[_0x66e1('0x25')]=function(_0x361f71,_0xb17802){return db[_0x66e1('0x2d')][_0x66e1('0x3a')]({'where':{'id':_0x361f71[_0x66e1('0x2a')]['id']}})[_0x66e1('0x24')](handleEntityNotFound(_0xb17802,null))[_0x66e1('0x24')](removeEntity(_0xb17802,null))[_0x66e1('0x38')](handleError(_0xb17802,null));};