81d026dfb7329823bb03a07c8bee2b6a8a006012
[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 _0xfc03=['util','path','sox','to-csv','ejs','fs-extra','lodash','crypto','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','sendStatus','end','status','json','offset','undefined','count','limit','set','Content-Range','apply','reject','save','update','then','destroy','error','stack','name','send','show','params','model','keys','ChatApplication','query','filters','intersection','attributes','fields','length','includeAll','include','merge','options','catch','body','find','eml-format','zip-dir','fast-json-patch','moment','mustache'];(function(_0x193ddf,_0x6f30bb){var _0x5bc6df=function(_0x70fd9e){while(--_0x70fd9e){_0x193ddf['push'](_0x193ddf['shift']());}};_0x5bc6df(++_0x6f30bb);}(_0xfc03,0x16f));var _0x3fc0=function(_0x4ff09b,_0x53f67d){_0x4ff09b=_0x4ff09b-0x0;var _0x3f5c2e=_0xfc03[_0x4ff09b];return _0x3f5c2e;};'use strict';var emlformat=require(_0x3fc0('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x3fc0('0x1'));var jsonpatch=require(_0x3fc0('0x2'));var rp=require('request-promise');var moment=require(_0x3fc0('0x3'));var BPromise=require('bluebird');var Mustache=require(_0x3fc0('0x4'));var util=require(_0x3fc0('0x5'));var path=require(_0x3fc0('0x6'));var sox=require(_0x3fc0('0x7'));var csv=require(_0x3fc0('0x8'));var ejs=require(_0x3fc0('0x9'));var fs=require('fs');var fs_extra=require(_0x3fc0('0xa'));var _=require(_0x3fc0('0xb'));var squel=require('squel');var crypto=require(_0x3fc0('0xc'));var jsforce=require('jsforce');var deskjs=require(_0x3fc0('0xd'));var toCsv=require(_0x3fc0('0x8'));var querystring=require(_0x3fc0('0xe'));var Papa=require(_0x3fc0('0xf'));var Redis=require('ioredis');var authService=require(_0x3fc0('0x10'));var qs=require(_0x3fc0('0x11'));var as=require(_0x3fc0('0x12'));var hardwareService=require(_0x3fc0('0x13'));var logger=require(_0x3fc0('0x14'))('api');var utils=require(_0x3fc0('0x15'));var config=require(_0x3fc0('0x16'));var licenseUtil=require(_0x3fc0('0x17'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x1011b7,_0x582e22){_0x582e22=_0x582e22||0xcc;return function(_0x3a4cc0){if(_0x3a4cc0){return _0x1011b7[_0x3fc0('0x18')](_0x582e22);}return _0x1011b7['status'](_0x582e22)[_0x3fc0('0x19')]();};}function respondWithResult(_0x422926,_0x392c46){_0x392c46=_0x392c46||0xc8;return function(_0x4eb69a){if(_0x4eb69a){return _0x422926[_0x3fc0('0x1a')](_0x392c46)[_0x3fc0('0x1b')](_0x4eb69a);}};}function respondWithFilteredResult(_0x367ce1,_0x27619a){return function(_0x562ecc){if(_0x562ecc){var _0x277dbf=typeof _0x27619a[_0x3fc0('0x1c')]===_0x3fc0('0x1d')&&typeof _0x27619a['limit']===_0x3fc0('0x1d');var _0x491446=_0x562ecc[_0x3fc0('0x1e')];var _0x3c5026=_0x277dbf?0x0:_0x27619a['offset'];var _0x3bb388=_0x277dbf?_0x562ecc[_0x3fc0('0x1e')]:_0x27619a[_0x3fc0('0x1c')]+_0x27619a[_0x3fc0('0x1f')];var _0x1bd575;if(_0x3bb388>=_0x491446){_0x3bb388=_0x491446;_0x1bd575=0xc8;}else{_0x1bd575=0xce;}_0x367ce1[_0x3fc0('0x1a')](_0x1bd575);return _0x367ce1[_0x3fc0('0x20')](_0x3fc0('0x21'),_0x3c5026+'-'+_0x3bb388+'/'+_0x491446)[_0x3fc0('0x1b')](_0x562ecc);}return null;};}function patchUpdates(_0x5c859e){return function(_0xf13744){try{jsonpatch[_0x3fc0('0x22')](_0xf13744,_0x5c859e,!![]);}catch(_0x34ffa7){return BPromise[_0x3fc0('0x23')](_0x34ffa7);}return _0xf13744[_0x3fc0('0x24')]();};}function saveUpdates(_0x448293,_0x47c770){return function(_0x477674){if(_0x477674){return _0x477674[_0x3fc0('0x25')](_0x448293)[_0x3fc0('0x26')](function(_0x28fc65){return _0x28fc65;});}return null;};}function removeEntity(_0x46c213,_0x303dd2){return function(_0x2f423e){if(_0x2f423e){return _0x2f423e[_0x3fc0('0x27')]()[_0x3fc0('0x26')](function(){_0x46c213[_0x3fc0('0x1a')](0xcc)[_0x3fc0('0x19')]();});}};}function handleEntityNotFound(_0x1abe10,_0x784765){return function(_0xba1a23){if(!_0xba1a23){_0x1abe10[_0x3fc0('0x18')](0x194);}return _0xba1a23;};}function handleError(_0xbec5b5,_0x4f5111){_0x4f5111=_0x4f5111||0x1f4;return function(_0x365c8e){logger[_0x3fc0('0x28')](_0x365c8e[_0x3fc0('0x29')]);if(_0x365c8e[_0x3fc0('0x2a')]){delete _0x365c8e['name'];}_0xbec5b5[_0x3fc0('0x1a')](_0x4f5111)[_0x3fc0('0x2b')](_0x365c8e);};}exports[_0x3fc0('0x2c')]=function(_0x2645b4,_0x559fcc){var _0x1e4d99={'raw':!![],'where':{'id':_0x2645b4[_0x3fc0('0x2d')]['id']}},_0x1a2261={};_0x1a2261[_0x3fc0('0x2e')]=_[_0x3fc0('0x2f')](db[_0x3fc0('0x30')]['rawAttributes']);_0x1a2261[_0x3fc0('0x31')]=_[_0x3fc0('0x2f')](_0x2645b4[_0x3fc0('0x31')]);_0x1a2261[_0x3fc0('0x32')]=_[_0x3fc0('0x33')](_0x1a2261[_0x3fc0('0x2e')],_0x1a2261[_0x3fc0('0x31')]);_0x1e4d99[_0x3fc0('0x34')]=_['intersection'](_0x1a2261['model'],qs[_0x3fc0('0x35')](_0x2645b4['query'][_0x3fc0('0x35')]));_0x1e4d99[_0x3fc0('0x34')]=_0x1e4d99[_0x3fc0('0x34')][_0x3fc0('0x36')]?_0x1e4d99[_0x3fc0('0x34')]:_0x1a2261['model'];if(_0x2645b4['query'][_0x3fc0('0x37')]){_0x1e4d99[_0x3fc0('0x38')]=[{'all':!![]}];}_0x1e4d99=_[_0x3fc0('0x39')]({},_0x1e4d99,_0x2645b4[_0x3fc0('0x3a')]);return db[_0x3fc0('0x30')]['find'](_0x1e4d99)[_0x3fc0('0x26')](handleEntityNotFound(_0x559fcc,null))[_0x3fc0('0x26')](respondWithResult(_0x559fcc,null))[_0x3fc0('0x3b')](handleError(_0x559fcc,null));};exports['update']=function(_0x1a39c1,_0x4279c0){if(_0x1a39c1[_0x3fc0('0x3c')]['id']){delete _0x1a39c1[_0x3fc0('0x3c')]['id'];}return db['ChatApplication'][_0x3fc0('0x3d')]({'where':{'id':_0x1a39c1[_0x3fc0('0x2d')]['id']}})['then'](handleEntityNotFound(_0x4279c0,null))[_0x3fc0('0x26')](saveUpdates(_0x1a39c1['body'],null))[_0x3fc0('0x26')](respondWithResult(_0x4279c0,null))[_0x3fc0('0x3b')](handleError(_0x4279c0,null));};exports[_0x3fc0('0x27')]=function(_0x2db02e,_0x302a02){return db[_0x3fc0('0x30')][_0x3fc0('0x3d')]({'where':{'id':_0x2db02e[_0x3fc0('0x2d')]['id']}})[_0x3fc0('0x26')](handleEntityNotFound(_0x302a02,null))[_0x3fc0('0x26')](removeEntity(_0x302a02,null))[_0x3fc0('0x3b')](handleError(_0x302a02,null));};