f366339148ce7bfa6fd83e973c5e5e5e9fceab2d
[motion2.git] / server / api / squareProject / squareProject.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 _0x7b34=['info','SquareProject,\x20%s,\x20%s','request\x20sent','debug','stringify','error','code','message','catch','ShowSquareProject','SquareProject','find','options','where','attributes','map','model','include','lodash','randomstring','ioredis','../../config/utils','../../config/logger','rpc','../../config/environment','jayson/promise','client','http','redis','defaults','./squareProject.socket','register','request','then'];(function(_0x52ca87,_0x412bca){var _0x197520=function(_0x13b7b6){while(--_0x13b7b6){_0x52ca87['push'](_0x52ca87['shift']());}};_0x197520(++_0x412bca);}(_0x7b34,0x1cc));var _0x47b3=function(_0x1d8caa,_0x169515){_0x1d8caa=_0x1d8caa-0x0;var _0x6b833c=_0x7b34[_0x1d8caa];return _0x6b833c;};'use strict';var _=require(_0x47b3('0x0'));var util=require('util');var moment=require('moment');var BPromise=require('bluebird');var rs=require(_0x47b3('0x1'));var fs=require('fs');var Redis=require(_0x47b3('0x2'));var db=require('../../mysqldb')['db'];var utils=require(_0x47b3('0x3'));var logger=require(_0x47b3('0x4'))(_0x47b3('0x5'));var config=require(_0x47b3('0x6'));var jayson=require(_0x47b3('0x7'));var client=jayson[_0x47b3('0x8')][_0x47b3('0x9')]({'port':0x232a});config[_0x47b3('0xa')]=_[_0x47b3('0xb')](config[_0x47b3('0xa')],{'host':'localhost','port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config['redis']));require(_0x47b3('0xc'))[_0x47b3('0xd')](socket);function respondWithRpcPromise(_0x2ddded,_0x336417,_0x20a08b){return new BPromise(function(_0x1cdce5,_0x2ce3c9){return client[_0x47b3('0xe')](_0x2ddded,_0x20a08b)[_0x47b3('0xf')](function(_0x44c1b2){logger[_0x47b3('0x10')](_0x47b3('0x11'),_0x336417,_0x47b3('0x12'));logger[_0x47b3('0x13')]('SquareProject,\x20%s,\x20%s,\x20%s',_0x336417,_0x47b3('0x12'),JSON[_0x47b3('0x14')](_0x44c1b2));if(_0x44c1b2[_0x47b3('0x15')]){if(_0x44c1b2[_0x47b3('0x15')][_0x47b3('0x16')]===0x1f4){logger['error'](_0x47b3('0x11'),_0x336417,_0x44c1b2[_0x47b3('0x15')][_0x47b3('0x17')]);return _0x2ce3c9(_0x44c1b2['error'][_0x47b3('0x17')]);}logger[_0x47b3('0x15')]('SquareProject,\x20%s,\x20%s',_0x336417,_0x44c1b2[_0x47b3('0x15')][_0x47b3('0x17')]);return _0x1cdce5(_0x44c1b2[_0x47b3('0x15')][_0x47b3('0x17')]);}else{logger[_0x47b3('0x10')]('SquareProject,\x20%s,\x20%s',_0x336417,_0x47b3('0x12'));_0x1cdce5(_0x44c1b2['result']['message']);}})[_0x47b3('0x18')](function(_0x37da85){logger['error']('SquareProject,\x20%s,\x20%s',_0x336417,_0x37da85);_0x2ce3c9(_0x37da85);});});}exports[_0x47b3('0x19')]=function(_0x35e4b9){var _0x1fe028=this;return new Promise(function(_0x54e961,_0x1b57ad){return db[_0x47b3('0x1a')][_0x47b3('0x1b')]({'raw':_0x35e4b9[_0x47b3('0x1c')]?_0x35e4b9[_0x47b3('0x1c')]['raw']===undefined?!![]:![]:!![],'where':_0x35e4b9[_0x47b3('0x1c')]?_0x35e4b9[_0x47b3('0x1c')][_0x47b3('0x1d')]||null:null,'attributes':_0x35e4b9[_0x47b3('0x1c')]?_0x35e4b9[_0x47b3('0x1c')][_0x47b3('0x1e')]||null:null,'include':_0x35e4b9[_0x47b3('0x1c')]?_0x35e4b9['options']['include']?_[_0x47b3('0x1f')](_0x35e4b9[_0x47b3('0x1c')]['include'],function(_0x3eb35c){return{'model':db[_0x3eb35c[_0x47b3('0x20')]],'as':_0x3eb35c['as'],'attributes':_0x3eb35c[_0x47b3('0x1e')],'include':_0x3eb35c[_0x47b3('0x21')]?_[_0x47b3('0x1f')](_0x3eb35c[_0x47b3('0x21')],function(_0x30db34){return{'model':db[_0x30db34['model']],'as':_0x30db34['as'],'attributes':_0x30db34[_0x47b3('0x1e')],'include':_0x30db34[_0x47b3('0x21')]?_[_0x47b3('0x1f')](_0x30db34[_0x47b3('0x21')],function(_0xa0b092){return{'model':db[_0xa0b092[_0x47b3('0x20')]],'as':_0xa0b092['as'],'attributes':_0xa0b092[_0x47b3('0x1e')]};}):[]};}):[]};}):[]:[]})['then'](function(_0x4e7a1c){logger['info'](_0x47b3('0x19'),_0x35e4b9);logger['debug'](_0x47b3('0x19'),_0x35e4b9,JSON['stringify'](_0x4e7a1c));_0x54e961(_0x4e7a1c);})['catch'](function(_0x1428b6){logger[_0x47b3('0x15')]('ShowSquareProject',_0x1428b6['message'],_0x35e4b9);_0x1b57ad(_0x1fe028['error'](0x1f4,_0x1428b6[_0x47b3('0x17')]));});});};