29fea71d7f8b4b53a6e1faadbe2bc3156dd8ada6
[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 _0x7bae=['create','body','catch','params','destroy','zip-dir','fast-json-patch','moment','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','end','json','limit','count','offset','set','Content-Range','apply','save','update','then','error','stack','name','show','keys','ChatProactiveAction','rawAttributes','query','filters','intersection','model','fields','attributes','length','includeAll','merge','options','find'];(function(_0x2dafbe,_0x5d04de){var _0x58a45a=function(_0x50ac96){while(--_0x50ac96){_0x2dafbe['push'](_0x2dafbe['shift']());}};_0x58a45a(++_0x5d04de);}(_0x7bae,0x13b));var _0xe7ba=function(_0x3bf83f,_0x181cac){_0x3bf83f=_0x3bf83f-0x0;var _0x22c4a9=_0x7bae[_0x3bf83f];return _0x22c4a9;};'use strict';var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require(_0xe7ba('0x0'));var jsonpatch=require(_0xe7ba('0x1'));var rp=require('request-promise');var moment=require(_0xe7ba('0x2'));var BPromise=require('bluebird');var Mustache=require(_0xe7ba('0x3'));var util=require(_0xe7ba('0x4'));var path=require(_0xe7ba('0x5'));var sox=require(_0xe7ba('0x6'));var csv=require(_0xe7ba('0x7'));var ejs=require(_0xe7ba('0x8'));var fs=require('fs');var fs_extra=require(_0xe7ba('0x9'));var _=require(_0xe7ba('0xa'));var squel=require(_0xe7ba('0xb'));var crypto=require(_0xe7ba('0xc'));var jsforce=require(_0xe7ba('0xd'));var deskjs=require(_0xe7ba('0xe'));var toCsv=require(_0xe7ba('0x7'));var querystring=require(_0xe7ba('0xf'));var Papa=require('papaparse');var Redis=require(_0xe7ba('0x10'));var authService=require(_0xe7ba('0x11'));var qs=require(_0xe7ba('0x12'));var as=require(_0xe7ba('0x13'));var hardwareService=require(_0xe7ba('0x14'));var logger=require(_0xe7ba('0x15'))(_0xe7ba('0x16'));var utils=require(_0xe7ba('0x17'));var config=require(_0xe7ba('0x18'));var licenseUtil=require('../../config/license/util');var db=require(_0xe7ba('0x19'))['db'];function respondWithStatusCode(_0x588c8b,_0x602b1){_0x602b1=_0x602b1||0xcc;return function(_0x45229c){if(_0x45229c){return _0x588c8b[_0xe7ba('0x1a')](_0x602b1);}return _0x588c8b[_0xe7ba('0x1b')](_0x602b1)[_0xe7ba('0x1c')]();};}function respondWithResult(_0x41369f,_0x561dbb){_0x561dbb=_0x561dbb||0xc8;return function(_0x561c48){if(_0x561c48){return _0x41369f[_0xe7ba('0x1b')](_0x561dbb)[_0xe7ba('0x1d')](_0x561c48);}};}function respondWithFilteredResult(_0x359f6f,_0x5d1d03){return function(_0x4390e3){if(_0x4390e3){var _0x4b20fd=typeof _0x5d1d03['offset']==='undefined'&&typeof _0x5d1d03[_0xe7ba('0x1e')]==='undefined';var _0x41a773=_0x4390e3['count'];var _0x4e3021=_0x4b20fd?0x0:_0x5d1d03['offset'];var _0x3f326a=_0x4b20fd?_0x4390e3[_0xe7ba('0x1f')]:_0x5d1d03[_0xe7ba('0x20')]+_0x5d1d03[_0xe7ba('0x1e')];var _0x1c8b5b;if(_0x3f326a>=_0x41a773){_0x3f326a=_0x41a773;_0x1c8b5b=0xc8;}else{_0x1c8b5b=0xce;}_0x359f6f['status'](_0x1c8b5b);return _0x359f6f[_0xe7ba('0x21')](_0xe7ba('0x22'),_0x4e3021+'-'+_0x3f326a+'/'+_0x41a773)[_0xe7ba('0x1d')](_0x4390e3);}return null;};}function patchUpdates(_0x136ec6){return function(_0x4aaf35){try{jsonpatch[_0xe7ba('0x23')](_0x4aaf35,_0x136ec6,!![]);}catch(_0x2936b7){return BPromise['reject'](_0x2936b7);}return _0x4aaf35[_0xe7ba('0x24')]();};}function saveUpdates(_0x4514e8,_0x27c882){return function(_0x7ab9e4){if(_0x7ab9e4){return _0x7ab9e4[_0xe7ba('0x25')](_0x4514e8)[_0xe7ba('0x26')](function(_0x293b14){return _0x293b14;});}return null;};}function removeEntity(_0x2b29f0,_0x41cbd9){return function(_0xa72f1c){if(_0xa72f1c){return _0xa72f1c['destroy']()['then'](function(){_0x2b29f0['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x4363a8,_0x576513){return function(_0x4ecc0d){if(!_0x4ecc0d){_0x4363a8['sendStatus'](0x194);}return _0x4ecc0d;};}function handleError(_0x255def,_0x32cc00){_0x32cc00=_0x32cc00||0x1f4;return function(_0xe32862){logger[_0xe7ba('0x27')](_0xe32862[_0xe7ba('0x28')]);if(_0xe32862[_0xe7ba('0x29')]){delete _0xe32862[_0xe7ba('0x29')];}_0x255def[_0xe7ba('0x1b')](_0x32cc00)['send'](_0xe32862);};}exports[_0xe7ba('0x2a')]=function(_0x48c869,_0x102925){var _0x92fe7={'raw':!![],'where':{'id':_0x48c869['params']['id']}},_0x369451={};_0x369451['model']=_[_0xe7ba('0x2b')](db[_0xe7ba('0x2c')][_0xe7ba('0x2d')]);_0x369451[_0xe7ba('0x2e')]=_[_0xe7ba('0x2b')](_0x48c869['query']);_0x369451[_0xe7ba('0x2f')]=_[_0xe7ba('0x30')](_0x369451['model'],_0x369451[_0xe7ba('0x2e')]);_0x92fe7['attributes']=_['intersection'](_0x369451[_0xe7ba('0x31')],qs[_0xe7ba('0x32')](_0x48c869[_0xe7ba('0x2e')]['fields']));_0x92fe7[_0xe7ba('0x33')]=_0x92fe7['attributes'][_0xe7ba('0x34')]?_0x92fe7[_0xe7ba('0x33')]:_0x369451[_0xe7ba('0x31')];if(_0x48c869[_0xe7ba('0x2e')][_0xe7ba('0x35')]){_0x92fe7['include']=[{'all':!![]}];}_0x92fe7=_[_0xe7ba('0x36')]({},_0x92fe7,_0x48c869[_0xe7ba('0x37')]);return db['ChatProactiveAction'][_0xe7ba('0x38')](_0x92fe7)[_0xe7ba('0x26')](handleEntityNotFound(_0x102925,null))[_0xe7ba('0x26')](respondWithResult(_0x102925,null))['catch'](handleError(_0x102925,null));};exports[_0xe7ba('0x39')]=function(_0x23c36e,_0x5db8ab){return db[_0xe7ba('0x2c')][_0xe7ba('0x39')](_0x23c36e[_0xe7ba('0x3a')],{})['then'](respondWithResult(_0x5db8ab,0xc9))[_0xe7ba('0x3b')](handleError(_0x5db8ab,null));};exports[_0xe7ba('0x25')]=function(_0x575f4b,_0x330e98){if(_0x575f4b[_0xe7ba('0x3a')]['id']){delete _0x575f4b[_0xe7ba('0x3a')]['id'];}return db['ChatProactiveAction']['find']({'where':{'id':_0x575f4b[_0xe7ba('0x3c')]['id']}})[_0xe7ba('0x26')](handleEntityNotFound(_0x330e98,null))[_0xe7ba('0x26')](saveUpdates(_0x575f4b[_0xe7ba('0x3a')],null))[_0xe7ba('0x26')](respondWithResult(_0x330e98,null))['catch'](handleError(_0x330e98,null));};exports[_0xe7ba('0x3d')]=function(_0x2a6d2a,_0x3139a6){return db[_0xe7ba('0x2c')]['find']({'where':{'id':_0x2a6d2a[_0xe7ba('0x3c')]['id']}})[_0xe7ba('0x26')](handleEntityNotFound(_0x3139a6,null))[_0xe7ba('0x26')](removeEntity(_0x3139a6,null))[_0xe7ba('0x3b')](handleError(_0x3139a6,null));};