6d56c7fb0ab9629b5307459ebe441f472af95d2c
[motion2.git] / server / api / action / action.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 _0xc0fb=['undefined','limit','count','set','Content-Range','apply','reject','update','then','destroy','error','stack','name','send','body','Action','find','params','catch','zip-dir','request-promise','moment','bluebird','mustache','util','path','to-csv','ejs','fs-extra','lodash','squel','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','sendStatus','status','end','json','offset'];(function(_0x4b7895,_0x3c4f5d){var _0x264180=function(_0xe0e861){while(--_0xe0e861){_0x4b7895['push'](_0x4b7895['shift']());}};_0x264180(++_0x3c4f5d);}(_0xc0fb,0x19b));var _0xbc0f=function(_0x50b984,_0x2f44cb){_0x50b984=_0x50b984-0x0;var _0x4301b6=_0xc0fb[_0x50b984];return _0x4301b6;};'use strict';var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require(_0xbc0f('0x0'));var jsonpatch=require('fast-json-patch');var rp=require(_0xbc0f('0x1'));var moment=require(_0xbc0f('0x2'));var BPromise=require(_0xbc0f('0x3'));var Mustache=require(_0xbc0f('0x4'));var util=require(_0xbc0f('0x5'));var path=require(_0xbc0f('0x6'));var sox=require('sox');var csv=require(_0xbc0f('0x7'));var ejs=require(_0xbc0f('0x8'));var fs=require('fs');var fs_extra=require(_0xbc0f('0x9'));var _=require(_0xbc0f('0xa'));var squel=require(_0xbc0f('0xb'));var crypto=require('crypto');var jsforce=require(_0xbc0f('0xc'));var deskjs=require(_0xbc0f('0xd'));var toCsv=require(_0xbc0f('0x7'));var querystring=require(_0xbc0f('0xe'));var Papa=require(_0xbc0f('0xf'));var Redis=require(_0xbc0f('0x10'));var authService=require(_0xbc0f('0x11'));var qs=require('../../components/parsers/qs');var as=require(_0xbc0f('0x12'));var hardwareService=require(_0xbc0f('0x13'));var logger=require(_0xbc0f('0x14'))(_0xbc0f('0x15'));var utils=require(_0xbc0f('0x16'));var config=require(_0xbc0f('0x17'));var licenseUtil=require(_0xbc0f('0x18'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x515add,_0x183f35){_0x183f35=_0x183f35||0xcc;return function(_0x19bbd6){if(_0x19bbd6){return _0x515add[_0xbc0f('0x19')](_0x183f35);}return _0x515add[_0xbc0f('0x1a')](_0x183f35)[_0xbc0f('0x1b')]();};}function respondWithResult(_0x3470c0,_0x1af5eb){_0x1af5eb=_0x1af5eb||0xc8;return function(_0x1da83a){if(_0x1da83a){return _0x3470c0[_0xbc0f('0x1a')](_0x1af5eb)[_0xbc0f('0x1c')](_0x1da83a);}};}function respondWithFilteredResult(_0x28e4b4,_0x3862c4){return function(_0x46d0e1){if(_0x46d0e1){var _0x2fbfb9=typeof _0x3862c4[_0xbc0f('0x1d')]===_0xbc0f('0x1e')&&typeof _0x3862c4[_0xbc0f('0x1f')]===_0xbc0f('0x1e');var _0x85acfa=_0x46d0e1[_0xbc0f('0x20')];var _0xf65ee2=_0x2fbfb9?0x0:_0x3862c4[_0xbc0f('0x1d')];var _0x2f04ea=_0x2fbfb9?_0x46d0e1[_0xbc0f('0x20')]:_0x3862c4[_0xbc0f('0x1d')]+_0x3862c4[_0xbc0f('0x1f')];var _0x573f21;if(_0x2f04ea>=_0x85acfa){_0x2f04ea=_0x85acfa;_0x573f21=0xc8;}else{_0x573f21=0xce;}_0x28e4b4['status'](_0x573f21);return _0x28e4b4[_0xbc0f('0x21')](_0xbc0f('0x22'),_0xf65ee2+'-'+_0x2f04ea+'/'+_0x85acfa)['json'](_0x46d0e1);}return null;};}function patchUpdates(_0x554da9){return function(_0x2fa51c){try{jsonpatch[_0xbc0f('0x23')](_0x2fa51c,_0x554da9,!![]);}catch(_0x30ecf0){return BPromise[_0xbc0f('0x24')](_0x30ecf0);}return _0x2fa51c['save']();};}function saveUpdates(_0x2071e1,_0x419462){return function(_0x4f143f){if(_0x4f143f){return _0x4f143f[_0xbc0f('0x25')](_0x2071e1)[_0xbc0f('0x26')](function(_0x2302e3){return _0x2302e3;});}return null;};}function removeEntity(_0x5bade2,_0x508ba3){return function(_0x59db00){if(_0x59db00){return _0x59db00[_0xbc0f('0x27')]()['then'](function(){_0x5bade2[_0xbc0f('0x1a')](0xcc)['end']();});}};}function handleEntityNotFound(_0x18f23f,_0x5b37cd){return function(_0x47b2fb){if(!_0x47b2fb){_0x18f23f['sendStatus'](0x194);}return _0x47b2fb;};}function handleError(_0x444834,_0xb868dd){_0xb868dd=_0xb868dd||0x1f4;return function(_0x315a66){logger[_0xbc0f('0x28')](_0x315a66[_0xbc0f('0x29')]);if(_0x315a66['name']){delete _0x315a66[_0xbc0f('0x2a')];}_0x444834[_0xbc0f('0x1a')](_0xb868dd)[_0xbc0f('0x2b')](_0x315a66);};}exports[_0xbc0f('0x25')]=function(_0x3575c7,_0x5bbd9e){if(_0x3575c7[_0xbc0f('0x2c')]['id']){delete _0x3575c7[_0xbc0f('0x2c')]['id'];}return db[_0xbc0f('0x2d')][_0xbc0f('0x2e')]({'where':{'id':_0x3575c7[_0xbc0f('0x2f')]['id']}})['then'](handleEntityNotFound(_0x5bbd9e,null))['then'](saveUpdates(_0x3575c7[_0xbc0f('0x2c')],null))[_0xbc0f('0x26')](respondWithResult(_0x5bbd9e,null))[_0xbc0f('0x30')](handleError(_0x5bbd9e,null));};exports['destroy']=function(_0x38921e,_0x35f301){return db[_0xbc0f('0x2d')][_0xbc0f('0x2e')]({'where':{'id':_0x38921e['params']['id']}})[_0xbc0f('0x26')](handleEntityNotFound(_0x35f301,null))[_0xbc0f('0x26')](removeEntity(_0x35f301,null))[_0xbc0f('0x30')](handleError(_0x35f301,null));};