Built motion from commit (unavailable).|2.0.84
[motion2.git] / server / api / openchannelMessage / openchannelMessage.model.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 _0xdace=['then','OpenchannelAccount','find','OpenchannelAccountId','Contact','keys','replyUri','info','OpenchannelMessage,\x20%s,\x20%s','afterCreate','format','Forwarding\x20message\x20%d\x20to\x20%s','Interactions','length','omit','POST','GET','Message\x20%d\x20forwarded\x20to\x20%s','finally','utf8mb4','utf8mb4_unicode_ci','lodash','../../config/logger','api','moment','request-promise','./openchannelMessage.attributes','exports','define','OpenchannelMessage','openchannel_messages','get','direction','toLowerCase','out','UserId','OpenchannelInteraction','OpenchannelInteractionId','update','createdAt','body','catch','secret','CmContact'];(function(_0x342959,_0x2344d0){var _0x67dbf5=function(_0x2e67b6){while(--_0x2e67b6){_0x342959['push'](_0x342959['shift']());}};_0x67dbf5(++_0x2344d0);}(_0xdace,0xc5));var _0xedac=function(_0x278e3c,_0x1c9cfd){_0x278e3c=_0x278e3c-0x0;var _0x3e2d9b=_0xdace[_0x278e3c];return _0x3e2d9b;};'use strict';var _=require(_0xedac('0x0'));var util=require('util');var logger=require(_0xedac('0x1'))(_0xedac('0x2'));var moment=require(_0xedac('0x3'));var BPromise=require('bluebird');var rp=require(_0xedac('0x4'));var attributes=require(_0xedac('0x5'));module[_0xedac('0x6')]=function(_0xefb142,_0x5a97c0){return _0xefb142[_0xedac('0x7')](_0xedac('0x8'),attributes,{'tableName':_0xedac('0x9'),'paranoid':![],'indexes':[],'timestamps':!![],'hooks':{'afterCreate':function(_0x5ecbd3,_0x4081c6,_0x21440e){var _0x162eea=_0xefb142['models'];var _0x27243f=_0x5ecbd3[_0xedac('0xa')]({'plain':!![]});if(_0x27243f[_0xedac('0xb')]['toLowerCase']()==='in'||_0x27243f['direction'][_0xedac('0xc')]()===_0xedac('0xd')&&!_0x27243f['secret']&&!_['isNil'](_0x27243f[_0xedac('0xe')])){_0x162eea[_0xedac('0xf')]['findOne']({'where':{'id':_0x27243f[_0xedac('0x10')]}})['then'](function(_0x21c6ae){if(_0x21c6ae){_0x21c6ae[_0xedac('0x11')]({'lastMsgAt':_0x27243f[_0xedac('0x12')],'lastMsgDirection':_0x27243f[_0xedac('0xb')][_0xedac('0xc')](),'lastMsgBody':_0x27243f[_0xedac('0x13')]});}})[_0xedac('0x14')](function(_0x11f0b0){console['error'](_0x11f0b0);});}if(_0x27243f[_0xedac('0xb')]===_0xedac('0xd')&&!_0x27243f[_0xedac('0x15')]){var _0x2676c3;_0x162eea[_0xedac('0x16')]['describe']()[_0xedac('0x17')](function(_0x594b11){return _0x162eea[_0xedac('0x18')][_0xedac('0x19')]({'where':{'id':_0x27243f[_0xedac('0x1a')]},'include':[{'model':_0x162eea[_0xedac('0xf')],'as':'Interactions','where':{'id':_0x27243f['OpenchannelInteractionId']},'limit':0x1,'include':[{'model':_0x162eea[_0xedac('0x16')],'as':_0xedac('0x1b'),'attributes':_[_0xedac('0x1c')](_0x594b11)}]}]});})[_0xedac('0x17')](function(_0x5a5438){_0x2676c3=_0x5a5438['get']({'plain':!![]});if(_0x2676c3&&_0x2676c3[_0xedac('0x1d')]){logger[_0xedac('0x1e')](_0xedac('0x1f'),_0xedac('0x20'),util[_0xedac('0x21')](_0xedac('0x22'),_0x27243f['id'],_0x2676c3[_0xedac('0x1d')]));if(_0x2676c3[_0xedac('0x23')]&&_0x2676c3['Interactions'][_0xedac('0x24')]){_0x27243f['Interaction']=_[_0xedac('0x25')](_0x2676c3[_0xedac('0x23')][0x0],'Contact');_0x27243f[_0xedac('0x1b')]=_0x2676c3[_0xedac('0x23')][0x0][_0xedac('0x1b')];}var _0x4081c6={'method':_0xedac('0x26'),'uri':encodeURI(_0x2676c3[_0xedac('0x1d')]),'json':!![],'resolveWithFullResponse':!![]};switch(_0x4081c6['method']){case _0xedac('0x27'):_0x4081c6['qs']=_0x27243f;break;case _0xedac('0x26'):_0x4081c6[_0xedac('0x13')]=_0x27243f;break;}return rp(_0x4081c6)[_0xedac('0x17')](function(_0x1ff33e){logger[_0xedac('0x1e')](_0xedac('0x1f'),_0xedac('0x20'),util[_0xedac('0x21')](_0xedac('0x28'),_0x27243f['id'],_0x2676c3['replyUri']));return _0x5ecbd3[_0xedac('0x11')]({'read':!![]});})[_0xedac('0x14')](function(_0x19aed3){logger['error'](_0xedac('0x1f'),'afterCreate',util['inspect'](_0x19aed3,{'showHidden':![],'depth':null}));_0x21440e();});}else{_0x21440e();}})[_0xedac('0x29')](function(){_0x21440e();});}else{_0x21440e();}}},'charset':_0xedac('0x2a'),'collate':_0xedac('0x2b')});};