Built motion from commit (unavailable).|2.4.21
[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 _0x5f68=['sox','to-csv','ejs','jsforce','querystring','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','sendStatus','status','json','count','offset','limit','set','Content-Range','apply','reject','destroy','then','end','stack','name','send','update','body','find','params','catch','Action','html-pdf','eml-format','zip-dir','request-promise','bluebird','mustache','util'];(function(_0x145bfe,_0xcfba1){var _0x2c03ca=function(_0x2b5f4c){while(--_0x2b5f4c){_0x145bfe['push'](_0x145bfe['shift']());}};_0x2c03ca(++_0xcfba1);}(_0x5f68,0x189));var _0x85f6=function(_0x422db0,_0x33be5b){_0x422db0=_0x422db0-0x0;var _0x355e09=_0x5f68[_0x422db0];return _0x355e09;};'use strict';var pdf=require(_0x85f6('0x0'));var emlformat=require(_0x85f6('0x1'));var rimraf=require('rimraf');var zipdir=require(_0x85f6('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0x85f6('0x3'));var moment=require('moment');var BPromise=require(_0x85f6('0x4'));var Mustache=require(_0x85f6('0x5'));var util=require(_0x85f6('0x6'));var path=require('path');var sox=require(_0x85f6('0x7'));var csv=require(_0x85f6('0x8'));var ejs=require(_0x85f6('0x9'));var fs=require('fs');var _=require('lodash');var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0x85f6('0xa'));var deskjs=require('desk.js');var toCsv=require(_0x85f6('0x8'));var querystring=require(_0x85f6('0xb'));var Papa=require('papaparse');var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require(_0x85f6('0xc'));var as=require(_0x85f6('0xd'));var hardwareService=require(_0x85f6('0xe'));var logger=require('../../config/logger')(_0x85f6('0xf'));var utils=require(_0x85f6('0x10'));var config=require(_0x85f6('0x11'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x1d743f,_0xbdf8cb){_0xbdf8cb=_0xbdf8cb||0xcc;return function(_0x146c39){if(_0x146c39){return _0x1d743f[_0x85f6('0x12')](_0xbdf8cb);}return _0x1d743f[_0x85f6('0x13')](_0xbdf8cb)['end']();};}function respondWithResult(_0x2b66c2,_0x58e8bb){_0x58e8bb=_0x58e8bb||0xc8;return function(_0x4a0fbd){if(_0x4a0fbd){return _0x2b66c2[_0x85f6('0x13')](_0x58e8bb)[_0x85f6('0x14')](_0x4a0fbd);}};}function respondWithFilteredResult(_0x56c3b1,_0x3c3945){return function(_0x2b4d29){if(_0x2b4d29){var _0x59068d=_0x2b4d29[_0x85f6('0x15')],_0x4e3f0c=_0x3c3945[_0x85f6('0x16')],_0x5a041e=_0x3c3945['offset']+_0x3c3945[_0x85f6('0x17')],_0x1639e6;if(_0x5a041e>=_0x59068d){_0x5a041e=_0x59068d;_0x1639e6=0xc8;}else{_0x1639e6=0xce;}_0x56c3b1[_0x85f6('0x13')](_0x1639e6);return _0x56c3b1[_0x85f6('0x18')](_0x85f6('0x19'),_0x4e3f0c+'-'+_0x5a041e+'/'+_0x59068d)[_0x85f6('0x14')](_0x2b4d29);}return null;};}function patchUpdates(_0x5eb057){return function(_0x5c1c7a){try{jsonpatch[_0x85f6('0x1a')](_0x5c1c7a,_0x5eb057,!![]);}catch(_0x1e1d3c){return BPromise[_0x85f6('0x1b')](_0x1e1d3c);}return _0x5c1c7a['save']();};}function saveUpdates(_0x58abde,_0x3cb6b9){return function(_0x8fe98d){if(_0x8fe98d){return _0x8fe98d['update'](_0x58abde)['then'](function(_0x5b28d8){return _0x5b28d8;});}return null;};}function removeEntity(_0x4a917d,_0x356b73){return function(_0x21f616){if(_0x21f616){return _0x21f616[_0x85f6('0x1c')]()[_0x85f6('0x1d')](function(){_0x4a917d[_0x85f6('0x13')](0xcc)[_0x85f6('0x1e')]();});}};}function handleEntityNotFound(_0x1fb5fb,_0x2dd816){return function(_0x50f87f){if(!_0x50f87f){_0x1fb5fb[_0x85f6('0x12')](0x194);}return _0x50f87f;};}function handleError(_0x199407,_0x5a1bf8){_0x5a1bf8=_0x5a1bf8||0x1f4;return function(_0x481ad0){logger['error'](_0x481ad0[_0x85f6('0x1f')]);if(_0x481ad0[_0x85f6('0x20')]){delete _0x481ad0[_0x85f6('0x20')];}_0x199407[_0x85f6('0x13')](_0x5a1bf8)[_0x85f6('0x21')](_0x481ad0);};}exports[_0x85f6('0x22')]=function(_0x50471f,_0x2bf0d7){if(_0x50471f[_0x85f6('0x23')]['id']){delete _0x50471f[_0x85f6('0x23')]['id'];}return db['Action'][_0x85f6('0x24')]({'where':{'id':_0x50471f[_0x85f6('0x25')]['id']}})[_0x85f6('0x1d')](handleEntityNotFound(_0x2bf0d7,null))[_0x85f6('0x1d')](saveUpdates(_0x50471f[_0x85f6('0x23')],null))[_0x85f6('0x1d')](respondWithResult(_0x2bf0d7,null))[_0x85f6('0x26')](handleError(_0x2bf0d7,null));};exports[_0x85f6('0x1c')]=function(_0x95f606,_0x5cecb4){return db[_0x85f6('0x27')][_0x85f6('0x24')]({'where':{'id':_0x95f606[_0x85f6('0x25')]['id']}})[_0x85f6('0x1d')](handleEntityNotFound(_0x5cecb4,null))[_0x85f6('0x1d')](removeEntity(_0x5cecb4,null))[_0x85f6('0x26')](handleError(_0x5cecb4,null));};