6e8f19eedfbe8df8c5a1ab90ceedd666af5497a3
[motion2.git] / server / api / chatProactiveAction / chatProactiveAction.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 _0x255f=['desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','status','end','json','count','offset','limit','set','apply','reject','save','update','then','destroy','sendStatus','name','show','model','ChatProactiveAction','query','filtears','attributes','intersection','fields','length','includeAll','include','options','find','create','catch','body','params','html-pdf','eml-format','zip-dir','request-promise','bluebird','mustache','util','path','sox','to-csv','crypto','jsforce'];(function(_0x24f31b,_0x44b8f3){var _0x488401=function(_0x204caf){while(--_0x204caf){_0x24f31b['push'](_0x24f31b['shift']());}};_0x488401(++_0x44b8f3);}(_0x255f,0x1b4));var _0xf255=function(_0x1f21bc,_0x4b89b8){_0x1f21bc=_0x1f21bc-0x0;var _0x115182=_0x255f[_0x1f21bc];return _0x115182;};'use strict';var pdf=require(_0xf255('0x0'));var emlformat=require(_0xf255('0x1'));var rimraf=require('rimraf');var zipdir=require(_0xf255('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0xf255('0x3'));var moment=require('moment');var BPromise=require(_0xf255('0x4'));var Mustache=require(_0xf255('0x5'));var util=require(_0xf255('0x6'));var path=require(_0xf255('0x7'));var sox=require(_0xf255('0x8'));var csv=require(_0xf255('0x9'));var ejs=require('ejs');var fs=require('fs');var _=require('lodash');var squel=require('squel');var crypto=require(_0xf255('0xa'));var jsforce=require(_0xf255('0xb'));var deskjs=require(_0xf255('0xc'));var toCsv=require(_0xf255('0x9'));var querystring=require(_0xf255('0xd'));var Papa=require(_0xf255('0xe'));var Redis=require('ioredis');var authService=require(_0xf255('0xf'));var qs=require(_0xf255('0x10'));var as=require(_0xf255('0x11'));var hardwareService=require(_0xf255('0x12'));var logger=require(_0xf255('0x13'))(_0xf255('0x14'));var utils=require('../../config/utils');var config=require(_0xf255('0x15'));var licenseUtil=require(_0xf255('0x16'));var db=require(_0xf255('0x17'))['db'];function respondWithStatusCode(_0x201be7,_0x3a61c2){_0x3a61c2=_0x3a61c2||0xcc;return function(_0x462cfb){if(_0x462cfb){return _0x201be7['sendStatus'](_0x3a61c2);}return _0x201be7[_0xf255('0x18')](_0x3a61c2)[_0xf255('0x19')]();};}function respondWithResult(_0x1386ab,_0x5ea7c5){_0x5ea7c5=_0x5ea7c5||0xc8;return function(_0x393bdc){if(_0x393bdc){return _0x1386ab[_0xf255('0x18')](_0x5ea7c5)[_0xf255('0x1a')](_0x393bdc);}};}function respondWithFilteredResult(_0x48b6d4,_0x4257f2){return function(_0xcee0d9){if(_0xcee0d9){var _0x3f061f=_0xcee0d9[_0xf255('0x1b')],_0x4dc136=_0x4257f2[_0xf255('0x1c')],_0x3aa176=_0x4257f2[_0xf255('0x1c')]+_0x4257f2[_0xf255('0x1d')],_0x37f1e4;if(_0x3aa176>=_0x3f061f){_0x3aa176=_0x3f061f;_0x37f1e4=0xc8;}else{_0x37f1e4=0xce;}_0x48b6d4[_0xf255('0x18')](_0x37f1e4);return _0x48b6d4[_0xf255('0x1e')]('Content-Range',_0x4dc136+'-'+_0x3aa176+'/'+_0x3f061f)[_0xf255('0x1a')](_0xcee0d9);}return null;};}function patchUpdates(_0x1a8a1d){return function(_0x489a26){try{jsonpatch[_0xf255('0x1f')](_0x489a26,_0x1a8a1d,!![]);}catch(_0x1c56ef){return BPromise[_0xf255('0x20')](_0x1c56ef);}return _0x489a26[_0xf255('0x21')]();};}function saveUpdates(_0x1efd74,_0x1da246){return function(_0x1d38ef){if(_0x1d38ef){return _0x1d38ef[_0xf255('0x22')](_0x1efd74)[_0xf255('0x23')](function(_0x72c21c){return _0x72c21c;});}return null;};}function removeEntity(_0x3ad4ba,_0x56b073){return function(_0x3de88f){if(_0x3de88f){return _0x3de88f[_0xf255('0x24')]()[_0xf255('0x23')](function(){_0x3ad4ba[_0xf255('0x18')](0xcc)[_0xf255('0x19')]();});}};}function handleEntityNotFound(_0x5a0af2,_0x176a47){return function(_0x2c1645){if(!_0x2c1645){_0x5a0af2[_0xf255('0x25')](0x194);}return _0x2c1645;};}function handleError(_0x331d1c,_0x16bacb){_0x16bacb=_0x16bacb||0x1f4;return function(_0x78e251){logger['error'](_0x78e251['stack']);if(_0x78e251[_0xf255('0x26')]){delete _0x78e251[_0xf255('0x26')];}_0x331d1c[_0xf255('0x18')](_0x16bacb)['send'](_0x78e251);};}exports[_0xf255('0x27')]=function(_0x55516e,_0x95128d){var _0x3073f2={'raw':!![],'where':{'id':_0x55516e['params']['id']}},_0x4fbf5a={};_0x4fbf5a[_0xf255('0x28')]=_['keys'](db[_0xf255('0x29')]['rawAttributes']);_0x4fbf5a['query']=_['keys'](_0x55516e[_0xf255('0x2a')]);_0x4fbf5a[_0xf255('0x2b')]=_['intersection'](_0x4fbf5a[_0xf255('0x28')],_0x4fbf5a[_0xf255('0x2a')]);_0x3073f2[_0xf255('0x2c')]=_[_0xf255('0x2d')](_0x4fbf5a[_0xf255('0x28')],qs[_0xf255('0x2e')](_0x55516e[_0xf255('0x2a')][_0xf255('0x2e')]));_0x3073f2['attributes']=_0x3073f2[_0xf255('0x2c')][_0xf255('0x2f')]?_0x3073f2['attributes']:_0x4fbf5a[_0xf255('0x28')];if(_0x55516e[_0xf255('0x2a')][_0xf255('0x30')]){_0x3073f2[_0xf255('0x31')]=[{'all':!![]}];}_0x3073f2=_['merge']({},_0x3073f2,_0x55516e[_0xf255('0x32')]);return db[_0xf255('0x29')][_0xf255('0x33')](_0x3073f2)[_0xf255('0x23')](handleEntityNotFound(_0x95128d,null))[_0xf255('0x23')](respondWithResult(_0x95128d,null))['catch'](handleError(_0x95128d,null));};exports['create']=function(_0xe14cd6,_0x368475){return db[_0xf255('0x29')][_0xf255('0x34')](_0xe14cd6['body'],{})[_0xf255('0x23')](respondWithResult(_0x368475,0xc9))[_0xf255('0x35')](handleError(_0x368475,null));};exports['update']=function(_0x5c652f,_0x1e5c72){if(_0x5c652f[_0xf255('0x36')]['id']){delete _0x5c652f[_0xf255('0x36')]['id'];}return db['ChatProactiveAction']['find']({'where':{'id':_0x5c652f[_0xf255('0x37')]['id']}})[_0xf255('0x23')](handleEntityNotFound(_0x1e5c72,null))[_0xf255('0x23')](saveUpdates(_0x5c652f[_0xf255('0x36')],null))[_0xf255('0x23')](respondWithResult(_0x1e5c72,null))['catch'](handleError(_0x1e5c72,null));};exports['destroy']=function(_0xf3b394,_0x189d8e){return db[_0xf255('0x29')][_0xf255('0x33')]({'where':{'id':_0xf3b394[_0xf255('0x37')]['id']}})['then'](handleEntityNotFound(_0x189d8e,null))[_0xf255('0x23')](removeEntity(_0x189d8e,null))[_0xf255('0x35')](handleError(_0x189d8e,null));};