Built motion from commit da617fac.|2.6.6
[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 _0xce3a=['../../config/license/hardware','../../config/logger','../../config/license/util','sendStatus','end','status','json','offset','undefined','limit','count','set','Content-Range','save','update','then','error','stack','name','send','show','params','model','keys','rawAttributes','query','filters','intersection','fields','attributes','length','includeAll','include','merge','options','ChatApplication','catch','body','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','fs-extra','lodash','squel','crypto','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch'];(function(_0x476d90,_0x459710){var _0x56f307=function(_0x1082fb){while(--_0x1082fb){_0x476d90['push'](_0x476d90['shift']());}};_0x56f307(++_0x459710);}(_0xce3a,0x194));var _0xace3=function(_0x11e1b6,_0x28e796){_0x11e1b6=_0x11e1b6-0x0;var _0x275329=_0xce3a[_0x11e1b6];return _0x275329;};'use strict';var emlformat=require(_0xace3('0x0'));var rimraf=require(_0xace3('0x1'));var zipdir=require(_0xace3('0x2'));var jsonpatch=require(_0xace3('0x3'));var rp=require(_0xace3('0x4'));var moment=require(_0xace3('0x5'));var BPromise=require(_0xace3('0x6'));var Mustache=require(_0xace3('0x7'));var util=require(_0xace3('0x8'));var path=require(_0xace3('0x9'));var sox=require(_0xace3('0xa'));var csv=require(_0xace3('0xb'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xace3('0xc'));var _=require(_0xace3('0xd'));var squel=require(_0xace3('0xe'));var crypto=require(_0xace3('0xf'));var jsforce=require('jsforce');var deskjs=require(_0xace3('0x10'));var toCsv=require('to-csv');var querystring=require(_0xace3('0x11'));var Papa=require(_0xace3('0x12'));var Redis=require(_0xace3('0x13'));var authService=require(_0xace3('0x14'));var qs=require(_0xace3('0x15'));var as=require(_0xace3('0x16'));var hardwareService=require(_0xace3('0x17'));var logger=require(_0xace3('0x18'))('api');var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require(_0xace3('0x19'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x4be1f1,_0x3566ad){_0x3566ad=_0x3566ad||0xcc;return function(_0x5ac505){if(_0x5ac505){return _0x4be1f1[_0xace3('0x1a')](_0x3566ad);}return _0x4be1f1['status'](_0x3566ad)[_0xace3('0x1b')]();};}function respondWithResult(_0x19dc11,_0x16ef3e){_0x16ef3e=_0x16ef3e||0xc8;return function(_0x5983b9){if(_0x5983b9){return _0x19dc11[_0xace3('0x1c')](_0x16ef3e)[_0xace3('0x1d')](_0x5983b9);}};}function respondWithFilteredResult(_0x1cfa39,_0x54ec35){return function(_0x51ed6c){if(_0x51ed6c){var _0x1ad5c0=typeof _0x54ec35[_0xace3('0x1e')]===_0xace3('0x1f')&&typeof _0x54ec35[_0xace3('0x20')]==='undefined';var _0x3debc2=_0x51ed6c[_0xace3('0x21')];var _0x39536d=_0x1ad5c0?0x0:_0x54ec35[_0xace3('0x1e')];var _0x2ef370=_0x1ad5c0?_0x51ed6c[_0xace3('0x21')]:_0x54ec35['offset']+_0x54ec35['limit'];var _0x2ee18d;if(_0x2ef370>=_0x3debc2){_0x2ef370=_0x3debc2;_0x2ee18d=0xc8;}else{_0x2ee18d=0xce;}_0x1cfa39['status'](_0x2ee18d);return _0x1cfa39[_0xace3('0x22')](_0xace3('0x23'),_0x39536d+'-'+_0x2ef370+'/'+_0x3debc2)['json'](_0x51ed6c);}return null;};}function patchUpdates(_0xab91f7){return function(_0x16f406){try{jsonpatch['apply'](_0x16f406,_0xab91f7,!![]);}catch(_0x4b90c9){return BPromise['reject'](_0x4b90c9);}return _0x16f406[_0xace3('0x24')]();};}function saveUpdates(_0x1ed5fe,_0x3bbe41){return function(_0x34a7a5){if(_0x34a7a5){return _0x34a7a5[_0xace3('0x25')](_0x1ed5fe)[_0xace3('0x26')](function(_0xa9b5ed){return _0xa9b5ed;});}return null;};}function removeEntity(_0x3c0a56,_0x5a4c02){return function(_0x5980fe){if(_0x5980fe){return _0x5980fe['destroy']()['then'](function(){_0x3c0a56[_0xace3('0x1c')](0xcc)[_0xace3('0x1b')]();});}};}function handleEntityNotFound(_0x2c137d,_0xf42f4){return function(_0x4b287c){if(!_0x4b287c){_0x2c137d[_0xace3('0x1a')](0x194);}return _0x4b287c;};}function handleError(_0x3b4cb5,_0x144f86){_0x144f86=_0x144f86||0x1f4;return function(_0x32e39d){logger[_0xace3('0x27')](_0x32e39d[_0xace3('0x28')]);if(_0x32e39d[_0xace3('0x29')]){delete _0x32e39d['name'];}_0x3b4cb5[_0xace3('0x1c')](_0x144f86)[_0xace3('0x2a')](_0x32e39d);};}exports[_0xace3('0x2b')]=function(_0x3aa28a,_0x599e73){var _0x56efae={'raw':!![],'where':{'id':_0x3aa28a[_0xace3('0x2c')]['id']}},_0x3b1ad1={};_0x3b1ad1[_0xace3('0x2d')]=_[_0xace3('0x2e')](db['ChatApplication'][_0xace3('0x2f')]);_0x3b1ad1[_0xace3('0x30')]=_[_0xace3('0x2e')](_0x3aa28a[_0xace3('0x30')]);_0x3b1ad1[_0xace3('0x31')]=_[_0xace3('0x32')](_0x3b1ad1[_0xace3('0x2d')],_0x3b1ad1['query']);_0x56efae['attributes']=_[_0xace3('0x32')](_0x3b1ad1[_0xace3('0x2d')],qs[_0xace3('0x33')](_0x3aa28a[_0xace3('0x30')][_0xace3('0x33')]));_0x56efae[_0xace3('0x34')]=_0x56efae[_0xace3('0x34')][_0xace3('0x35')]?_0x56efae[_0xace3('0x34')]:_0x3b1ad1[_0xace3('0x2d')];if(_0x3aa28a[_0xace3('0x30')][_0xace3('0x36')]){_0x56efae[_0xace3('0x37')]=[{'all':!![]}];}_0x56efae=_[_0xace3('0x38')]({},_0x56efae,_0x3aa28a[_0xace3('0x39')]);return db[_0xace3('0x3a')]['find'](_0x56efae)[_0xace3('0x26')](handleEntityNotFound(_0x599e73,null))[_0xace3('0x26')](respondWithResult(_0x599e73,null))[_0xace3('0x3b')](handleError(_0x599e73,null));};exports[_0xace3('0x25')]=function(_0x39a447,_0xe0243b){if(_0x39a447[_0xace3('0x3c')]['id']){delete _0x39a447[_0xace3('0x3c')]['id'];}return db[_0xace3('0x3a')]['find']({'where':{'id':_0x39a447[_0xace3('0x2c')]['id']}})[_0xace3('0x26')](handleEntityNotFound(_0xe0243b,null))[_0xace3('0x26')](saveUpdates(_0x39a447[_0xace3('0x3c')],null))['then'](respondWithResult(_0xe0243b,null))['catch'](handleError(_0xe0243b,null));};exports['destroy']=function(_0x541d51,_0x181d79){return db[_0xace3('0x3a')]['find']({'where':{'id':_0x541d51[_0xace3('0x2c')]['id']}})['then'](handleEntityNotFound(_0x181d79,null))['then'](removeEntity(_0x181d79,null))[_0xace3('0x3b')](handleError(_0x181d79,null));};