5e337824a2f36573e42e9cd8c346d13926a53663
[motion2.git] / server / api / cmContact / cmContact.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 _0x386c=['request\x20sent','debug','stringify','error','message','result','catch','ShowCmContact','CmContact','options','raw','where','include','map','attributes','model','then','info','CreateCmContact','create','body','lodash','util','moment','bluebird','randomstring','ioredis','../../config/logger','rpc','../../config/environment','jayson/promise','client','http','redis','defaults','localhost','socket.io-emitter','./cmContact.socket','request','CmContact,\x20%s,\x20%s'];(function(_0x15c103,_0x27f243){var _0x4123b8=function(_0x53a347){while(--_0x53a347){_0x15c103['push'](_0x15c103['shift']());}};_0x4123b8(++_0x27f243);}(_0x386c,0x65));var _0xc386=function(_0x1cc8fe,_0x105328){_0x1cc8fe=_0x1cc8fe-0x0;var _0x230054=_0x386c[_0x1cc8fe];return _0x230054;};'use strict';var _=require(_0xc386('0x0'));var util=require(_0xc386('0x1'));var moment=require(_0xc386('0x2'));var BPromise=require(_0xc386('0x3'));var rs=require(_0xc386('0x4'));var fs=require('fs');var Redis=require(_0xc386('0x5'));var db=require('../../mysqldb')['db'];var utils=require('../../config/utils');var logger=require(_0xc386('0x6'))(_0xc386('0x7'));var config=require(_0xc386('0x8'));var jayson=require(_0xc386('0x9'));var client=jayson[_0xc386('0xa')][_0xc386('0xb')]({'port':0x232a});config[_0xc386('0xc')]=_[_0xc386('0xd')](config[_0xc386('0xc')],{'host':_0xc386('0xe'),'port':0x18eb});var socket=require(_0xc386('0xf'))(new Redis(config[_0xc386('0xc')]));require(_0xc386('0x10'))['register'](socket);function respondWithRpcPromise(_0x2e8ef8,_0x1ba4ed,_0x5b82bf){return new BPromise(function(_0x256162,_0xf6e6e8){return client[_0xc386('0x11')](_0x2e8ef8,_0x5b82bf)['then'](function(_0x1d64ef){logger['info'](_0xc386('0x12'),_0x1ba4ed,_0xc386('0x13'));logger[_0xc386('0x14')]('CmContact,\x20%s,\x20%s,\x20%s',_0x1ba4ed,_0xc386('0x13'),JSON[_0xc386('0x15')](_0x1d64ef));if(_0x1d64ef[_0xc386('0x16')]){if(_0x1d64ef[_0xc386('0x16')]['code']===0x1f4){logger[_0xc386('0x16')](_0xc386('0x12'),_0x1ba4ed,_0x1d64ef[_0xc386('0x16')][_0xc386('0x17')]);return _0xf6e6e8(_0x1d64ef['error'][_0xc386('0x17')]);}logger[_0xc386('0x16')](_0xc386('0x12'),_0x1ba4ed,_0x1d64ef[_0xc386('0x16')][_0xc386('0x17')]);return _0x256162(_0x1d64ef[_0xc386('0x16')][_0xc386('0x17')]);}else{logger['info'](_0xc386('0x12'),_0x1ba4ed,_0xc386('0x13'));_0x256162(_0x1d64ef[_0xc386('0x18')][_0xc386('0x17')]);}})[_0xc386('0x19')](function(_0x35c98c){logger['error'](_0xc386('0x12'),_0x1ba4ed,_0x35c98c);_0xf6e6e8(_0x35c98c);});});}exports[_0xc386('0x1a')]=function(_0x793995){var _0x46a422=this;return new Promise(function(_0x3c0f6a,_0x447b6c){return db[_0xc386('0x1b')]['find']({'raw':_0x793995[_0xc386('0x1c')]?_0x793995[_0xc386('0x1c')][_0xc386('0x1d')]===undefined?!![]:![]:!![],'where':_0x793995['options']?_0x793995[_0xc386('0x1c')][_0xc386('0x1e')]||null:null,'attributes':_0x793995['options']?_0x793995[_0xc386('0x1c')]['attributes']||null:null,'include':_0x793995['options']?_0x793995[_0xc386('0x1c')][_0xc386('0x1f')]?_[_0xc386('0x20')](_0x793995[_0xc386('0x1c')][_0xc386('0x1f')],function(_0x2c2898){return{'model':db[_0x2c2898['model']],'as':_0x2c2898['as'],'attributes':_0x2c2898[_0xc386('0x21')],'include':_0x2c2898[_0xc386('0x1f')]?_['map'](_0x2c2898[_0xc386('0x1f')],function(_0xb0c151){return{'model':db[_0xb0c151['model']],'as':_0xb0c151['as'],'attributes':_0xb0c151[_0xc386('0x21')],'include':_0xb0c151[_0xc386('0x1f')]?_[_0xc386('0x20')](_0xb0c151['include'],function(_0x44ecaf){return{'model':db[_0x44ecaf[_0xc386('0x22')]],'as':_0x44ecaf['as'],'attributes':_0x44ecaf[_0xc386('0x21')]};}):[]};}):[]};}):[]:[]})[_0xc386('0x23')](function(_0x50e19c){logger[_0xc386('0x24')](_0xc386('0x1a'),_0x793995);logger[_0xc386('0x14')](_0xc386('0x1a'),_0x793995,JSON['stringify'](_0x50e19c));_0x3c0f6a(_0x50e19c);})[_0xc386('0x19')](function(_0x121b20){logger[_0xc386('0x16')](_0xc386('0x1a'),_0x121b20[_0xc386('0x17')],_0x793995);_0x447b6c(_0x46a422[_0xc386('0x16')](0x1f4,_0x121b20['message']));});});};exports[_0xc386('0x25')]=function(_0x247dfe){var _0x2af975=this;return new Promise(function(_0x55d2a2,_0x55ec7c){return db['CmContact'][_0xc386('0x26')](_0x247dfe[_0xc386('0x27')],{'raw':_0x247dfe[_0xc386('0x1c')]?_0x247dfe['options'][_0xc386('0x1d')]===undefined?!![]:![]:!![]})['then'](function(_0xfc4cc8){logger['info']('CreateCmContact',_0x247dfe);logger[_0xc386('0x14')](_0xc386('0x25'),_0x247dfe,JSON[_0xc386('0x15')](_0xfc4cc8));_0x55d2a2(_0xfc4cc8);})[_0xc386('0x19')](function(_0x5ee94d){logger[_0xc386('0x16')](_0xc386('0x25'),_0x5ee94d[_0xc386('0x17')],_0x247dfe);_0x55ec7c(_0x2af975['error'](0x1f4,_0x5ee94d[_0xc386('0x17')]));});});};