Built motion from commit (unavailable).|2.5.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 _0xa940=['papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','sendStatus','end','status','json','count','offset','limit','apply','reject','save','update','then','destroy','error','stack','name','send','show','params','model','keys','ChatApplication','rawAttributes','query','filters','intersection','fields','attributes','include','merge','options','find','catch','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','bluebird','mustache','util','path','sox','to-csv','lodash','jsforce','desk.js','querystring'];(function(_0x30ed68,_0x1bec8c){var _0x31d73a=function(_0x30f1d1){while(--_0x30f1d1){_0x30ed68['push'](_0x30ed68['shift']());}};_0x31d73a(++_0x1bec8c);}(_0xa940,0x113));var _0x0a94=function(_0x35dbcd,_0x4e143f){_0x35dbcd=_0x35dbcd-0x0;var _0x54a28a=_0xa940[_0x35dbcd];return _0x54a28a;};'use strict';var pdf=require(_0x0a94('0x0'));var emlformat=require(_0x0a94('0x1'));var rimraf=require(_0x0a94('0x2'));var zipdir=require(_0x0a94('0x3'));var jsonpatch=require(_0x0a94('0x4'));var rp=require('request-promise');var moment=require('moment');var BPromise=require(_0x0a94('0x5'));var Mustache=require(_0x0a94('0x6'));var util=require(_0x0a94('0x7'));var path=require(_0x0a94('0x8'));var sox=require(_0x0a94('0x9'));var csv=require(_0x0a94('0xa'));var ejs=require('ejs');var fs=require('fs');var _=require(_0x0a94('0xb'));var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0x0a94('0xc'));var deskjs=require(_0x0a94('0xd'));var toCsv=require('to-csv');var querystring=require(_0x0a94('0xe'));var Papa=require(_0x0a94('0xf'));var Redis=require(_0x0a94('0x10'));var authService=require(_0x0a94('0x11'));var qs=require(_0x0a94('0x12'));var as=require(_0x0a94('0x13'));var hardwareService=require(_0x0a94('0x14'));var logger=require(_0x0a94('0x15'))(_0x0a94('0x16'));var utils=require(_0x0a94('0x17'));var config=require('../../config/environment');var licenseUtil=require(_0x0a94('0x18'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x128aac,_0x3f7fc3){_0x3f7fc3=_0x3f7fc3||0xcc;return function(_0x3d0ef7){if(_0x3d0ef7){return _0x128aac[_0x0a94('0x19')](_0x3f7fc3);}return _0x128aac['status'](_0x3f7fc3)[_0x0a94('0x1a')]();};}function respondWithResult(_0x2f3071,_0x1e1b1f){_0x1e1b1f=_0x1e1b1f||0xc8;return function(_0x3aeb27){if(_0x3aeb27){return _0x2f3071[_0x0a94('0x1b')](_0x1e1b1f)[_0x0a94('0x1c')](_0x3aeb27);}};}function respondWithFilteredResult(_0x338bc4,_0x322c32){return function(_0x5b6240){if(_0x5b6240){var _0x250472=_0x5b6240[_0x0a94('0x1d')],_0x19ffe0=_0x322c32[_0x0a94('0x1e')],_0x388a90=_0x322c32[_0x0a94('0x1e')]+_0x322c32[_0x0a94('0x1f')],_0x4d3799;if(_0x388a90>=_0x250472){_0x388a90=_0x250472;_0x4d3799=0xc8;}else{_0x4d3799=0xce;}_0x338bc4[_0x0a94('0x1b')](_0x4d3799);return _0x338bc4['set']('Content-Range',_0x19ffe0+'-'+_0x388a90+'/'+_0x250472)[_0x0a94('0x1c')](_0x5b6240);}return null;};}function patchUpdates(_0x4856cf){return function(_0x3d2f03){try{jsonpatch[_0x0a94('0x20')](_0x3d2f03,_0x4856cf,!![]);}catch(_0x1fa4ab){return BPromise[_0x0a94('0x21')](_0x1fa4ab);}return _0x3d2f03[_0x0a94('0x22')]();};}function saveUpdates(_0x5d2771,_0x33f0a2){return function(_0x16a7d4){if(_0x16a7d4){return _0x16a7d4[_0x0a94('0x23')](_0x5d2771)[_0x0a94('0x24')](function(_0x5370bb){return _0x5370bb;});}return null;};}function removeEntity(_0x572ec2,_0x4b1227){return function(_0x5048b4){if(_0x5048b4){return _0x5048b4[_0x0a94('0x25')]()[_0x0a94('0x24')](function(){_0x572ec2[_0x0a94('0x1b')](0xcc)[_0x0a94('0x1a')]();});}};}function handleEntityNotFound(_0x100fd2,_0x777cb8){return function(_0x1f6e67){if(!_0x1f6e67){_0x100fd2[_0x0a94('0x19')](0x194);}return _0x1f6e67;};}function handleError(_0x5f7c79,_0x22ad95){_0x22ad95=_0x22ad95||0x1f4;return function(_0xb2d3f){logger[_0x0a94('0x26')](_0xb2d3f[_0x0a94('0x27')]);if(_0xb2d3f[_0x0a94('0x28')]){delete _0xb2d3f['name'];}_0x5f7c79['status'](_0x22ad95)[_0x0a94('0x29')](_0xb2d3f);};}exports[_0x0a94('0x2a')]=function(_0x598874,_0x56c628){var _0xfeddb4={'raw':!![],'where':{'id':_0x598874[_0x0a94('0x2b')]['id']}},_0x40293c={};_0x40293c[_0x0a94('0x2c')]=_[_0x0a94('0x2d')](db[_0x0a94('0x2e')][_0x0a94('0x2f')]);_0x40293c[_0x0a94('0x30')]=_['keys'](_0x598874[_0x0a94('0x30')]);_0x40293c[_0x0a94('0x31')]=_[_0x0a94('0x32')](_0x40293c[_0x0a94('0x2c')],_0x40293c[_0x0a94('0x30')]);_0xfeddb4['attributes']=_['intersection'](_0x40293c[_0x0a94('0x2c')],qs['fields'](_0x598874['query'][_0x0a94('0x33')]));_0xfeddb4[_0x0a94('0x34')]=_0xfeddb4[_0x0a94('0x34')]['length']?_0xfeddb4[_0x0a94('0x34')]:_0x40293c['model'];if(_0x598874[_0x0a94('0x30')]['includeAll']){_0xfeddb4[_0x0a94('0x35')]=[{'all':!![]}];}_0xfeddb4=_[_0x0a94('0x36')]({},_0xfeddb4,_0x598874[_0x0a94('0x37')]);return db[_0x0a94('0x2e')][_0x0a94('0x38')](_0xfeddb4)[_0x0a94('0x24')](handleEntityNotFound(_0x56c628,null))['then'](respondWithResult(_0x56c628,null))[_0x0a94('0x39')](handleError(_0x56c628,null));};exports[_0x0a94('0x23')]=function(_0x3eb7d3,_0x161ded){if(_0x3eb7d3['body']['id']){delete _0x3eb7d3['body']['id'];}return db[_0x0a94('0x2e')][_0x0a94('0x38')]({'where':{'id':_0x3eb7d3[_0x0a94('0x2b')]['id']}})[_0x0a94('0x24')](handleEntityNotFound(_0x161ded,null))[_0x0a94('0x24')](saveUpdates(_0x3eb7d3['body'],null))[_0x0a94('0x24')](respondWithResult(_0x161ded,null))['catch'](handleError(_0x161ded,null));};exports[_0x0a94('0x25')]=function(_0x230722,_0x2d3cc4){return db[_0x0a94('0x2e')][_0x0a94('0x38')]({'where':{'id':_0x230722[_0x0a94('0x2b')]['id']}})[_0x0a94('0x24')](handleEntityNotFound(_0x2d3cc4,null))[_0x0a94('0x24')](removeEntity(_0x2d3cc4,null))['catch'](handleError(_0x2d3cc4,null));};