1a3d23683307686c6e86577924611bffcebbbb7e
[motion2.git] / server / api / UserChatInteraction / UserChatInteraction.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 _0x18b3=['html-pdf','eml-format','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','sox','to-csv','jsforce','desk.js','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','end','status','json','offset','limit','set','Content-Range','reject','update','then','destroy','get','UserChatInteractions','sendStatus','error','stack','name','map','UserChatInteraction','rawAttributes','fieldName','type','model','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','sort','where','filter','merge','VIRTUAL','options','count','includeAll','include','findAll','catch','show','params','keys','find','create','Unable\x20to\x20retrieve\x20the\x20current\x20user','user','UserProfileSection','userProfileId','autoAssociation','UserProfileResource','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','body'];(function(_0x340e2e,_0x418ad4){var _0x10c790=function(_0x3b3959){while(--_0x3b3959){_0x340e2e['push'](_0x340e2e['shift']());}};_0x10c790(++_0x418ad4);}(_0x18b3,0x140));var _0x318b=function(_0x2fbbd0,_0x586599){_0x2fbbd0=_0x2fbbd0-0x0;var _0x107d4a=_0x18b3[_0x2fbbd0];return _0x107d4a;};'use strict';var pdf=require(_0x318b('0x0'));var emlformat=require(_0x318b('0x1'));var rimraf=require('rimraf');var zipdir=require(_0x318b('0x2'));var jsonpatch=require(_0x318b('0x3'));var rp=require(_0x318b('0x4'));var moment=require(_0x318b('0x5'));var BPromise=require(_0x318b('0x6'));var Mustache=require(_0x318b('0x7'));var util=require(_0x318b('0x8'));var path=require('path');var sox=require(_0x318b('0x9'));var csv=require(_0x318b('0xa'));var ejs=require('ejs');var fs=require('fs');var _=require('lodash');var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0x318b('0xb'));var deskjs=require(_0x318b('0xc'));var toCsv=require('to-csv');var querystring=require(_0x318b('0xd'));var Papa=require(_0x318b('0xe'));var Redis=require('ioredis');var authService=require(_0x318b('0xf'));var qs=require(_0x318b('0x10'));var as=require(_0x318b('0x11'));var hardwareService=require(_0x318b('0x12'));var logger=require(_0x318b('0x13'))(_0x318b('0x14'));var utils=require(_0x318b('0x15'));var config=require(_0x318b('0x16'));var licenseUtil=require(_0x318b('0x17'));var db=require(_0x318b('0x18'))['db'];function respondWithStatusCode(_0x3825bc,_0x244689){_0x244689=_0x244689||0xcc;return function(_0x736f27){if(_0x736f27){return _0x3825bc['sendStatus'](_0x244689);}return _0x3825bc['status'](_0x244689)[_0x318b('0x19')]();};}function respondWithResult(_0x565d7d,_0x114d00){_0x114d00=_0x114d00||0xc8;return function(_0x2894c2){if(_0x2894c2){return _0x565d7d[_0x318b('0x1a')](_0x114d00)[_0x318b('0x1b')](_0x2894c2);}};}function respondWithFilteredResult(_0xba214a,_0xcfe57c){return function(_0x5ac16c){if(_0x5ac16c){var _0x620e9e=_0x5ac16c['count'],_0x46f5fc=_0xcfe57c[_0x318b('0x1c')],_0x2e2142=_0xcfe57c[_0x318b('0x1c')]+_0xcfe57c[_0x318b('0x1d')],_0x2549e0;if(_0x2e2142>=_0x620e9e){_0x2e2142=_0x620e9e;_0x2549e0=0xc8;}else{_0x2549e0=0xce;}_0xba214a[_0x318b('0x1a')](_0x2549e0);return _0xba214a[_0x318b('0x1e')](_0x318b('0x1f'),_0x46f5fc+'-'+_0x2e2142+'/'+_0x620e9e)[_0x318b('0x1b')](_0x5ac16c);}return null;};}function patchUpdates(_0x51a919){return function(_0x4b6f05){try{jsonpatch['apply'](_0x4b6f05,_0x51a919,!![]);}catch(_0x240d0f){return BPromise[_0x318b('0x20')](_0x240d0f);}return _0x4b6f05['save']();};}function saveUpdates(_0x3deeca,_0x5265de){return function(_0x594110){if(_0x594110){return _0x594110[_0x318b('0x21')](_0x3deeca)[_0x318b('0x22')](function(_0x23a452){return _0x23a452;});}return null;};}function removeEntity(_0x49a817,_0x5a0363){return function(_0x5ef8ba){if(_0x5ef8ba){return _0x5ef8ba[_0x318b('0x23')]()[_0x318b('0x22')](function(){var _0x1b3b72=_0x5ef8ba[_0x318b('0x24')]({'plain':!![]});var _0x411ee7=_0x318b('0x25');return db['UserProfileResource'][_0x318b('0x23')]({'where':{'type':_0x411ee7,'resourceId':_0x1b3b72['id']}})[_0x318b('0x22')](function(){return _0x5ef8ba;});})[_0x318b('0x22')](function(){_0x49a817['status'](0xcc)[_0x318b('0x19')]();});}};}function handleEntityNotFound(_0x12124a,_0x143c9a){return function(_0x2d996c){if(!_0x2d996c){_0x12124a[_0x318b('0x26')](0x194);}return _0x2d996c;};}function handleError(_0x38446c,_0x260205){_0x260205=_0x260205||0x1f4;return function(_0x3ef071){logger[_0x318b('0x27')](_0x3ef071[_0x318b('0x28')]);if(_0x3ef071[_0x318b('0x29')]){delete _0x3ef071[_0x318b('0x29')];}_0x38446c[_0x318b('0x1a')](_0x260205)['send'](_0x3ef071);};}exports['index']=function(_0x275d08,_0xd6155c){var _0x2f5dd3={},_0xb136a={},_0x25fad5={'count':0x0,'rows':[]};var _0x50f16d=_[_0x318b('0x2a')](db[_0x318b('0x2b')][_0x318b('0x2c')],function(_0x512714){return{'name':_0x512714[_0x318b('0x2d')],'type':_0x512714[_0x318b('0x2e')]['key']};});_0xb136a[_0x318b('0x2f')]=_[_0x318b('0x2a')](_0x50f16d,_0x318b('0x29'));_0xb136a['query']=_['keys'](_0x275d08[_0x318b('0x30')]);_0xb136a[_0x318b('0x31')]=_[_0x318b('0x32')](_0xb136a['model'],_0xb136a[_0x318b('0x30')]);_0x2f5dd3[_0x318b('0x33')]=_[_0x318b('0x32')](_0xb136a[_0x318b('0x2f')],qs['fields'](_0x275d08['query'][_0x318b('0x34')]));_0x2f5dd3['attributes']=_0x2f5dd3['attributes'][_0x318b('0x35')]?_0x2f5dd3['attributes']:_0xb136a[_0x318b('0x2f')];if(!_0x275d08[_0x318b('0x30')][_0x318b('0x36')](_0x318b('0x37'))){_0x2f5dd3[_0x318b('0x1d')]=qs[_0x318b('0x1d')](_0x275d08[_0x318b('0x30')][_0x318b('0x1d')]);_0x2f5dd3[_0x318b('0x1c')]=qs[_0x318b('0x1c')](_0x275d08[_0x318b('0x30')][_0x318b('0x1c')]);}_0x2f5dd3['order']=qs[_0x318b('0x38')](_0x275d08[_0x318b('0x30')][_0x318b('0x38')]);_0x2f5dd3[_0x318b('0x39')]=qs['filters'](_['pick'](_0x275d08['query'],_0xb136a['filters']),_0x50f16d);if(_0x275d08[_0x318b('0x30')][_0x318b('0x3a')]){_0x2f5dd3[_0x318b('0x39')]=_[_0x318b('0x3b')](_0x2f5dd3[_0x318b('0x39')],{'$or':_[_0x318b('0x2a')](_0x50f16d,function(_0xdfec32){if(_0xdfec32[_0x318b('0x2e')]!==_0x318b('0x3c')){var _0x1c3f0f={};_0x1c3f0f[_0xdfec32[_0x318b('0x29')]]={'$like':'%'+_0x275d08[_0x318b('0x30')][_0x318b('0x3a')]+'%'};return _0x1c3f0f;}})});}_0x2f5dd3=_[_0x318b('0x3b')]({},_0x2f5dd3,_0x275d08[_0x318b('0x3d')]);var _0x1b3c39={'where':_0x2f5dd3[_0x318b('0x39')]};return db['UserChatInteraction'][_0x318b('0x3e')](_0x1b3c39)[_0x318b('0x22')](function(_0x415afd){_0x25fad5[_0x318b('0x3e')]=_0x415afd;if(_0x275d08['query'][_0x318b('0x3f')]){_0x2f5dd3[_0x318b('0x40')]=[{'all':!![]}];}return db[_0x318b('0x2b')][_0x318b('0x41')](_0x2f5dd3);})[_0x318b('0x22')](function(_0x14e9bf){_0x25fad5['rows']=_0x14e9bf;return _0x25fad5;})[_0x318b('0x22')](respondWithFilteredResult(_0xd6155c,_0x2f5dd3))[_0x318b('0x42')](handleError(_0xd6155c,null));};exports[_0x318b('0x43')]=function(_0x3ff041,_0x5c568f){var _0x596430={'raw':!![],'where':{'id':_0x3ff041[_0x318b('0x44')]['id']}},_0x2b5972={};_0x2b5972[_0x318b('0x2f')]=_[_0x318b('0x45')](db[_0x318b('0x2b')][_0x318b('0x2c')]);_0x2b5972['query']=_['keys'](_0x3ff041[_0x318b('0x30')]);_0x2b5972[_0x318b('0x31')]=_[_0x318b('0x32')](_0x2b5972[_0x318b('0x2f')],_0x2b5972[_0x318b('0x30')]);_0x596430['attributes']=_[_0x318b('0x32')](_0x2b5972['model'],qs[_0x318b('0x34')](_0x3ff041[_0x318b('0x30')][_0x318b('0x34')]));_0x596430['attributes']=_0x596430['attributes'][_0x318b('0x35')]?_0x596430[_0x318b('0x33')]:_0x2b5972[_0x318b('0x2f')];if(_0x3ff041[_0x318b('0x30')][_0x318b('0x3f')]){_0x596430[_0x318b('0x40')]=[{'all':!![]}];}_0x596430=_[_0x318b('0x3b')]({},_0x596430,_0x3ff041['options']);return db[_0x318b('0x2b')][_0x318b('0x46')](_0x596430)[_0x318b('0x22')](handleEntityNotFound(_0x5c568f,null))[_0x318b('0x22')](respondWithResult(_0x5c568f,null))[_0x318b('0x42')](handleError(_0x5c568f,null));};exports['create']=function(_0x5672e2,_0x5939f1){return db['UserChatInteraction'][_0x318b('0x47')](_0x5672e2['body'],{})[_0x318b('0x22')](function(_0x344dc1){var _0x4767d7=_0x5672e2['user']['get']({'plain':!![]});if(!_0x4767d7)throw new Error(_0x318b('0x48'));if(_0x4767d7['role']===_0x318b('0x49')){var _0x1afaf2=_0x344dc1[_0x318b('0x24')]({'plain':!![]});var _0x54bf61=_0x318b('0x25');return db[_0x318b('0x4a')][_0x318b('0x46')]({'where':{'name':_0x54bf61,'userProfileId':_0x4767d7[_0x318b('0x4b')]},'raw':!![]})[_0x318b('0x22')](function(_0x8d0e6a){if(_0x8d0e6a&&_0x8d0e6a[_0x318b('0x4c')]===0x0){return db[_0x318b('0x4d')][_0x318b('0x47')]({'name':_0x1afaf2['name'],'resourceId':_0x1afaf2['id'],'type':_0x8d0e6a[_0x318b('0x29')],'sectionId':_0x8d0e6a['id']},{})[_0x318b('0x22')](function(){return _0x344dc1;});}else{return _0x344dc1;}})[_0x318b('0x42')](function(_0x5630c6){logger[_0x318b('0x27')](_0x318b('0x4e'),_0x5630c6);throw _0x5630c6;});}return _0x344dc1;})[_0x318b('0x22')](respondWithResult(_0x5939f1,0xc9))['catch'](handleError(_0x5939f1,null));};exports[_0x318b('0x21')]=function(_0x529387,_0x2f16b4){if(_0x529387[_0x318b('0x4f')]['id']){delete _0x529387[_0x318b('0x4f')]['id'];}return db['UserChatInteraction'][_0x318b('0x46')]({'where':{'id':_0x529387[_0x318b('0x44')]['id']}})[_0x318b('0x22')](handleEntityNotFound(_0x2f16b4,null))[_0x318b('0x22')](saveUpdates(_0x529387[_0x318b('0x4f')],null))['then'](respondWithResult(_0x2f16b4,null))[_0x318b('0x42')](handleError(_0x2f16b4,null));};exports[_0x318b('0x23')]=function(_0x598cdd,_0x3cddf){return db[_0x318b('0x2b')][_0x318b('0x46')]({'where':{'id':_0x598cdd[_0x318b('0x44')]['id']}})[_0x318b('0x22')](handleEntityNotFound(_0x3cddf,null))[_0x318b('0x22')](removeEntity(_0x3cddf,null))[_0x318b('0x42')](handleError(_0x3cddf,null));};