396ca509ce1c2d73cbf447e93dbe2add412fff96
[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 _0xb4ff=['to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','undefined','count','set','apply','reject','save','update','then','destroy','error','stack','name','send','body','Action','find','catch','eml-format','zip-dir','fast-json-patch','bluebird','sox'];(function(_0x31826c,_0x1995c5){var _0x20bbd7=function(_0x2a98ab){while(--_0x2a98ab){_0x31826c['push'](_0x31826c['shift']());}};_0x20bbd7(++_0x1995c5);}(_0xb4ff,0x16b));var _0xfb4f=function(_0x88e11c,_0x2715a5){_0x88e11c=_0x88e11c-0x0;var _0x41ef2f=_0xb4ff[_0x88e11c];return _0x41ef2f;};'use strict';var emlformat=require(_0xfb4f('0x0'));var rimraf=require('rimraf');var zipdir=require(_0xfb4f('0x1'));var jsonpatch=require(_0xfb4f('0x2'));var rp=require('request-promise');var moment=require('moment');var BPromise=require(_0xfb4f('0x3'));var Mustache=require('mustache');var util=require('util');var path=require('path');var sox=require(_0xfb4f('0x4'));var csv=require(_0xfb4f('0x5'));var ejs=require(_0xfb4f('0x6'));var fs=require('fs');var fs_extra=require(_0xfb4f('0x7'));var _=require(_0xfb4f('0x8'));var squel=require(_0xfb4f('0x9'));var crypto=require(_0xfb4f('0xa'));var jsforce=require(_0xfb4f('0xb'));var deskjs=require(_0xfb4f('0xc'));var toCsv=require(_0xfb4f('0x5'));var querystring=require('querystring');var Papa=require(_0xfb4f('0xd'));var Redis=require(_0xfb4f('0xe'));var authService=require(_0xfb4f('0xf'));var qs=require('../../components/parsers/qs');var as=require(_0xfb4f('0x10'));var hardwareService=require(_0xfb4f('0x11'));var logger=require(_0xfb4f('0x12'))(_0xfb4f('0x13'));var utils=require(_0xfb4f('0x14'));var config=require(_0xfb4f('0x15'));var licenseUtil=require(_0xfb4f('0x16'));var db=require(_0xfb4f('0x17'))['db'];function respondWithStatusCode(_0x3b35cc,_0x1529c6){_0x1529c6=_0x1529c6||0xcc;return function(_0x1b0f6d){if(_0x1b0f6d){return _0x3b35cc[_0xfb4f('0x18')](_0x1529c6);}return _0x3b35cc[_0xfb4f('0x19')](_0x1529c6)[_0xfb4f('0x1a')]();};}function respondWithResult(_0x3f39a8,_0xa66c57){_0xa66c57=_0xa66c57||0xc8;return function(_0x279b58){if(_0x279b58){return _0x3f39a8[_0xfb4f('0x19')](_0xa66c57)[_0xfb4f('0x1b')](_0x279b58);}};}function respondWithFilteredResult(_0x266c4f,_0x1eb8be){return function(_0x1ae033){if(_0x1ae033){var _0x68ae65=typeof _0x1eb8be[_0xfb4f('0x1c')]==='undefined'&&typeof _0x1eb8be['limit']===_0xfb4f('0x1d');var _0x5a7922=_0x1ae033[_0xfb4f('0x1e')];var _0x2fb007=_0x68ae65?0x0:_0x1eb8be[_0xfb4f('0x1c')];var _0x37aaa4=_0x68ae65?_0x1ae033[_0xfb4f('0x1e')]:_0x1eb8be['offset']+_0x1eb8be['limit'];var _0x64f1b9;if(_0x37aaa4>=_0x5a7922){_0x37aaa4=_0x5a7922;_0x64f1b9=0xc8;}else{_0x64f1b9=0xce;}_0x266c4f[_0xfb4f('0x19')](_0x64f1b9);return _0x266c4f[_0xfb4f('0x1f')]('Content-Range',_0x2fb007+'-'+_0x37aaa4+'/'+_0x5a7922)[_0xfb4f('0x1b')](_0x1ae033);}return null;};}function patchUpdates(_0x16a68f){return function(_0x2c930b){try{jsonpatch[_0xfb4f('0x20')](_0x2c930b,_0x16a68f,!![]);}catch(_0x1f9235){return BPromise[_0xfb4f('0x21')](_0x1f9235);}return _0x2c930b[_0xfb4f('0x22')]();};}function saveUpdates(_0x3157db,_0x570adb){return function(_0x32d4a4){if(_0x32d4a4){return _0x32d4a4[_0xfb4f('0x23')](_0x3157db)[_0xfb4f('0x24')](function(_0x4be5f6){return _0x4be5f6;});}return null;};}function removeEntity(_0x3ac293,_0x195d64){return function(_0x578b77){if(_0x578b77){return _0x578b77[_0xfb4f('0x25')]()['then'](function(){_0x3ac293[_0xfb4f('0x19')](0xcc)[_0xfb4f('0x1a')]();});}};}function handleEntityNotFound(_0x31933d,_0x4e3b73){return function(_0x21d2b5){if(!_0x21d2b5){_0x31933d[_0xfb4f('0x18')](0x194);}return _0x21d2b5;};}function handleError(_0x3de587,_0x2dc0a6){_0x2dc0a6=_0x2dc0a6||0x1f4;return function(_0x372ef3){logger[_0xfb4f('0x26')](_0x372ef3[_0xfb4f('0x27')]);if(_0x372ef3[_0xfb4f('0x28')]){delete _0x372ef3['name'];}_0x3de587[_0xfb4f('0x19')](_0x2dc0a6)[_0xfb4f('0x29')](_0x372ef3);};}exports[_0xfb4f('0x23')]=function(_0x109ccc,_0x4af6ff){if(_0x109ccc[_0xfb4f('0x2a')]['id']){delete _0x109ccc[_0xfb4f('0x2a')]['id'];}return db[_0xfb4f('0x2b')][_0xfb4f('0x2c')]({'where':{'id':_0x109ccc['params']['id']}})[_0xfb4f('0x24')](handleEntityNotFound(_0x4af6ff,null))[_0xfb4f('0x24')](saveUpdates(_0x109ccc[_0xfb4f('0x2a')],null))[_0xfb4f('0x24')](respondWithResult(_0x4af6ff,null))['catch'](handleError(_0x4af6ff,null));};exports[_0xfb4f('0x25')]=function(_0x2f49a5,_0x18580e){return db[_0xfb4f('0x2b')][_0xfb4f('0x2c')]({'where':{'id':_0x2f49a5['params']['id']}})[_0xfb4f('0x24')](handleEntityNotFound(_0x18580e,null))[_0xfb4f('0x24')](removeEntity(_0x18580e,null))[_0xfb4f('0x2d')](handleError(_0x18580e,null));};