5e347a7d390446fe631f2247b0a184bf466927f0
[motion2.git] / server / components / interaction / utils.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 _0xb5f8=['toLowerCase','[%s]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','stringify','null','findOne','update','then','info','catch','error','exports','lodash','../../mysqldb','../../config/logger','openchannel-interactions','fax-interactions','sms-interactions','whatsapp-interactions','chat','Website','Account','capitalize','InteractionId','upperFirst','unknown','websites','accounts','_interactions','_interaction_has_tags','_messages'];(function(_0x137f32,_0x5922c7){var _0x37b28b=function(_0x275cf8){while(--_0x275cf8){_0x137f32['push'](_0x137f32['shift']());}};_0x37b28b(++_0x5922c7);}(_0xb5f8,0x88));var _0x8b5f=function(_0x27f3d3,_0x27d8db){_0x27f3d3=_0x27f3d3-0x0;var _0x147352=_0xb5f8[_0x27f3d3];return _0x147352;};'use strict';var _=require(_0x8b5f('0x0'));var db=require(_0x8b5f('0x1'))['db'];var loggers={'openchannel':require(_0x8b5f('0x2'))(_0x8b5f('0x3')),'mail':require(_0x8b5f('0x2'))('mail-interactions'),'fax':require(_0x8b5f('0x2'))(_0x8b5f('0x4')),'sms':require('../../config/logger')(_0x8b5f('0x5')),'chat':require(_0x8b5f('0x2'))('chat-interactions'),'whatsapp':require(_0x8b5f('0x2'))(_0x8b5f('0x6'))};function getAccountFK(_0x4d3b72){return _['capitalize'](_0x4d3b72)+(_0x4d3b72===_0x8b5f('0x7')?_0x8b5f('0x8'):_0x8b5f('0x9'))+'Id';}function getInteractionFK(_0x28c5dd){return _[_0x8b5f('0xa')](_0x28c5dd)+'InteractionId';}function getInteractionId(_0x3a0cb2,_0x499e38,_0x3033cd){if(_0x3a0cb2&&_0x3a0cb2[_['upperFirst'](_0x3033cd)+_0x8b5f('0xb')]){return _0x3a0cb2[_[_0x8b5f('0xc')](_0x3033cd)+_0x8b5f('0xb')];}else if(_0x3a0cb2&&_0x3a0cb2['id']){return _0x3a0cb2['id'];}else if(_0x499e38&&_0x499e38['id']){return _0x499e38['id'];}else{return _0x8b5f('0xd');}}function getInteractionsTables(_0x53c123){return{'accounts':_0x53c123+'_'+(_0x53c123===_0x8b5f('0x7')?_0x8b5f('0xe'):_0x8b5f('0xf')),'interactions':_0x53c123+_0x8b5f('0x10'),'interactionsTags':_0x53c123+_0x8b5f('0x11'),'messages':_0x53c123+_0x8b5f('0x12'),'userInteractions':'user_has_'+_0x53c123+_0x8b5f('0x10')};}function getSelectedTags(_0x5d2186){var _0x53a284=[];if(_0x5d2186){_0x53a284=Array['isArray'](_0x5d2186)?_0x5d2186:[_0x5d2186];}return _0x53a284;}function log(_0x2c231b,_0x1aea64,_0x2bcb0a,_0x3fba31,_0x5549ef,_0xfa1643){loggers[_0x5549ef[_0x8b5f('0x13')]()][_0x2c231b](_0x8b5f('0x14'),_0xfa1643['toUpperCase'](),_0x1aea64?_0x1aea64['id']:null,_0x1aea64?_0x1aea64['name']:null,_0x1aea64?_0x1aea64[_0x8b5f('0x15')]:null,getInteractionId(_0x2bcb0a,_0x3fba31,_0x5549ef),_0x2bcb0a?JSON[_0x8b5f('0x16')](_0x2bcb0a):_0x8b5f('0x17'));}function updateUser(_0x32fad9,_0x114c0f,_0x29795e,_0x2279a8,_0x306034){db[_['upperFirst'](_0x2279a8)+'Interaction'][_0x8b5f('0x18')]({'where':{'id':getInteractionId(_0x114c0f,_0x29795e,_0x2279a8)}})['then'](function(_0x4ab3bc){if(_0x4ab3bc){return _0x4ab3bc[_0x8b5f('0x19')]({'UserId':_0x32fad9?_0x32fad9['id']:null});}})[_0x8b5f('0x1a')](function(_0x323046){if(_0x323046){log(_0x8b5f('0x1b'),_0x32fad9,_0x114c0f,_0x29795e,_0x2279a8,_0x306034);}})[_0x8b5f('0x1c')](function(){log(_0x8b5f('0x1d'),_0x32fad9,_0x114c0f,_0x29795e,_0x2279a8,_0x306034);});}module[_0x8b5f('0x1e')]={'getAccountFK':getAccountFK,'getInteractionFK':getInteractionFK,'getInteractionsTables':getInteractionsTables,'getSelectedTags':getSelectedTags,'updateUser':updateUser};