1e469b3c2a3c6ae436123d675c0ba5a84caed1bb
[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 _0x3cfb=['rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','path','sox','to-csv','fs-extra','lodash','squel','jsforce','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','status','end','json','offset','undefined','limit','count','Content-Range','apply','reject','save','update','then','destroy','sendStatus','error','name','show','params','model','keys','ChatApplication','rawAttributes','query','intersection','fields','attributes','length','includeAll','include','merge','options','body','find','catch','eml-format'];(function(_0x209941,_0x5c9988){var _0x1e8729=function(_0x51a9b8){while(--_0x51a9b8){_0x209941['push'](_0x209941['shift']());}};_0x1e8729(++_0x5c9988);}(_0x3cfb,0x1b8));var _0xb3cf=function(_0x5a06b1,_0x3feb4c){_0x5a06b1=_0x5a06b1-0x0;var _0x42bfbd=_0x3cfb[_0x5a06b1];return _0x42bfbd;};'use strict';var emlformat=require(_0xb3cf('0x0'));var rimraf=require(_0xb3cf('0x1'));var zipdir=require(_0xb3cf('0x2'));var jsonpatch=require(_0xb3cf('0x3'));var rp=require(_0xb3cf('0x4'));var moment=require(_0xb3cf('0x5'));var BPromise=require(_0xb3cf('0x6'));var Mustache=require(_0xb3cf('0x7'));var util=require('util');var path=require(_0xb3cf('0x8'));var sox=require(_0xb3cf('0x9'));var csv=require(_0xb3cf('0xa'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xb3cf('0xb'));var _=require(_0xb3cf('0xc'));var squel=require(_0xb3cf('0xd'));var crypto=require('crypto');var jsforce=require(_0xb3cf('0xe'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require(_0xb3cf('0xf'));var Papa=require(_0xb3cf('0x10'));var Redis=require(_0xb3cf('0x11'));var authService=require(_0xb3cf('0x12'));var qs=require(_0xb3cf('0x13'));var as=require(_0xb3cf('0x14'));var hardwareService=require(_0xb3cf('0x15'));var logger=require(_0xb3cf('0x16'))(_0xb3cf('0x17'));var utils=require(_0xb3cf('0x18'));var config=require(_0xb3cf('0x19'));var licenseUtil=require(_0xb3cf('0x1a'));var db=require(_0xb3cf('0x1b'))['db'];function respondWithStatusCode(_0x80af12,_0x16bb17){_0x16bb17=_0x16bb17||0xcc;return function(_0x530325){if(_0x530325){return _0x80af12['sendStatus'](_0x16bb17);}return _0x80af12[_0xb3cf('0x1c')](_0x16bb17)[_0xb3cf('0x1d')]();};}function respondWithResult(_0x5ec589,_0x21ce6c){_0x21ce6c=_0x21ce6c||0xc8;return function(_0x510bae){if(_0x510bae){return _0x5ec589['status'](_0x21ce6c)[_0xb3cf('0x1e')](_0x510bae);}};}function respondWithFilteredResult(_0x66ea06,_0x2eff5c){return function(_0x56f703){if(_0x56f703){var _0x17e8cd=typeof _0x2eff5c[_0xb3cf('0x1f')]===_0xb3cf('0x20')&&typeof _0x2eff5c[_0xb3cf('0x21')]===_0xb3cf('0x20');var _0x31ad79=_0x56f703[_0xb3cf('0x22')];var _0x2d0018=_0x17e8cd?0x0:_0x2eff5c[_0xb3cf('0x1f')];var _0x222c1d=_0x17e8cd?_0x56f703['count']:_0x2eff5c[_0xb3cf('0x1f')]+_0x2eff5c[_0xb3cf('0x21')];var _0x35fb62;if(_0x222c1d>=_0x31ad79){_0x222c1d=_0x31ad79;_0x35fb62=0xc8;}else{_0x35fb62=0xce;}_0x66ea06[_0xb3cf('0x1c')](_0x35fb62);return _0x66ea06['set'](_0xb3cf('0x23'),_0x2d0018+'-'+_0x222c1d+'/'+_0x31ad79)[_0xb3cf('0x1e')](_0x56f703);}return null;};}function patchUpdates(_0x2557db){return function(_0x1dfbc3){try{jsonpatch[_0xb3cf('0x24')](_0x1dfbc3,_0x2557db,!![]);}catch(_0x2ee4a0){return BPromise[_0xb3cf('0x25')](_0x2ee4a0);}return _0x1dfbc3[_0xb3cf('0x26')]();};}function saveUpdates(_0x33ed8f,_0x1bfe02){return function(_0x4c96fd){if(_0x4c96fd){return _0x4c96fd[_0xb3cf('0x27')](_0x33ed8f)[_0xb3cf('0x28')](function(_0x351196){return _0x351196;});}return null;};}function removeEntity(_0x203ce3,_0x1fb3ea){return function(_0x402d3e){if(_0x402d3e){return _0x402d3e[_0xb3cf('0x29')]()[_0xb3cf('0x28')](function(){_0x203ce3[_0xb3cf('0x1c')](0xcc)[_0xb3cf('0x1d')]();});}};}function handleEntityNotFound(_0x5d939e,_0x89f345){return function(_0x3b8c91){if(!_0x3b8c91){_0x5d939e[_0xb3cf('0x2a')](0x194);}return _0x3b8c91;};}function handleError(_0x4fd689,_0x4cae37){_0x4cae37=_0x4cae37||0x1f4;return function(_0x15cf4d){logger[_0xb3cf('0x2b')](_0x15cf4d['stack']);if(_0x15cf4d['name']){delete _0x15cf4d[_0xb3cf('0x2c')];}_0x4fd689[_0xb3cf('0x1c')](_0x4cae37)['send'](_0x15cf4d);};}exports[_0xb3cf('0x2d')]=function(_0x42b1fc,_0x20c6f5){var _0x376f73={'raw':!![],'where':{'id':_0x42b1fc[_0xb3cf('0x2e')]['id']}},_0x1b1460={};_0x1b1460[_0xb3cf('0x2f')]=_[_0xb3cf('0x30')](db[_0xb3cf('0x31')][_0xb3cf('0x32')]);_0x1b1460['query']=_[_0xb3cf('0x30')](_0x42b1fc['query']);_0x1b1460['filters']=_['intersection'](_0x1b1460[_0xb3cf('0x2f')],_0x1b1460[_0xb3cf('0x33')]);_0x376f73['attributes']=_[_0xb3cf('0x34')](_0x1b1460[_0xb3cf('0x2f')],qs[_0xb3cf('0x35')](_0x42b1fc[_0xb3cf('0x33')][_0xb3cf('0x35')]));_0x376f73[_0xb3cf('0x36')]=_0x376f73['attributes'][_0xb3cf('0x37')]?_0x376f73['attributes']:_0x1b1460[_0xb3cf('0x2f')];if(_0x42b1fc[_0xb3cf('0x33')][_0xb3cf('0x38')]){_0x376f73[_0xb3cf('0x39')]=[{'all':!![]}];}_0x376f73=_[_0xb3cf('0x3a')]({},_0x376f73,_0x42b1fc[_0xb3cf('0x3b')]);return db['ChatApplication']['find'](_0x376f73)[_0xb3cf('0x28')](handleEntityNotFound(_0x20c6f5,null))['then'](respondWithResult(_0x20c6f5,null))['catch'](handleError(_0x20c6f5,null));};exports[_0xb3cf('0x27')]=function(_0x4d7ea4,_0x1c088c){if(_0x4d7ea4[_0xb3cf('0x3c')]['id']){delete _0x4d7ea4[_0xb3cf('0x3c')]['id'];}return db[_0xb3cf('0x31')][_0xb3cf('0x3d')]({'where':{'id':_0x4d7ea4[_0xb3cf('0x2e')]['id']}})['then'](handleEntityNotFound(_0x1c088c,null))[_0xb3cf('0x28')](saveUpdates(_0x4d7ea4[_0xb3cf('0x3c')],null))[_0xb3cf('0x28')](respondWithResult(_0x1c088c,null))[_0xb3cf('0x3e')](handleError(_0x1c088c,null));};exports['destroy']=function(_0x37b5fc,_0x4c3b82){return db[_0xb3cf('0x31')]['find']({'where':{'id':_0x37b5fc[_0xb3cf('0x2e')]['id']}})[_0xb3cf('0x28')](handleEntityNotFound(_0x4c3b82,null))[_0xb3cf('0x28')](removeEntity(_0x4c3b82,null))['catch'](handleError(_0x4c3b82,null));};