e477ebbfff214a992d151974df562692e69aa718
[motion2.git] / server / api / faxInteraction / faxInteraction.rpc.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 _0x7823=['ids','omit','spread','AddTags','util','moment','randomstring','../../mysqldb','../../config/utils','rpc','../../config/environment','jayson/promise','client','http','defaults','redis','socket.io-emitter','./faxInteraction.socket','register','request','then','info','FaxInteraction,\x20%s,\x20%s','request\x20sent','debug','FaxInteraction,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','catch','UpdateFaxInteraction','FaxInteraction','update','body','options','raw','attributes','find','where','addTags'];(function(_0x454fe7,_0x492eba){var _0x30f729=function(_0x54f9c1){while(--_0x54f9c1){_0x454fe7['push'](_0x454fe7['shift']());}};_0x30f729(++_0x492eba);}(_0x7823,0xac));var _0x3782=function(_0xbca1b1,_0x33f0ce){_0xbca1b1=_0xbca1b1-0x0;var _0x4e1686=_0x7823[_0xbca1b1];return _0x4e1686;};'use strict';var _=require('lodash');var util=require(_0x3782('0x0'));var moment=require(_0x3782('0x1'));var BPromise=require('bluebird');var rs=require(_0x3782('0x2'));var fs=require('fs');var Redis=require('ioredis');var db=require(_0x3782('0x3'))['db'];var utils=require(_0x3782('0x4'));var logger=require('../../config/logger')(_0x3782('0x5'));var config=require(_0x3782('0x6'));var jayson=require(_0x3782('0x7'));var client=jayson[_0x3782('0x8')][_0x3782('0x9')]({'port':0x232a});config['redis']=_[_0x3782('0xa')](config[_0x3782('0xb')],{'host':'localhost','port':0x18eb});var socket=require(_0x3782('0xc'))(new Redis(config[_0x3782('0xb')]));require(_0x3782('0xd'))[_0x3782('0xe')](socket);function respondWithRpcPromise(_0x728539,_0x500f3c,_0x546341){return new BPromise(function(_0x39d518,_0x47e94d){return client[_0x3782('0xf')](_0x728539,_0x546341)[_0x3782('0x10')](function(_0x3f639d){logger[_0x3782('0x11')](_0x3782('0x12'),_0x500f3c,_0x3782('0x13'));logger[_0x3782('0x14')](_0x3782('0x15'),_0x500f3c,'request\x20sent',JSON[_0x3782('0x16')](_0x3f639d));if(_0x3f639d[_0x3782('0x17')]){if(_0x3f639d['error'][_0x3782('0x18')]===0x1f4){logger['error'](_0x3782('0x12'),_0x500f3c,_0x3f639d[_0x3782('0x17')][_0x3782('0x19')]);return _0x47e94d(_0x3f639d[_0x3782('0x17')][_0x3782('0x19')]);}logger['error'](_0x3782('0x12'),_0x500f3c,_0x3f639d[_0x3782('0x17')][_0x3782('0x19')]);return _0x39d518(_0x3f639d['error']['message']);}else{logger[_0x3782('0x11')](_0x3782('0x12'),_0x500f3c,_0x3782('0x13'));_0x39d518(_0x3f639d[_0x3782('0x1a')][_0x3782('0x19')]);}})[_0x3782('0x1b')](function(_0x460d38){logger['error'](_0x3782('0x12'),_0x500f3c,_0x460d38);_0x47e94d(_0x460d38);});});}exports[_0x3782('0x1c')]=function(_0x492f54){var _0x810c79=this;return new Promise(function(_0x2e395f,_0x585d0a){return db[_0x3782('0x1d')][_0x3782('0x1e')](_0x492f54[_0x3782('0x1f')],{'raw':_0x492f54[_0x3782('0x20')]?_0x492f54[_0x3782('0x20')][_0x3782('0x21')]===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x492f54['options']?_0x492f54[_0x3782('0x20')]['where']||null:null,'attributes':_0x492f54[_0x3782('0x20')]?_0x492f54[_0x3782('0x20')][_0x3782('0x22')]||null:null,'limit':_0x492f54[_0x3782('0x20')]?_0x492f54[_0x3782('0x20')]['limit']||null:null})[_0x3782('0x10')](function(_0x5587db){logger['info'](_0x3782('0x1c'),_0x492f54);logger[_0x3782('0x14')](_0x3782('0x1c'),_0x492f54,JSON[_0x3782('0x16')](_0x5587db));_0x2e395f(_0x5587db);})['catch'](function(_0xe9078e){logger[_0x3782('0x17')](_0x3782('0x1c'),_0xe9078e[_0x3782('0x19')],_0x492f54);_0x585d0a(_0x810c79[_0x3782('0x17')](0x1f4,_0xe9078e[_0x3782('0x19')]));});});};exports['AddTagsToFaxInteraction']=function(_0x2f5264){return new Promise(function(_0x41c533,_0x1b1c49){return db['FaxInteraction'][_0x3782('0x23')]({'where':_0x2f5264[_0x3782('0x20')]?_0x2f5264['options'][_0x3782('0x24')]||null:null})[_0x3782('0x10')](function(_0x1c63b1){if(_0x1c63b1){return _0x1c63b1[_0x3782('0x25')](_0x2f5264['body'][_0x3782('0x26')],_[_0x3782('0x27')](_0x2f5264['body'],[_0x3782('0x26'),'id'])||{});}})[_0x3782('0x28')](function(_0x3a24a2){logger['info']('AddTags',_0x2f5264);logger[_0x3782('0x14')](_0x3782('0x29'),_0x2f5264,JSON[_0x3782('0x16')](_0x3a24a2));_0x41c533(_0x3a24a2);})[_0x3782('0x1b')](function(_0x1398f8){logger[_0x3782('0x17')](_0x3782('0x29'),_0x1398f8['message'],_0x2f5264);_0x1b1c49(_this[_0x3782('0x17')](0x1f4,_0x1398f8[_0x3782('0x19')]));});});};