2194154182f17af40038c925a20cdbba23115c33
[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 _0x488f=['../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','json','offset','undefined','limit','count','set','reject','save','update','then','destroy','end','error','stack','name','body','Action','params','catch','find','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','util','path','sox','to-csv','ejs','fs-extra','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs'];(function(_0x54c3da,_0x2b8969){var _0x334eb9=function(_0x3bbc52){while(--_0x3bbc52){_0x54c3da['push'](_0x54c3da['shift']());}};_0x334eb9(++_0x2b8969);}(_0x488f,0xe5));var _0xf488=function(_0x242a5b,_0x179409){_0x242a5b=_0x242a5b-0x0;var _0x4e55ae=_0x488f[_0x242a5b];return _0x4e55ae;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xf488('0x0'));var zipdir=require(_0xf488('0x1'));var jsonpatch=require(_0xf488('0x2'));var rp=require(_0xf488('0x3'));var moment=require(_0xf488('0x4'));var BPromise=require('bluebird');var Mustache=require(_0xf488('0x5'));var util=require(_0xf488('0x6'));var path=require(_0xf488('0x7'));var sox=require(_0xf488('0x8'));var csv=require(_0xf488('0x9'));var ejs=require(_0xf488('0xa'));var fs=require('fs');var fs_extra=require(_0xf488('0xb'));var _=require('lodash');var squel=require(_0xf488('0xc'));var crypto=require(_0xf488('0xd'));var jsforce=require(_0xf488('0xe'));var deskjs=require(_0xf488('0xf'));var toCsv=require('to-csv');var querystring=require(_0xf488('0x10'));var Papa=require(_0xf488('0x11'));var Redis=require(_0xf488('0x12'));var authService=require(_0xf488('0x13'));var qs=require(_0xf488('0x14'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xf488('0x15'));var logger=require(_0xf488('0x16'))(_0xf488('0x17'));var utils=require(_0xf488('0x18'));var config=require(_0xf488('0x19'));var licenseUtil=require(_0xf488('0x1a'));var db=require(_0xf488('0x1b'))['db'];function respondWithStatusCode(_0x3148f5,_0x35ccc7){_0x35ccc7=_0x35ccc7||0xcc;return function(_0xea0f3f){if(_0xea0f3f){return _0x3148f5[_0xf488('0x1c')](_0x35ccc7);}return _0x3148f5[_0xf488('0x1d')](_0x35ccc7)['end']();};}function respondWithResult(_0x18ba55,_0x4c24d7){_0x4c24d7=_0x4c24d7||0xc8;return function(_0x2feef4){if(_0x2feef4){return _0x18ba55[_0xf488('0x1d')](_0x4c24d7)[_0xf488('0x1e')](_0x2feef4);}};}function respondWithFilteredResult(_0x26f4f7,_0x4d1676){return function(_0x365d68){if(_0x365d68){var _0x482883=typeof _0x4d1676[_0xf488('0x1f')]===_0xf488('0x20')&&typeof _0x4d1676[_0xf488('0x21')]===_0xf488('0x20');var _0xe7494b=_0x365d68[_0xf488('0x22')];var _0x5bb6e4=_0x482883?0x0:_0x4d1676[_0xf488('0x1f')];var _0x38dc2f=_0x482883?_0x365d68[_0xf488('0x22')]:_0x4d1676['offset']+_0x4d1676[_0xf488('0x21')];var _0x15408f;if(_0x38dc2f>=_0xe7494b){_0x38dc2f=_0xe7494b;_0x15408f=0xc8;}else{_0x15408f=0xce;}_0x26f4f7['status'](_0x15408f);return _0x26f4f7[_0xf488('0x23')]('Content-Range',_0x5bb6e4+'-'+_0x38dc2f+'/'+_0xe7494b)[_0xf488('0x1e')](_0x365d68);}return null;};}function patchUpdates(_0x5ed26a){return function(_0x4b01c9){try{jsonpatch['apply'](_0x4b01c9,_0x5ed26a,!![]);}catch(_0x4bfc66){return BPromise[_0xf488('0x24')](_0x4bfc66);}return _0x4b01c9[_0xf488('0x25')]();};}function saveUpdates(_0xd2bd0c,_0x2e567f){return function(_0x212702){if(_0x212702){return _0x212702[_0xf488('0x26')](_0xd2bd0c)[_0xf488('0x27')](function(_0x49cf36){return _0x49cf36;});}return null;};}function removeEntity(_0x1f5795,_0x4d3447){return function(_0x247263){if(_0x247263){return _0x247263[_0xf488('0x28')]()[_0xf488('0x27')](function(){_0x1f5795[_0xf488('0x1d')](0xcc)[_0xf488('0x29')]();});}};}function handleEntityNotFound(_0xee239c,_0x29bc3c){return function(_0x2e9a2c){if(!_0x2e9a2c){_0xee239c[_0xf488('0x1c')](0x194);}return _0x2e9a2c;};}function handleError(_0x4f2641,_0x1dd034){_0x1dd034=_0x1dd034||0x1f4;return function(_0x4d1944){logger[_0xf488('0x2a')](_0x4d1944[_0xf488('0x2b')]);if(_0x4d1944[_0xf488('0x2c')]){delete _0x4d1944[_0xf488('0x2c')];}_0x4f2641['status'](_0x1dd034)['send'](_0x4d1944);};}exports['update']=function(_0x4efdae,_0x437667){if(_0x4efdae['body']['id']){delete _0x4efdae[_0xf488('0x2d')]['id'];}return db[_0xf488('0x2e')]['find']({'where':{'id':_0x4efdae[_0xf488('0x2f')]['id']}})[_0xf488('0x27')](handleEntityNotFound(_0x437667,null))[_0xf488('0x27')](saveUpdates(_0x4efdae[_0xf488('0x2d')],null))['then'](respondWithResult(_0x437667,null))[_0xf488('0x30')](handleError(_0x437667,null));};exports[_0xf488('0x28')]=function(_0x2f25f0,_0x386580){return db[_0xf488('0x2e')][_0xf488('0x31')]({'where':{'id':_0x2f25f0[_0xf488('0x2f')]['id']}})['then'](handleEntityNotFound(_0x386580,null))[_0xf488('0x27')](removeEntity(_0x386580,null))[_0xf488('0x30')](handleError(_0x386580,null));};