f087efd0e7bb07e92d6b39f6306112b6c3740151
[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 _0xe77f=['body','find','destroy','eml-format','rimraf','fast-json-patch','request-promise','bluebird','mustache','path','sox','to-csv','ejs','fs-extra','crypto','jsforce','desk.js','querystring','papaparse','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','end','status','json','offset','undefined','limit','count','set','apply','reject','save','update','then','error','stack','name','send','show','params','model','keys','ChatProactiveAction','filters','intersection','query','fields','attributes','length','includeAll','include','options','catch','create'];(function(_0x40a045,_0x516f0e){var _0x1a687c=function(_0x48c9fe){while(--_0x48c9fe){_0x40a045['push'](_0x40a045['shift']());}};_0x1a687c(++_0x516f0e);}(_0xe77f,0xba));var _0xfe77=function(_0x4c394b,_0x43ced4){_0x4c394b=_0x4c394b-0x0;var _0x536301=_0xe77f[_0x4c394b];return _0x536301;};'use strict';var emlformat=require(_0xfe77('0x0'));var rimraf=require(_0xfe77('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0xfe77('0x2'));var rp=require(_0xfe77('0x3'));var moment=require('moment');var BPromise=require(_0xfe77('0x4'));var Mustache=require(_0xfe77('0x5'));var util=require('util');var path=require(_0xfe77('0x6'));var sox=require(_0xfe77('0x7'));var csv=require(_0xfe77('0x8'));var ejs=require(_0xfe77('0x9'));var fs=require('fs');var fs_extra=require(_0xfe77('0xa'));var _=require('lodash');var squel=require('squel');var crypto=require(_0xfe77('0xb'));var jsforce=require(_0xfe77('0xc'));var deskjs=require(_0xfe77('0xd'));var toCsv=require(_0xfe77('0x8'));var querystring=require(_0xfe77('0xe'));var Papa=require(_0xfe77('0xf'));var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require(_0xfe77('0x10'));var as=require(_0xfe77('0x11'));var hardwareService=require(_0xfe77('0x12'));var logger=require(_0xfe77('0x13'))('api');var utils=require(_0xfe77('0x14'));var config=require(_0xfe77('0x15'));var licenseUtil=require(_0xfe77('0x16'));var db=require(_0xfe77('0x17'))['db'];function respondWithStatusCode(_0x4cf458,_0x1aa2ea){_0x1aa2ea=_0x1aa2ea||0xcc;return function(_0x3b7edd){if(_0x3b7edd){return _0x4cf458[_0xfe77('0x18')](_0x1aa2ea);}return _0x4cf458['status'](_0x1aa2ea)[_0xfe77('0x19')]();};}function respondWithResult(_0x1a686e,_0x51f692){_0x51f692=_0x51f692||0xc8;return function(_0xc793dd){if(_0xc793dd){return _0x1a686e[_0xfe77('0x1a')](_0x51f692)[_0xfe77('0x1b')](_0xc793dd);}};}function respondWithFilteredResult(_0x28366f,_0x110dbd){return function(_0x1ab4f8){if(_0x1ab4f8){var _0x4d21f0=typeof _0x110dbd[_0xfe77('0x1c')]===_0xfe77('0x1d')&&typeof _0x110dbd[_0xfe77('0x1e')]===_0xfe77('0x1d');var _0x84d3da=_0x1ab4f8[_0xfe77('0x1f')];var _0x5b9f81=_0x4d21f0?0x0:_0x110dbd[_0xfe77('0x1c')];var _0x596f18=_0x4d21f0?_0x1ab4f8[_0xfe77('0x1f')]:_0x110dbd[_0xfe77('0x1c')]+_0x110dbd['limit'];var _0x347a14;if(_0x596f18>=_0x84d3da){_0x596f18=_0x84d3da;_0x347a14=0xc8;}else{_0x347a14=0xce;}_0x28366f['status'](_0x347a14);return _0x28366f[_0xfe77('0x20')]('Content-Range',_0x5b9f81+'-'+_0x596f18+'/'+_0x84d3da)['json'](_0x1ab4f8);}return null;};}function patchUpdates(_0x25a620){return function(_0x586d1d){try{jsonpatch[_0xfe77('0x21')](_0x586d1d,_0x25a620,!![]);}catch(_0x26eb4c){return BPromise[_0xfe77('0x22')](_0x26eb4c);}return _0x586d1d[_0xfe77('0x23')]();};}function saveUpdates(_0x219ccf,_0x27c49f){return function(_0x160c44){if(_0x160c44){return _0x160c44[_0xfe77('0x24')](_0x219ccf)[_0xfe77('0x25')](function(_0x21d660){return _0x21d660;});}return null;};}function removeEntity(_0x3f9ab8,_0x10de1a){return function(_0x5053f2){if(_0x5053f2){return _0x5053f2['destroy']()['then'](function(){_0x3f9ab8[_0xfe77('0x1a')](0xcc)[_0xfe77('0x19')]();});}};}function handleEntityNotFound(_0x9b5b2f,_0x41ba66){return function(_0x57f895){if(!_0x57f895){_0x9b5b2f[_0xfe77('0x18')](0x194);}return _0x57f895;};}function handleError(_0x63d932,_0x5b1e3d){_0x5b1e3d=_0x5b1e3d||0x1f4;return function(_0x3fe30d){logger[_0xfe77('0x26')](_0x3fe30d[_0xfe77('0x27')]);if(_0x3fe30d[_0xfe77('0x28')]){delete _0x3fe30d[_0xfe77('0x28')];}_0x63d932[_0xfe77('0x1a')](_0x5b1e3d)[_0xfe77('0x29')](_0x3fe30d);};}exports[_0xfe77('0x2a')]=function(_0x4565f9,_0x52cee8){var _0x243171={'raw':!![],'where':{'id':_0x4565f9[_0xfe77('0x2b')]['id']}},_0x2faa56={};_0x2faa56[_0xfe77('0x2c')]=_[_0xfe77('0x2d')](db[_0xfe77('0x2e')]['rawAttributes']);_0x2faa56['query']=_[_0xfe77('0x2d')](_0x4565f9['query']);_0x2faa56[_0xfe77('0x2f')]=_[_0xfe77('0x30')](_0x2faa56[_0xfe77('0x2c')],_0x2faa56[_0xfe77('0x31')]);_0x243171['attributes']=_[_0xfe77('0x30')](_0x2faa56[_0xfe77('0x2c')],qs[_0xfe77('0x32')](_0x4565f9[_0xfe77('0x31')]['fields']));_0x243171[_0xfe77('0x33')]=_0x243171[_0xfe77('0x33')][_0xfe77('0x34')]?_0x243171[_0xfe77('0x33')]:_0x2faa56[_0xfe77('0x2c')];if(_0x4565f9['query'][_0xfe77('0x35')]){_0x243171[_0xfe77('0x36')]=[{'all':!![]}];}_0x243171=_['merge']({},_0x243171,_0x4565f9[_0xfe77('0x37')]);return db[_0xfe77('0x2e')]['find'](_0x243171)[_0xfe77('0x25')](handleEntityNotFound(_0x52cee8,null))[_0xfe77('0x25')](respondWithResult(_0x52cee8,null))[_0xfe77('0x38')](handleError(_0x52cee8,null));};exports[_0xfe77('0x39')]=function(_0x2a85a2,_0x313892){return db['ChatProactiveAction'][_0xfe77('0x39')](_0x2a85a2[_0xfe77('0x3a')],{})[_0xfe77('0x25')](respondWithResult(_0x313892,0xc9))[_0xfe77('0x38')](handleError(_0x313892,null));};exports[_0xfe77('0x24')]=function(_0x487be6,_0x391ab3){if(_0x487be6[_0xfe77('0x3a')]['id']){delete _0x487be6[_0xfe77('0x3a')]['id'];}return db[_0xfe77('0x2e')][_0xfe77('0x3b')]({'where':{'id':_0x487be6[_0xfe77('0x2b')]['id']}})['then'](handleEntityNotFound(_0x391ab3,null))[_0xfe77('0x25')](saveUpdates(_0x487be6[_0xfe77('0x3a')],null))[_0xfe77('0x25')](respondWithResult(_0x391ab3,null))[_0xfe77('0x38')](handleError(_0x391ab3,null));};exports[_0xfe77('0x3c')]=function(_0x50083f,_0xd5cd1){return db[_0xfe77('0x2e')][_0xfe77('0x3b')]({'where':{'id':_0x50083f[_0xfe77('0x2b')]['id']}})[_0xfe77('0x25')](handleEntityNotFound(_0xd5cd1,null))['then'](removeEntity(_0xd5cd1,null))[_0xfe77('0x38')](handleError(_0xd5cd1,null));};