Built motion from commit 994c64e1.|2.6.1
[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 _0x0a52=['../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','status','end','json','offset','limit','count','set','Content-Range','apply','reject','save','update','then','destroy','sendStatus','name','send','show','params','model','keys','ChatProactiveAction','rawAttributes','query','filters','intersection','fields','attributes','length','includeAll','include','merge','options','find','catch','create','body','eml-format','rimraf','fast-json-patch','request-promise','moment','mustache','util','path','sox','to-csv','ejs','squel','crypto','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware'];(function(_0x17bed4,_0x2dcc8d){var _0x43f1dd=function(_0x128acd){while(--_0x128acd){_0x17bed4['push'](_0x17bed4['shift']());}};_0x43f1dd(++_0x2dcc8d);}(_0x0a52,0xe4));var _0x20a5=function(_0x9f1d45,_0x3ed644){_0x9f1d45=_0x9f1d45-0x0;var _0x22e96c=_0x0a52[_0x9f1d45];return _0x22e96c;};'use strict';var emlformat=require(_0x20a5('0x0'));var rimraf=require(_0x20a5('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x20a5('0x2'));var rp=require(_0x20a5('0x3'));var moment=require(_0x20a5('0x4'));var BPromise=require('bluebird');var Mustache=require(_0x20a5('0x5'));var util=require(_0x20a5('0x6'));var path=require(_0x20a5('0x7'));var sox=require(_0x20a5('0x8'));var csv=require(_0x20a5('0x9'));var ejs=require(_0x20a5('0xa'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require('lodash');var squel=require(_0x20a5('0xb'));var crypto=require(_0x20a5('0xc'));var jsforce=require('jsforce');var deskjs=require(_0x20a5('0xd'));var toCsv=require(_0x20a5('0x9'));var querystring=require(_0x20a5('0xe'));var Papa=require(_0x20a5('0xf'));var Redis=require('ioredis');var authService=require(_0x20a5('0x10'));var qs=require(_0x20a5('0x11'));var as=require(_0x20a5('0x12'));var hardwareService=require(_0x20a5('0x13'));var logger=require(_0x20a5('0x14'))(_0x20a5('0x15'));var utils=require(_0x20a5('0x16'));var config=require(_0x20a5('0x17'));var licenseUtil=require('../../config/license/util');var db=require(_0x20a5('0x18'))['db'];function respondWithStatusCode(_0x5e6c3b,_0xd07281){_0xd07281=_0xd07281||0xcc;return function(_0x429c69){if(_0x429c69){return _0x5e6c3b['sendStatus'](_0xd07281);}return _0x5e6c3b[_0x20a5('0x19')](_0xd07281)[_0x20a5('0x1a')]();};}function respondWithResult(_0x46acee,_0x43528b){_0x43528b=_0x43528b||0xc8;return function(_0x42bc38){if(_0x42bc38){return _0x46acee[_0x20a5('0x19')](_0x43528b)[_0x20a5('0x1b')](_0x42bc38);}};}function respondWithFilteredResult(_0x254546,_0x39b063){return function(_0x446a4f){if(_0x446a4f){var _0x24e1b0=typeof _0x39b063[_0x20a5('0x1c')]==='undefined'&&typeof _0x39b063[_0x20a5('0x1d')]==='undefined';var _0x312978=_0x446a4f[_0x20a5('0x1e')];var _0x11a4e3=_0x24e1b0?0x0:_0x39b063[_0x20a5('0x1c')];var _0x2cb0e8=_0x24e1b0?_0x446a4f[_0x20a5('0x1e')]:_0x39b063[_0x20a5('0x1c')]+_0x39b063['limit'];var _0x43cd40;if(_0x2cb0e8>=_0x312978){_0x2cb0e8=_0x312978;_0x43cd40=0xc8;}else{_0x43cd40=0xce;}_0x254546['status'](_0x43cd40);return _0x254546[_0x20a5('0x1f')](_0x20a5('0x20'),_0x11a4e3+'-'+_0x2cb0e8+'/'+_0x312978)[_0x20a5('0x1b')](_0x446a4f);}return null;};}function patchUpdates(_0x3bf093){return function(_0x40e28e){try{jsonpatch[_0x20a5('0x21')](_0x40e28e,_0x3bf093,!![]);}catch(_0xf577cd){return BPromise[_0x20a5('0x22')](_0xf577cd);}return _0x40e28e[_0x20a5('0x23')]();};}function saveUpdates(_0x1e43e4,_0x42c159){return function(_0x580d39){if(_0x580d39){return _0x580d39[_0x20a5('0x24')](_0x1e43e4)[_0x20a5('0x25')](function(_0x39ac06){return _0x39ac06;});}return null;};}function removeEntity(_0x4d4052,_0x370efa){return function(_0x1b2850){if(_0x1b2850){return _0x1b2850[_0x20a5('0x26')]()[_0x20a5('0x25')](function(){_0x4d4052['status'](0xcc)[_0x20a5('0x1a')]();});}};}function handleEntityNotFound(_0x3103bd,_0x16022f){return function(_0x21978f){if(!_0x21978f){_0x3103bd[_0x20a5('0x27')](0x194);}return _0x21978f;};}function handleError(_0x23239d,_0x171cd5){_0x171cd5=_0x171cd5||0x1f4;return function(_0x3987c5){logger['error'](_0x3987c5['stack']);if(_0x3987c5[_0x20a5('0x28')]){delete _0x3987c5[_0x20a5('0x28')];}_0x23239d['status'](_0x171cd5)[_0x20a5('0x29')](_0x3987c5);};}exports[_0x20a5('0x2a')]=function(_0x2b891c,_0x38bae9){var _0x5a84be={'raw':!![],'where':{'id':_0x2b891c[_0x20a5('0x2b')]['id']}},_0x33f000={};_0x33f000[_0x20a5('0x2c')]=_[_0x20a5('0x2d')](db[_0x20a5('0x2e')][_0x20a5('0x2f')]);_0x33f000[_0x20a5('0x30')]=_[_0x20a5('0x2d')](_0x2b891c['query']);_0x33f000[_0x20a5('0x31')]=_[_0x20a5('0x32')](_0x33f000[_0x20a5('0x2c')],_0x33f000[_0x20a5('0x30')]);_0x5a84be['attributes']=_[_0x20a5('0x32')](_0x33f000[_0x20a5('0x2c')],qs['fields'](_0x2b891c[_0x20a5('0x30')][_0x20a5('0x33')]));_0x5a84be[_0x20a5('0x34')]=_0x5a84be[_0x20a5('0x34')][_0x20a5('0x35')]?_0x5a84be[_0x20a5('0x34')]:_0x33f000[_0x20a5('0x2c')];if(_0x2b891c['query'][_0x20a5('0x36')]){_0x5a84be[_0x20a5('0x37')]=[{'all':!![]}];}_0x5a84be=_[_0x20a5('0x38')]({},_0x5a84be,_0x2b891c[_0x20a5('0x39')]);return db[_0x20a5('0x2e')][_0x20a5('0x3a')](_0x5a84be)[_0x20a5('0x25')](handleEntityNotFound(_0x38bae9,null))['then'](respondWithResult(_0x38bae9,null))[_0x20a5('0x3b')](handleError(_0x38bae9,null));};exports[_0x20a5('0x3c')]=function(_0x11e6e9,_0x193398){return db['ChatProactiveAction'][_0x20a5('0x3c')](_0x11e6e9[_0x20a5('0x3d')],{})[_0x20a5('0x25')](respondWithResult(_0x193398,0xc9))[_0x20a5('0x3b')](handleError(_0x193398,null));};exports['update']=function(_0x1808a0,_0x54d667){if(_0x1808a0[_0x20a5('0x3d')]['id']){delete _0x1808a0['body']['id'];}return db[_0x20a5('0x2e')][_0x20a5('0x3a')]({'where':{'id':_0x1808a0[_0x20a5('0x2b')]['id']}})[_0x20a5('0x25')](handleEntityNotFound(_0x54d667,null))[_0x20a5('0x25')](saveUpdates(_0x1808a0['body'],null))[_0x20a5('0x25')](respondWithResult(_0x54d667,null))[_0x20a5('0x3b')](handleError(_0x54d667,null));};exports[_0x20a5('0x26')]=function(_0x141766,_0x2bdc15){return db[_0x20a5('0x2e')][_0x20a5('0x3a')]({'where':{'id':_0x141766[_0x20a5('0x2b')]['id']}})['then'](handleEntityNotFound(_0x2bdc15,null))[_0x20a5('0x25')](removeEntity(_0x2bdc15,null))['catch'](handleError(_0x2bdc15,null));};