86fc020a1391a3b0569750e7729e89a5367dbbf4
[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 _0xa423=['squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','sendStatus','status','end','offset','limit','set','json','apply','reject','update','then','destroy','error','stack','name','send','body','Action','find','params','catch','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird','util','path','sox','to-csv','ejs'];(function(_0x1d4f4c,_0x3c3f4a){var _0x4ab87a=function(_0x5598ee){while(--_0x5598ee){_0x1d4f4c['push'](_0x1d4f4c['shift']());}};_0x4ab87a(++_0x3c3f4a);}(_0xa423,0x16c));var _0x3a42=function(_0x349edb,_0x2fc4b1){_0x349edb=_0x349edb-0x0;var _0x517f7e=_0xa423[_0x349edb];return _0x517f7e;};'use strict';var pdf=require(_0x3a42('0x0'));var emlformat=require(_0x3a42('0x1'));var rimraf=require(_0x3a42('0x2'));var zipdir=require(_0x3a42('0x3'));var jsonpatch=require(_0x3a42('0x4'));var rp=require('request-promise');var moment=require(_0x3a42('0x5'));var BPromise=require(_0x3a42('0x6'));var Mustache=require('mustache');var util=require(_0x3a42('0x7'));var path=require(_0x3a42('0x8'));var sox=require(_0x3a42('0x9'));var csv=require(_0x3a42('0xa'));var ejs=require(_0x3a42('0xb'));var fs=require('fs');var _=require('lodash');var squel=require(_0x3a42('0xc'));var crypto=require(_0x3a42('0xd'));var jsforce=require(_0x3a42('0xe'));var deskjs=require(_0x3a42('0xf'));var toCsv=require(_0x3a42('0xa'));var querystring=require(_0x3a42('0x10'));var Papa=require(_0x3a42('0x11'));var Redis=require(_0x3a42('0x12'));var authService=require(_0x3a42('0x13'));var qs=require(_0x3a42('0x14'));var as=require(_0x3a42('0x15'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x3a42('0x16'))(_0x3a42('0x17'));var utils=require(_0x3a42('0x18'));var config=require(_0x3a42('0x19'));var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x11ccc8,_0x4df153){_0x4df153=_0x4df153||0xcc;return function(_0x4008ea){if(_0x4008ea){return _0x11ccc8[_0x3a42('0x1a')](_0x4df153);}return _0x11ccc8[_0x3a42('0x1b')](_0x4df153)[_0x3a42('0x1c')]();};}function respondWithResult(_0x891963,_0x475602){_0x475602=_0x475602||0xc8;return function(_0x5f5244){if(_0x5f5244){return _0x891963[_0x3a42('0x1b')](_0x475602)['json'](_0x5f5244);}};}function respondWithFilteredResult(_0x469c73,_0x4b1d68){return function(_0x3e5d77){if(_0x3e5d77){var _0x5895a8=_0x3e5d77['count'],_0x46ef1e=_0x4b1d68[_0x3a42('0x1d')],_0x4edcf5=_0x4b1d68[_0x3a42('0x1d')]+_0x4b1d68[_0x3a42('0x1e')],_0x486c74;if(_0x4edcf5>=_0x5895a8){_0x4edcf5=_0x5895a8;_0x486c74=0xc8;}else{_0x486c74=0xce;}_0x469c73[_0x3a42('0x1b')](_0x486c74);return _0x469c73[_0x3a42('0x1f')]('Content-Range',_0x46ef1e+'-'+_0x4edcf5+'/'+_0x5895a8)[_0x3a42('0x20')](_0x3e5d77);}return null;};}function patchUpdates(_0x2e5e64){return function(_0x49f00e){try{jsonpatch[_0x3a42('0x21')](_0x49f00e,_0x2e5e64,!![]);}catch(_0xa89087){return BPromise[_0x3a42('0x22')](_0xa89087);}return _0x49f00e['save']();};}function saveUpdates(_0x1fcea4,_0x3f4afb){return function(_0x3bb792){if(_0x3bb792){return _0x3bb792[_0x3a42('0x23')](_0x1fcea4)[_0x3a42('0x24')](function(_0x526d7c){return _0x526d7c;});}return null;};}function removeEntity(_0x34927a,_0x42b40f){return function(_0x379fe6){if(_0x379fe6){return _0x379fe6[_0x3a42('0x25')]()[_0x3a42('0x24')](function(){_0x34927a['status'](0xcc)[_0x3a42('0x1c')]();});}};}function handleEntityNotFound(_0x41b374,_0x477cb9){return function(_0x1add9b){if(!_0x1add9b){_0x41b374[_0x3a42('0x1a')](0x194);}return _0x1add9b;};}function handleError(_0x258917,_0x2ee4b8){_0x2ee4b8=_0x2ee4b8||0x1f4;return function(_0x434044){logger[_0x3a42('0x26')](_0x434044[_0x3a42('0x27')]);if(_0x434044[_0x3a42('0x28')]){delete _0x434044['name'];}_0x258917[_0x3a42('0x1b')](_0x2ee4b8)[_0x3a42('0x29')](_0x434044);};}exports['update']=function(_0x3027dd,_0x5b5897){if(_0x3027dd[_0x3a42('0x2a')]['id']){delete _0x3027dd[_0x3a42('0x2a')]['id'];}return db[_0x3a42('0x2b')][_0x3a42('0x2c')]({'where':{'id':_0x3027dd[_0x3a42('0x2d')]['id']}})[_0x3a42('0x24')](handleEntityNotFound(_0x5b5897,null))['then'](saveUpdates(_0x3027dd[_0x3a42('0x2a')],null))[_0x3a42('0x24')](respondWithResult(_0x5b5897,null))[_0x3a42('0x2e')](handleError(_0x5b5897,null));};exports[_0x3a42('0x25')]=function(_0x1c8fe1,_0x44ef39){return db[_0x3a42('0x2b')]['find']({'where':{'id':_0x1c8fe1[_0x3a42('0x2d')]['id']}})[_0x3a42('0x24')](handleEntityNotFound(_0x44ef39,null))[_0x3a42('0x24')](removeEntity(_0x44ef39,null))[_0x3a42('0x2e')](handleError(_0x44ef39,null));};