85cee8ef9f3a365bbce9a92d9c1e9f61b313e7f3
[motion2.git] / server / api / squareOdbc / squareOdbc.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 _0xff74=['ioredis','../../mysqldb','rpc','client','http','request','SquareOdbc,\x20%s,\x20%s','request\x20sent','debug','SquareOdbc,\x20%s,\x20%s,\x20%s','stringify','error','code','message','info','catch','ShowSquareOdbc','SquareOdbc','find','options','where','attributes','map','model','include','then','moment','bluebird','randomstring'];(function(_0x2c94e6,_0x522d20){var _0x5eee3e=function(_0x3c7b8e){while(--_0x3c7b8e){_0x2c94e6['push'](_0x2c94e6['shift']());}};_0x5eee3e(++_0x522d20);}(_0xff74,0x1ea));var _0x4ff7=function(_0x263b35,_0x421508){_0x263b35=_0x263b35-0x0;var _0x48168e=_0xff74[_0x263b35];return _0x48168e;};'use strict';var _=require('lodash');var util=require('util');var moment=require(_0x4ff7('0x0'));var BPromise=require(_0x4ff7('0x1'));var rs=require(_0x4ff7('0x2'));var fs=require('fs');var Redis=require(_0x4ff7('0x3'));var db=require(_0x4ff7('0x4'))['db'];var utils=require('../../config/utils');var logger=require('../../config/logger')(_0x4ff7('0x5'));var config=require('../../config/environment');var jayson=require('jayson/promise');var client=jayson[_0x4ff7('0x6')][_0x4ff7('0x7')]({'port':0x232a});function respondWithRpcPromise(_0x58294b,_0x55e677,_0x47e6b5){return new BPromise(function(_0x3f68d3,_0x17aee0){return client[_0x4ff7('0x8')](_0x58294b,_0x47e6b5)['then'](function(_0x4d249d){logger['info'](_0x4ff7('0x9'),_0x55e677,_0x4ff7('0xa'));logger[_0x4ff7('0xb')](_0x4ff7('0xc'),_0x55e677,'request\x20sent',JSON[_0x4ff7('0xd')](_0x4d249d));if(_0x4d249d[_0x4ff7('0xe')]){if(_0x4d249d[_0x4ff7('0xe')][_0x4ff7('0xf')]===0x1f4){logger[_0x4ff7('0xe')](_0x4ff7('0x9'),_0x55e677,_0x4d249d[_0x4ff7('0xe')][_0x4ff7('0x10')]);return _0x17aee0(_0x4d249d[_0x4ff7('0xe')][_0x4ff7('0x10')]);}logger[_0x4ff7('0xe')](_0x4ff7('0x9'),_0x55e677,_0x4d249d[_0x4ff7('0xe')]['message']);return _0x3f68d3(_0x4d249d[_0x4ff7('0xe')][_0x4ff7('0x10')]);}else{logger[_0x4ff7('0x11')](_0x4ff7('0x9'),_0x55e677,_0x4ff7('0xa'));_0x3f68d3(_0x4d249d['result'][_0x4ff7('0x10')]);}})[_0x4ff7('0x12')](function(_0x3c05ae){logger['error'](_0x4ff7('0x9'),_0x55e677,_0x3c05ae);_0x17aee0(_0x3c05ae);});});}exports[_0x4ff7('0x13')]=function(_0x1914f9){var _0x1ffd59=this;return new Promise(function(_0x3873a0,_0x25a694){return db[_0x4ff7('0x14')][_0x4ff7('0x15')]({'raw':_0x1914f9[_0x4ff7('0x16')]?_0x1914f9[_0x4ff7('0x16')]['raw']===undefined?!![]:![]:!![],'where':_0x1914f9[_0x4ff7('0x16')]?_0x1914f9[_0x4ff7('0x16')][_0x4ff7('0x17')]||null:null,'attributes':_0x1914f9[_0x4ff7('0x16')]?_0x1914f9[_0x4ff7('0x16')][_0x4ff7('0x18')]||null:null,'include':_0x1914f9['options']?_0x1914f9[_0x4ff7('0x16')]['include']?_[_0x4ff7('0x19')](_0x1914f9[_0x4ff7('0x16')]['include'],function(_0x58033e){return{'model':db[_0x58033e[_0x4ff7('0x1a')]],'as':_0x58033e['as'],'attributes':_0x58033e[_0x4ff7('0x18')],'include':_0x58033e[_0x4ff7('0x1b')]?_[_0x4ff7('0x19')](_0x58033e['include'],function(_0x50fd2d){return{'model':db[_0x50fd2d[_0x4ff7('0x1a')]],'as':_0x50fd2d['as'],'attributes':_0x50fd2d[_0x4ff7('0x18')],'include':_0x50fd2d[_0x4ff7('0x1b')]?_[_0x4ff7('0x19')](_0x50fd2d[_0x4ff7('0x1b')],function(_0x10b40e){return{'model':db[_0x10b40e['model']],'as':_0x10b40e['as'],'attributes':_0x10b40e['attributes']};}):[]};}):[]};}):[]:[]})[_0x4ff7('0x1c')](function(_0xfc08ac){logger[_0x4ff7('0x11')]('ShowSquareOdbc',_0x1914f9);logger[_0x4ff7('0xb')]('ShowSquareOdbc',_0x1914f9,JSON['stringify'](_0xfc08ac));_0x3873a0(_0xfc08ac);})[_0x4ff7('0x12')](function(_0x4abaf4){logger[_0x4ff7('0xe')](_0x4ff7('0x13'),_0x4abaf4['message'],_0x1914f9);_0x25a694(_0x1ffd59[_0x4ff7('0xe')](0x1f4,_0x4abaf4[_0x4ff7('0x10')]));});});};