ae25af10d7a9e8405d77bda8d9c41b06b6a0d437
[motion2.git] / server / api / template / template.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 _0x680f=['ioredis','../../mysqldb','../../config/utils','jayson/promise','client','http','request','then','info','Template,\x20%s,\x20%s','debug','request\x20sent','error','code','message','result','catch','GetTemplate','Template','options','raw','attributes','limit','include','model','map','stringify','lodash','util','moment','randomstring'];(function(_0xee2e7a,_0x58354d){var _0x319dd3=function(_0xa99240){while(--_0xa99240){_0xee2e7a['push'](_0xee2e7a['shift']());}};_0x319dd3(++_0x58354d);}(_0x680f,0x78));var _0xf680=function(_0x323a4f,_0x5ad87f){_0x323a4f=_0x323a4f-0x0;var _0x3c07a3=_0x680f[_0x323a4f];return _0x3c07a3;};'use strict';var _=require(_0xf680('0x0'));var util=require(_0xf680('0x1'));var moment=require(_0xf680('0x2'));var BPromise=require('bluebird');var rs=require(_0xf680('0x3'));var fs=require('fs');var Redis=require(_0xf680('0x4'));var db=require(_0xf680('0x5'))['db'];var utils=require(_0xf680('0x6'));var logger=require('../../config/logger')('rpc');var config=require('../../config/environment');var jayson=require(_0xf680('0x7'));var client=jayson[_0xf680('0x8')][_0xf680('0x9')]({'port':0x232a});function respondWithRpcPromise(_0x57f5de,_0x3951ab,_0x43241f){return new BPromise(function(_0x4ff382,_0x1450d7){return client[_0xf680('0xa')](_0x57f5de,_0x43241f)[_0xf680('0xb')](function(_0x1730b8){logger[_0xf680('0xc')](_0xf680('0xd'),_0x3951ab,'request\x20sent');logger[_0xf680('0xe')]('Template,\x20%s,\x20%s,\x20%s',_0x3951ab,_0xf680('0xf'),JSON['stringify'](_0x1730b8));if(_0x1730b8[_0xf680('0x10')]){if(_0x1730b8[_0xf680('0x10')][_0xf680('0x11')]===0x1f4){logger[_0xf680('0x10')](_0xf680('0xd'),_0x3951ab,_0x1730b8[_0xf680('0x10')][_0xf680('0x12')]);return _0x1450d7(_0x1730b8[_0xf680('0x10')][_0xf680('0x12')]);}logger[_0xf680('0x10')](_0xf680('0xd'),_0x3951ab,_0x1730b8[_0xf680('0x10')][_0xf680('0x12')]);return _0x4ff382(_0x1730b8['error'][_0xf680('0x12')]);}else{logger[_0xf680('0xc')]('Template,\x20%s,\x20%s',_0x3951ab,_0xf680('0xf'));_0x4ff382(_0x1730b8[_0xf680('0x13')][_0xf680('0x12')]);}})[_0xf680('0x14')](function(_0x2acdd5){logger['error']('Template,\x20%s,\x20%s',_0x3951ab,_0x2acdd5);_0x1450d7(_0x2acdd5);});});}exports[_0xf680('0x15')]=function(_0x49672a){var _0x5d7e0e=this;return new Promise(function(_0x1c5f71,_0x297910){return db[_0xf680('0x16')]['findAll']({'raw':_0x49672a[_0xf680('0x17')]?_0x49672a[_0xf680('0x17')][_0xf680('0x18')]===undefined?!![]:![]:!![],'where':_0x49672a[_0xf680('0x17')]?_0x49672a['options']['where']||null:null,'attributes':_0x49672a[_0xf680('0x17')]?_0x49672a['options'][_0xf680('0x19')]||null:null,'limit':_0x49672a['options']?_0x49672a[_0xf680('0x17')][_0xf680('0x1a')]||null:null,'include':_0x49672a[_0xf680('0x17')]?_0x49672a[_0xf680('0x17')]['include']?_['map'](_0x49672a[_0xf680('0x17')][_0xf680('0x1b')],function(_0x570360){return{'model':db[_0x570360[_0xf680('0x1c')]],'as':_0x570360['as'],'attributes':_0x570360[_0xf680('0x19')],'include':_0x570360[_0xf680('0x1b')]?_[_0xf680('0x1d')](_0x570360['include'],function(_0x217094){return{'model':db[_0x217094['model']],'as':_0x217094['as'],'attributes':_0x217094[_0xf680('0x19')],'include':_0x217094[_0xf680('0x1b')]?_[_0xf680('0x1d')](_0x217094[_0xf680('0x1b')],function(_0x222cd5){return{'model':db[_0x222cd5['model']],'as':_0x222cd5['as'],'attributes':_0x222cd5[_0xf680('0x19')]};}):[]};}):[]};}):[]:[]})[_0xf680('0xb')](function(_0x537dd3){logger[_0xf680('0xc')](_0xf680('0x15'),_0x49672a);logger['debug'](_0xf680('0x15'),_0x49672a,JSON[_0xf680('0x1e')](_0x537dd3));_0x1c5f71(_0x537dd3);})[_0xf680('0x14')](function(_0x6eb3d7){logger[_0xf680('0x10')]('GetTemplate',_0x6eb3d7[_0xf680('0x12')],_0x49672a);_0x297910(_0x5d7e0e[_0xf680('0x10')](0x1f4,_0x6eb3d7['message']));});});};