Built motion from commit ddca4d0d.|2.5.47
[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 _0x19f6=['send','update','body','Action','find','params','catch','eml-format','rimraf','zip-dir','moment','mustache','util','path','to-csv','ejs','lodash','squel','jsforce','desk.js','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','limit','count','set','Content-Range','reject','save','then','destroy','error','stack','name'];(function(_0x48cfc5,_0x1eb2cb){var _0x183b40=function(_0x22a159){while(--_0x22a159){_0x48cfc5['push'](_0x48cfc5['shift']());}};_0x183b40(++_0x1eb2cb);}(_0x19f6,0x17f));var _0x619f=function(_0x47c75a,_0x447086){_0x47c75a=_0x47c75a-0x0;var _0x1e6f62=_0x19f6[_0x47c75a];return _0x1e6f62;};'use strict';var emlformat=require(_0x619f('0x0'));var rimraf=require(_0x619f('0x1'));var zipdir=require(_0x619f('0x2'));var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require(_0x619f('0x3'));var BPromise=require('bluebird');var Mustache=require(_0x619f('0x4'));var util=require(_0x619f('0x5'));var path=require(_0x619f('0x6'));var sox=require('sox');var csv=require(_0x619f('0x7'));var ejs=require(_0x619f('0x8'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x619f('0x9'));var squel=require(_0x619f('0xa'));var crypto=require('crypto');var jsforce=require(_0x619f('0xb'));var deskjs=require(_0x619f('0xc'));var toCsv=require(_0x619f('0x7'));var querystring=require(_0x619f('0xd'));var Papa=require(_0x619f('0xe'));var Redis=require(_0x619f('0xf'));var authService=require('../../components/auth/service');var qs=require(_0x619f('0x10'));var as=require(_0x619f('0x11'));var hardwareService=require(_0x619f('0x12'));var logger=require('../../config/logger')(_0x619f('0x13'));var utils=require(_0x619f('0x14'));var config=require(_0x619f('0x15'));var licenseUtil=require(_0x619f('0x16'));var db=require(_0x619f('0x17'))['db'];function respondWithStatusCode(_0x3e9ff3,_0x29a1cd){_0x29a1cd=_0x29a1cd||0xcc;return function(_0x18296d){if(_0x18296d){return _0x3e9ff3[_0x619f('0x18')](_0x29a1cd);}return _0x3e9ff3[_0x619f('0x19')](_0x29a1cd)[_0x619f('0x1a')]();};}function respondWithResult(_0xa93452,_0x29f2d4){_0x29f2d4=_0x29f2d4||0xc8;return function(_0x36f36b){if(_0x36f36b){return _0xa93452[_0x619f('0x19')](_0x29f2d4)[_0x619f('0x1b')](_0x36f36b);}};}function respondWithFilteredResult(_0x3c30b9,_0x13bb63){return function(_0x22706f){if(_0x22706f){var _0x31d452=typeof _0x13bb63[_0x619f('0x1c')]==='undefined'&&typeof _0x13bb63[_0x619f('0x1d')]==='undefined';var _0x5c8ff1=_0x22706f[_0x619f('0x1e')];var _0x980254=_0x31d452?0x0:_0x13bb63[_0x619f('0x1c')];var _0x2705c8=_0x31d452?_0x22706f[_0x619f('0x1e')]:_0x13bb63[_0x619f('0x1c')]+_0x13bb63[_0x619f('0x1d')];var _0x1b3894;if(_0x2705c8>=_0x5c8ff1){_0x2705c8=_0x5c8ff1;_0x1b3894=0xc8;}else{_0x1b3894=0xce;}_0x3c30b9['status'](_0x1b3894);return _0x3c30b9[_0x619f('0x1f')](_0x619f('0x20'),_0x980254+'-'+_0x2705c8+'/'+_0x5c8ff1)['json'](_0x22706f);}return null;};}function patchUpdates(_0x3ae043){return function(_0x3a043e){try{jsonpatch['apply'](_0x3a043e,_0x3ae043,!![]);}catch(_0x17c0b9){return BPromise[_0x619f('0x21')](_0x17c0b9);}return _0x3a043e[_0x619f('0x22')]();};}function saveUpdates(_0x1efa47,_0x1bd711){return function(_0x29a2d6){if(_0x29a2d6){return _0x29a2d6['update'](_0x1efa47)[_0x619f('0x23')](function(_0x1483fb){return _0x1483fb;});}return null;};}function removeEntity(_0x53ee41,_0x5c195d){return function(_0x1f414d){if(_0x1f414d){return _0x1f414d[_0x619f('0x24')]()[_0x619f('0x23')](function(){_0x53ee41[_0x619f('0x19')](0xcc)[_0x619f('0x1a')]();});}};}function handleEntityNotFound(_0x45aac3,_0x5cc5e6){return function(_0x43e291){if(!_0x43e291){_0x45aac3['sendStatus'](0x194);}return _0x43e291;};}function handleError(_0x2e9722,_0x377ce4){_0x377ce4=_0x377ce4||0x1f4;return function(_0xbdfdbc){logger[_0x619f('0x25')](_0xbdfdbc[_0x619f('0x26')]);if(_0xbdfdbc[_0x619f('0x27')]){delete _0xbdfdbc['name'];}_0x2e9722[_0x619f('0x19')](_0x377ce4)[_0x619f('0x28')](_0xbdfdbc);};}exports[_0x619f('0x29')]=function(_0x2cdcc8,_0x148adc){if(_0x2cdcc8[_0x619f('0x2a')]['id']){delete _0x2cdcc8[_0x619f('0x2a')]['id'];}return db[_0x619f('0x2b')][_0x619f('0x2c')]({'where':{'id':_0x2cdcc8[_0x619f('0x2d')]['id']}})[_0x619f('0x23')](handleEntityNotFound(_0x148adc,null))['then'](saveUpdates(_0x2cdcc8['body'],null))['then'](respondWithResult(_0x148adc,null))[_0x619f('0x2e')](handleError(_0x148adc,null));};exports[_0x619f('0x24')]=function(_0x3a749a,_0x587012){return db[_0x619f('0x2b')][_0x619f('0x2c')]({'where':{'id':_0x3a749a[_0x619f('0x2d')]['id']}})[_0x619f('0x23')](handleEntityNotFound(_0x587012,null))[_0x619f('0x23')](removeEntity(_0x587012,null))['catch'](handleError(_0x587012,null));};