Built motion from commit 25580385.|2.6.2
[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 _0x98a8=['moment','bluebird','util','path','sox','to-csv','ejs','lodash','crypto','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/environment','../../mysqldb','end','status','json','undefined','count','offset','apply','reject','save','update','then','destroy','error','stack','name','send','show','params','model','keys','ChatProactiveAction','rawAttributes','query','filters','intersection','fields','length','attributes','includeAll','include','merge','options','find','create','body','catch','eml-format','rimraf','zip-dir','fast-json-patch','request-promise'];(function(_0x3947c9,_0x4d6c97){var _0x2e7871=function(_0x1236cc){while(--_0x1236cc){_0x3947c9['push'](_0x3947c9['shift']());}};_0x2e7871(++_0x4d6c97);}(_0x98a8,0x12c));var _0x898a=function(_0x393212,_0x21372a){_0x393212=_0x393212-0x0;var _0x2eb518=_0x98a8[_0x393212];return _0x2eb518;};'use strict';var emlformat=require(_0x898a('0x0'));var rimraf=require(_0x898a('0x1'));var zipdir=require(_0x898a('0x2'));var jsonpatch=require(_0x898a('0x3'));var rp=require(_0x898a('0x4'));var moment=require(_0x898a('0x5'));var BPromise=require(_0x898a('0x6'));var Mustache=require('mustache');var util=require(_0x898a('0x7'));var path=require(_0x898a('0x8'));var sox=require(_0x898a('0x9'));var csv=require(_0x898a('0xa'));var ejs=require(_0x898a('0xb'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x898a('0xc'));var squel=require('squel');var crypto=require(_0x898a('0xd'));var jsforce=require('jsforce');var deskjs=require(_0x898a('0xe'));var toCsv=require(_0x898a('0xa'));var querystring=require(_0x898a('0xf'));var Papa=require(_0x898a('0x10'));var Redis=require(_0x898a('0x11'));var authService=require(_0x898a('0x12'));var qs=require(_0x898a('0x13'));var as=require(_0x898a('0x14'));var hardwareService=require(_0x898a('0x15'));var logger=require('../../config/logger')(_0x898a('0x16'));var utils=require('../../config/utils');var config=require(_0x898a('0x17'));var licenseUtil=require('../../config/license/util');var db=require(_0x898a('0x18'))['db'];function respondWithStatusCode(_0x2c76b7,_0x364a23){_0x364a23=_0x364a23||0xcc;return function(_0x5f5e06){if(_0x5f5e06){return _0x2c76b7['sendStatus'](_0x364a23);}return _0x2c76b7['status'](_0x364a23)[_0x898a('0x19')]();};}function respondWithResult(_0x1f5be4,_0xb24335){_0xb24335=_0xb24335||0xc8;return function(_0x116fbe){if(_0x116fbe){return _0x1f5be4[_0x898a('0x1a')](_0xb24335)[_0x898a('0x1b')](_0x116fbe);}};}function respondWithFilteredResult(_0x506023,_0x47033c){return function(_0x53a4b8){if(_0x53a4b8){var _0x3fec7a=typeof _0x47033c['offset']===_0x898a('0x1c')&&typeof _0x47033c['limit']===_0x898a('0x1c');var _0x56f8f9=_0x53a4b8[_0x898a('0x1d')];var _0x3197f7=_0x3fec7a?0x0:_0x47033c[_0x898a('0x1e')];var _0x4ddd4d=_0x3fec7a?_0x53a4b8[_0x898a('0x1d')]:_0x47033c['offset']+_0x47033c['limit'];var _0x3f8af4;if(_0x4ddd4d>=_0x56f8f9){_0x4ddd4d=_0x56f8f9;_0x3f8af4=0xc8;}else{_0x3f8af4=0xce;}_0x506023[_0x898a('0x1a')](_0x3f8af4);return _0x506023['set']('Content-Range',_0x3197f7+'-'+_0x4ddd4d+'/'+_0x56f8f9)[_0x898a('0x1b')](_0x53a4b8);}return null;};}function patchUpdates(_0x26449a){return function(_0x38a8f0){try{jsonpatch[_0x898a('0x1f')](_0x38a8f0,_0x26449a,!![]);}catch(_0x2da52d){return BPromise[_0x898a('0x20')](_0x2da52d);}return _0x38a8f0[_0x898a('0x21')]();};}function saveUpdates(_0x483212,_0x247cfc){return function(_0x50718e){if(_0x50718e){return _0x50718e[_0x898a('0x22')](_0x483212)[_0x898a('0x23')](function(_0x30495a){return _0x30495a;});}return null;};}function removeEntity(_0x310bfa,_0x4e254d){return function(_0x274cdf){if(_0x274cdf){return _0x274cdf[_0x898a('0x24')]()[_0x898a('0x23')](function(){_0x310bfa[_0x898a('0x1a')](0xcc)[_0x898a('0x19')]();});}};}function handleEntityNotFound(_0x1426e3,_0x5b7719){return function(_0x20bde0){if(!_0x20bde0){_0x1426e3['sendStatus'](0x194);}return _0x20bde0;};}function handleError(_0x513c6b,_0x53ddb2){_0x53ddb2=_0x53ddb2||0x1f4;return function(_0x3678be){logger[_0x898a('0x25')](_0x3678be[_0x898a('0x26')]);if(_0x3678be[_0x898a('0x27')]){delete _0x3678be[_0x898a('0x27')];}_0x513c6b[_0x898a('0x1a')](_0x53ddb2)[_0x898a('0x28')](_0x3678be);};}exports[_0x898a('0x29')]=function(_0xd31922,_0x58149d){var _0x4b3e68={'raw':!![],'where':{'id':_0xd31922[_0x898a('0x2a')]['id']}},_0x47f1ed={};_0x47f1ed[_0x898a('0x2b')]=_[_0x898a('0x2c')](db[_0x898a('0x2d')][_0x898a('0x2e')]);_0x47f1ed[_0x898a('0x2f')]=_[_0x898a('0x2c')](_0xd31922[_0x898a('0x2f')]);_0x47f1ed[_0x898a('0x30')]=_[_0x898a('0x31')](_0x47f1ed[_0x898a('0x2b')],_0x47f1ed[_0x898a('0x2f')]);_0x4b3e68['attributes']=_[_0x898a('0x31')](_0x47f1ed[_0x898a('0x2b')],qs[_0x898a('0x32')](_0xd31922[_0x898a('0x2f')][_0x898a('0x32')]));_0x4b3e68['attributes']=_0x4b3e68['attributes'][_0x898a('0x33')]?_0x4b3e68[_0x898a('0x34')]:_0x47f1ed[_0x898a('0x2b')];if(_0xd31922['query'][_0x898a('0x35')]){_0x4b3e68[_0x898a('0x36')]=[{'all':!![]}];}_0x4b3e68=_[_0x898a('0x37')]({},_0x4b3e68,_0xd31922[_0x898a('0x38')]);return db[_0x898a('0x2d')][_0x898a('0x39')](_0x4b3e68)[_0x898a('0x23')](handleEntityNotFound(_0x58149d,null))[_0x898a('0x23')](respondWithResult(_0x58149d,null))['catch'](handleError(_0x58149d,null));};exports[_0x898a('0x3a')]=function(_0x5baf5b,_0x573eb3){return db[_0x898a('0x2d')]['create'](_0x5baf5b[_0x898a('0x3b')],{})['then'](respondWithResult(_0x573eb3,0xc9))[_0x898a('0x3c')](handleError(_0x573eb3,null));};exports['update']=function(_0x299371,_0x354703){if(_0x299371[_0x898a('0x3b')]['id']){delete _0x299371['body']['id'];}return db['ChatProactiveAction']['find']({'where':{'id':_0x299371[_0x898a('0x2a')]['id']}})[_0x898a('0x23')](handleEntityNotFound(_0x354703,null))['then'](saveUpdates(_0x299371[_0x898a('0x3b')],null))[_0x898a('0x23')](respondWithResult(_0x354703,null))[_0x898a('0x3c')](handleError(_0x354703,null));};exports[_0x898a('0x24')]=function(_0x487093,_0x4b07bc){return db[_0x898a('0x2d')][_0x898a('0x39')]({'where':{'id':_0x487093['params']['id']}})['then'](handleEntityNotFound(_0x4b07bc,null))[_0x898a('0x23')](removeEntity(_0x4b07bc,null))[_0x898a('0x3c')](handleError(_0x4b07bc,null));};