53d188684b5f0b0b126e0abe6dbc1c9f2d9a4485
[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 _0xff16=['catch','eml-format','rimraf','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','ejs','lodash','squel','crypto','jsforce','desk.js','to-csv','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','status','end','json','offset','limit','undefined','count','set','apply','reject','save','then','destroy','stack','name','send','model','keys','ChatProactiveAction','rawAttributes','query','filters','intersection','fields','attributes','includeAll','include','merge','options','find','create','body','params'];(function(_0x5f21e5,_0x3832a7){var _0x16533a=function(_0x3d7947){while(--_0x3d7947){_0x5f21e5['push'](_0x5f21e5['shift']());}};_0x16533a(++_0x3832a7);}(_0xff16,0x7f));var _0x6ff1=function(_0x25d18b,_0x5c7657){_0x25d18b=_0x25d18b-0x0;var _0x4fec49=_0xff16[_0x25d18b];return _0x4fec49;};'use strict';var emlformat=require(_0x6ff1('0x0'));var rimraf=require(_0x6ff1('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x6ff1('0x2'));var rp=require(_0x6ff1('0x3'));var moment=require(_0x6ff1('0x4'));var BPromise=require(_0x6ff1('0x5'));var Mustache=require(_0x6ff1('0x6'));var util=require(_0x6ff1('0x7'));var path=require(_0x6ff1('0x8'));var sox=require(_0x6ff1('0x9'));var csv=require('to-csv');var ejs=require(_0x6ff1('0xa'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x6ff1('0xb'));var squel=require(_0x6ff1('0xc'));var crypto=require(_0x6ff1('0xd'));var jsforce=require(_0x6ff1('0xe'));var deskjs=require(_0x6ff1('0xf'));var toCsv=require(_0x6ff1('0x10'));var querystring=require(_0x6ff1('0x11'));var Papa=require(_0x6ff1('0x12'));var Redis=require('ioredis');var authService=require(_0x6ff1('0x13'));var qs=require(_0x6ff1('0x14'));var as=require(_0x6ff1('0x15'));var hardwareService=require(_0x6ff1('0x16'));var logger=require(_0x6ff1('0x17'))(_0x6ff1('0x18'));var utils=require(_0x6ff1('0x19'));var config=require(_0x6ff1('0x1a'));var licenseUtil=require(_0x6ff1('0x1b'));var db=require(_0x6ff1('0x1c'))['db'];function respondWithStatusCode(_0x4e8484,_0x5cf649){_0x5cf649=_0x5cf649||0xcc;return function(_0x5dacd6){if(_0x5dacd6){return _0x4e8484['sendStatus'](_0x5cf649);}return _0x4e8484[_0x6ff1('0x1d')](_0x5cf649)[_0x6ff1('0x1e')]();};}function respondWithResult(_0x1451af,_0x543e07){_0x543e07=_0x543e07||0xc8;return function(_0x58952d){if(_0x58952d){return _0x1451af['status'](_0x543e07)[_0x6ff1('0x1f')](_0x58952d);}};}function respondWithFilteredResult(_0x1ec8e9,_0x23112d){return function(_0x29e6c7){if(_0x29e6c7){var _0x36fa15=typeof _0x23112d[_0x6ff1('0x20')]==='undefined'&&typeof _0x23112d[_0x6ff1('0x21')]===_0x6ff1('0x22');var _0x4751b9=_0x29e6c7[_0x6ff1('0x23')];var _0xe5d26e=_0x36fa15?0x0:_0x23112d[_0x6ff1('0x20')];var _0x5041d7=_0x36fa15?_0x29e6c7[_0x6ff1('0x23')]:_0x23112d[_0x6ff1('0x20')]+_0x23112d[_0x6ff1('0x21')];var _0x256457;if(_0x5041d7>=_0x4751b9){_0x5041d7=_0x4751b9;_0x256457=0xc8;}else{_0x256457=0xce;}_0x1ec8e9[_0x6ff1('0x1d')](_0x256457);return _0x1ec8e9[_0x6ff1('0x24')]('Content-Range',_0xe5d26e+'-'+_0x5041d7+'/'+_0x4751b9)[_0x6ff1('0x1f')](_0x29e6c7);}return null;};}function patchUpdates(_0x54c961){return function(_0x328325){try{jsonpatch[_0x6ff1('0x25')](_0x328325,_0x54c961,!![]);}catch(_0x2d3131){return BPromise[_0x6ff1('0x26')](_0x2d3131);}return _0x328325[_0x6ff1('0x27')]();};}function saveUpdates(_0x47fd1f,_0x56027f){return function(_0x561bcd){if(_0x561bcd){return _0x561bcd['update'](_0x47fd1f)[_0x6ff1('0x28')](function(_0xbdd73e){return _0xbdd73e;});}return null;};}function removeEntity(_0x4b3d22,_0x41b160){return function(_0x1ec4f1){if(_0x1ec4f1){return _0x1ec4f1[_0x6ff1('0x29')]()[_0x6ff1('0x28')](function(){_0x4b3d22[_0x6ff1('0x1d')](0xcc)['end']();});}};}function handleEntityNotFound(_0x13acb3,_0x324645){return function(_0x13ff47){if(!_0x13ff47){_0x13acb3['sendStatus'](0x194);}return _0x13ff47;};}function handleError(_0x512759,_0x17036d){_0x17036d=_0x17036d||0x1f4;return function(_0x2705d4){logger['error'](_0x2705d4[_0x6ff1('0x2a')]);if(_0x2705d4[_0x6ff1('0x2b')]){delete _0x2705d4['name'];}_0x512759[_0x6ff1('0x1d')](_0x17036d)[_0x6ff1('0x2c')](_0x2705d4);};}exports['show']=function(_0x3cc69e,_0x3597c6){var _0x2f7006={'raw':!![],'where':{'id':_0x3cc69e['params']['id']}},_0x193c09={};_0x193c09[_0x6ff1('0x2d')]=_[_0x6ff1('0x2e')](db[_0x6ff1('0x2f')][_0x6ff1('0x30')]);_0x193c09[_0x6ff1('0x31')]=_['keys'](_0x3cc69e[_0x6ff1('0x31')]);_0x193c09[_0x6ff1('0x32')]=_[_0x6ff1('0x33')](_0x193c09['model'],_0x193c09[_0x6ff1('0x31')]);_0x2f7006['attributes']=_[_0x6ff1('0x33')](_0x193c09[_0x6ff1('0x2d')],qs[_0x6ff1('0x34')](_0x3cc69e[_0x6ff1('0x31')][_0x6ff1('0x34')]));_0x2f7006[_0x6ff1('0x35')]=_0x2f7006[_0x6ff1('0x35')]['length']?_0x2f7006['attributes']:_0x193c09[_0x6ff1('0x2d')];if(_0x3cc69e[_0x6ff1('0x31')][_0x6ff1('0x36')]){_0x2f7006[_0x6ff1('0x37')]=[{'all':!![]}];}_0x2f7006=_[_0x6ff1('0x38')]({},_0x2f7006,_0x3cc69e[_0x6ff1('0x39')]);return db['ChatProactiveAction'][_0x6ff1('0x3a')](_0x2f7006)[_0x6ff1('0x28')](handleEntityNotFound(_0x3597c6,null))[_0x6ff1('0x28')](respondWithResult(_0x3597c6,null))['catch'](handleError(_0x3597c6,null));};exports[_0x6ff1('0x3b')]=function(_0x48e7d9,_0x12affb){return db['ChatProactiveAction'][_0x6ff1('0x3b')](_0x48e7d9[_0x6ff1('0x3c')],{})['then'](respondWithResult(_0x12affb,0xc9))['catch'](handleError(_0x12affb,null));};exports['update']=function(_0x2f6172,_0xcf4451){if(_0x2f6172[_0x6ff1('0x3c')]['id']){delete _0x2f6172[_0x6ff1('0x3c')]['id'];}return db[_0x6ff1('0x2f')]['find']({'where':{'id':_0x2f6172[_0x6ff1('0x3d')]['id']}})['then'](handleEntityNotFound(_0xcf4451,null))[_0x6ff1('0x28')](saveUpdates(_0x2f6172['body'],null))['then'](respondWithResult(_0xcf4451,null))[_0x6ff1('0x3e')](handleError(_0xcf4451,null));};exports[_0x6ff1('0x29')]=function(_0x3f8d42,_0x91ddc7){return db[_0x6ff1('0x2f')][_0x6ff1('0x3a')]({'where':{'id':_0x3f8d42['params']['id']}})[_0x6ff1('0x28')](handleEntityNotFound(_0x91ddc7,null))[_0x6ff1('0x28')](removeEntity(_0x91ddc7,null))['catch'](handleError(_0x91ddc7,null));};