a29c9cad6856faa00dc1b55582e6346749c46c31
[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 _0xb3d7=['bluebird','randomstring','ioredis','../../config/utils','../../config/logger','rpc','../../config/environment','jayson/promise','client','redis','defaults','socket.io-emitter','./cmContact.socket','register','request','then','CmContact,\x20%s,\x20%s','request\x20sent','stringify','error','code','message','info','result','catch','ShowCmContact','CmContact','find','options','raw','attributes','include','model','map','CreateCmContact','debug','lodash','util','moment'];(function(_0x5cbd7b,_0x207439){var _0x3fdfb8=function(_0x4eb12e){while(--_0x4eb12e){_0x5cbd7b['push'](_0x5cbd7b['shift']());}};_0x3fdfb8(++_0x207439);}(_0xb3d7,0x1d1));var _0x7b3d=function(_0xd5a301,_0x2a266d){_0xd5a301=_0xd5a301-0x0;var _0x356568=_0xb3d7[_0xd5a301];return _0x356568;};'use strict';var _=require(_0x7b3d('0x0'));var util=require(_0x7b3d('0x1'));var moment=require(_0x7b3d('0x2'));var BPromise=require(_0x7b3d('0x3'));var rs=require(_0x7b3d('0x4'));var fs=require('fs');var Redis=require(_0x7b3d('0x5'));var db=require('../../mysqldb')['db'];var utils=require(_0x7b3d('0x6'));var logger=require(_0x7b3d('0x7'))(_0x7b3d('0x8'));var config=require(_0x7b3d('0x9'));var jayson=require(_0x7b3d('0xa'));var client=jayson[_0x7b3d('0xb')]['http']({'port':0x232a});config[_0x7b3d('0xc')]=_[_0x7b3d('0xd')](config[_0x7b3d('0xc')],{'host':'localhost','port':0x18eb});var socket=require(_0x7b3d('0xe'))(new Redis(config[_0x7b3d('0xc')]));require(_0x7b3d('0xf'))[_0x7b3d('0x10')](socket);function respondWithRpcPromise(_0x2878d1,_0x3a9509,_0x52e35c){return new BPromise(function(_0x345a5d,_0x47438e){return client[_0x7b3d('0x11')](_0x2878d1,_0x52e35c)[_0x7b3d('0x12')](function(_0x2b1449){logger['info'](_0x7b3d('0x13'),_0x3a9509,_0x7b3d('0x14'));logger['debug']('CmContact,\x20%s,\x20%s,\x20%s',_0x3a9509,_0x7b3d('0x14'),JSON[_0x7b3d('0x15')](_0x2b1449));if(_0x2b1449[_0x7b3d('0x16')]){if(_0x2b1449['error'][_0x7b3d('0x17')]===0x1f4){logger[_0x7b3d('0x16')](_0x7b3d('0x13'),_0x3a9509,_0x2b1449[_0x7b3d('0x16')]['message']);return _0x47438e(_0x2b1449[_0x7b3d('0x16')][_0x7b3d('0x18')]);}logger[_0x7b3d('0x16')](_0x7b3d('0x13'),_0x3a9509,_0x2b1449['error'][_0x7b3d('0x18')]);return _0x345a5d(_0x2b1449[_0x7b3d('0x16')]['message']);}else{logger[_0x7b3d('0x19')](_0x7b3d('0x13'),_0x3a9509,_0x7b3d('0x14'));_0x345a5d(_0x2b1449[_0x7b3d('0x1a')][_0x7b3d('0x18')]);}})[_0x7b3d('0x1b')](function(_0x314ff4){logger[_0x7b3d('0x16')](_0x7b3d('0x13'),_0x3a9509,_0x314ff4);_0x47438e(_0x314ff4);});});}exports[_0x7b3d('0x1c')]=function(_0x3be9c0){var _0x5c630b=this;return new Promise(function(_0x48d3b1,_0x2ec0dc){return db[_0x7b3d('0x1d')][_0x7b3d('0x1e')]({'raw':_0x3be9c0['options']?_0x3be9c0[_0x7b3d('0x1f')][_0x7b3d('0x20')]===undefined?!![]:![]:!![],'where':_0x3be9c0[_0x7b3d('0x1f')]?_0x3be9c0[_0x7b3d('0x1f')]['where']||null:null,'attributes':_0x3be9c0[_0x7b3d('0x1f')]?_0x3be9c0['options'][_0x7b3d('0x21')]||null:null,'include':_0x3be9c0['options']?_0x3be9c0['options'][_0x7b3d('0x22')]?_['map'](_0x3be9c0[_0x7b3d('0x1f')][_0x7b3d('0x22')],function(_0x37b313){return{'model':db[_0x37b313[_0x7b3d('0x23')]],'as':_0x37b313['as'],'attributes':_0x37b313[_0x7b3d('0x21')],'include':_0x37b313[_0x7b3d('0x22')]?_[_0x7b3d('0x24')](_0x37b313[_0x7b3d('0x22')],function(_0x1258e4){return{'model':db[_0x1258e4[_0x7b3d('0x23')]],'as':_0x1258e4['as'],'attributes':_0x1258e4[_0x7b3d('0x21')],'include':_0x1258e4[_0x7b3d('0x22')]?_['map'](_0x1258e4[_0x7b3d('0x22')],function(_0x38c01a){return{'model':db[_0x38c01a[_0x7b3d('0x23')]],'as':_0x38c01a['as'],'attributes':_0x38c01a['attributes']};}):[]};}):[]};}):[]:[]})[_0x7b3d('0x12')](function(_0x287dd9){logger['info'](_0x7b3d('0x1c'),_0x3be9c0);logger['debug']('ShowCmContact',_0x3be9c0,JSON[_0x7b3d('0x15')](_0x287dd9));_0x48d3b1(_0x287dd9);})[_0x7b3d('0x1b')](function(_0x33892f){logger['error'](_0x7b3d('0x1c'),_0x33892f['message'],_0x3be9c0);_0x2ec0dc(_0x5c630b[_0x7b3d('0x16')](0x1f4,_0x33892f['message']));});});};exports[_0x7b3d('0x25')]=function(_0x2e5282){var _0x11d806=this;return new Promise(function(_0x2fb00d,_0x2c2762){return db['CmContact']['create'](_0x2e5282['body'],{'raw':_0x2e5282[_0x7b3d('0x1f')]?_0x2e5282[_0x7b3d('0x1f')][_0x7b3d('0x20')]===undefined?!![]:![]:!![]})['then'](function(_0x1c1fbe){logger[_0x7b3d('0x19')](_0x7b3d('0x25'),_0x2e5282);logger[_0x7b3d('0x26')](_0x7b3d('0x25'),_0x2e5282,JSON[_0x7b3d('0x15')](_0x1c1fbe));_0x2fb00d(_0x1c1fbe);})[_0x7b3d('0x1b')](function(_0x227aa6){logger[_0x7b3d('0x16')](_0x7b3d('0x25'),_0x227aa6[_0x7b3d('0x18')],_0x2e5282);_0x2c2762(_0x11d806['error'](0x1f4,_0x227aa6[_0x7b3d('0x18')]));});});};