3f8072ad2a0e9b910afc2a170fb3658c48a43e28
[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 _0x6f44=['papaparse','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','end','status','json','set','apply','reject','save','update','destroy','then','error','stack','name','send','body','catch','Action','find','params','html-pdf','eml-format','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','ejs','lodash','squel','desk.js','to-csv'];(function(_0xe98b79,_0x1c8984){var _0x222bf3=function(_0x1c480e){while(--_0x1c480e){_0xe98b79['push'](_0xe98b79['shift']());}};_0x222bf3(++_0x1c8984);}(_0x6f44,0x1ea));var _0x46f4=function(_0x121d86,_0x2b6e20){_0x121d86=_0x121d86-0x0;var _0x372b7c=_0x6f44[_0x121d86];return _0x372b7c;};'use strict';var pdf=require(_0x46f4('0x0'));var emlformat=require(_0x46f4('0x1'));var rimraf=require('rimraf');var zipdir=require(_0x46f4('0x2'));var jsonpatch=require(_0x46f4('0x3'));var rp=require(_0x46f4('0x4'));var moment=require(_0x46f4('0x5'));var BPromise=require(_0x46f4('0x6'));var Mustache=require(_0x46f4('0x7'));var util=require(_0x46f4('0x8'));var path=require(_0x46f4('0x9'));var sox=require(_0x46f4('0xa'));var csv=require('to-csv');var ejs=require(_0x46f4('0xb'));var fs=require('fs');var _=require(_0x46f4('0xc'));var squel=require(_0x46f4('0xd'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0x46f4('0xe'));var toCsv=require(_0x46f4('0xf'));var querystring=require('querystring');var Papa=require(_0x46f4('0x10'));var Redis=require('ioredis');var authService=require(_0x46f4('0x11'));var qs=require('../../components/parsers/qs');var as=require(_0x46f4('0x12'));var hardwareService=require(_0x46f4('0x13'));var logger=require(_0x46f4('0x14'))(_0x46f4('0x15'));var utils=require(_0x46f4('0x16'));var config=require(_0x46f4('0x17'));var licenseUtil=require(_0x46f4('0x18'));var db=require(_0x46f4('0x19'))['db'];function respondWithStatusCode(_0x21d4a6,_0x1f4748){_0x1f4748=_0x1f4748||0xcc;return function(_0x1dd233){if(_0x1dd233){return _0x21d4a6[_0x46f4('0x1a')](_0x1f4748);}return _0x21d4a6['status'](_0x1f4748)[_0x46f4('0x1b')]();};}function respondWithResult(_0x33f73c,_0x52db86){_0x52db86=_0x52db86||0xc8;return function(_0x44a55b){if(_0x44a55b){return _0x33f73c[_0x46f4('0x1c')](_0x52db86)[_0x46f4('0x1d')](_0x44a55b);}};}function respondWithFilteredResult(_0x4dd2fb,_0x3dc516){return function(_0x4e0661){if(_0x4e0661){var _0x4e84ce=_0x4e0661['count'],_0x45917e=_0x3dc516['offset'],_0xf082a9=_0x3dc516['offset']+_0x3dc516['limit'],_0x39f902;if(_0xf082a9>=_0x4e84ce){_0xf082a9=_0x4e84ce;_0x39f902=0xc8;}else{_0x39f902=0xce;}_0x4dd2fb[_0x46f4('0x1c')](_0x39f902);return _0x4dd2fb[_0x46f4('0x1e')]('Content-Range',_0x45917e+'-'+_0xf082a9+'/'+_0x4e84ce)[_0x46f4('0x1d')](_0x4e0661);}return null;};}function patchUpdates(_0x108e6d){return function(_0x2232d6){try{jsonpatch[_0x46f4('0x1f')](_0x2232d6,_0x108e6d,!![]);}catch(_0x4b0650){return BPromise[_0x46f4('0x20')](_0x4b0650);}return _0x2232d6[_0x46f4('0x21')]();};}function saveUpdates(_0x1627db,_0x6476f0){return function(_0x42b0ca){if(_0x42b0ca){return _0x42b0ca[_0x46f4('0x22')](_0x1627db)['then'](function(_0x4bae60){return _0x4bae60;});}return null;};}function removeEntity(_0x2b88d3,_0x39760b){return function(_0x4ba21a){if(_0x4ba21a){return _0x4ba21a[_0x46f4('0x23')]()[_0x46f4('0x24')](function(){_0x2b88d3[_0x46f4('0x1c')](0xcc)[_0x46f4('0x1b')]();});}};}function handleEntityNotFound(_0x36092e,_0x41be5e){return function(_0x204db6){if(!_0x204db6){_0x36092e[_0x46f4('0x1a')](0x194);}return _0x204db6;};}function handleError(_0x39eb2f,_0x301e24){_0x301e24=_0x301e24||0x1f4;return function(_0x2ad553){logger[_0x46f4('0x25')](_0x2ad553[_0x46f4('0x26')]);if(_0x2ad553['name']){delete _0x2ad553[_0x46f4('0x27')];}_0x39eb2f[_0x46f4('0x1c')](_0x301e24)[_0x46f4('0x28')](_0x2ad553);};}exports[_0x46f4('0x22')]=function(_0x57eb00,_0x33a7c5){if(_0x57eb00['body']['id']){delete _0x57eb00[_0x46f4('0x29')]['id'];}return db['Action']['find']({'where':{'id':_0x57eb00['params']['id']}})[_0x46f4('0x24')](handleEntityNotFound(_0x33a7c5,null))['then'](saveUpdates(_0x57eb00[_0x46f4('0x29')],null))[_0x46f4('0x24')](respondWithResult(_0x33a7c5,null))[_0x46f4('0x2a')](handleError(_0x33a7c5,null));};exports[_0x46f4('0x23')]=function(_0x375da1,_0x57464c){return db[_0x46f4('0x2b')][_0x46f4('0x2c')]({'where':{'id':_0x375da1[_0x46f4('0x2d')]['id']}})['then'](handleEntityNotFound(_0x57464c,null))[_0x46f4('0x24')](removeEntity(_0x57464c,null))[_0x46f4('0x2a')](handleError(_0x57464c,null));};