Built motion from commit da24aabd.|2.6.20
[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 _0x62f0=['../../mysqldb','../../config/logger','rpc','../../config/environment','jayson/promise','client','request','then','Template,\x20%s,\x20%s','request\x20sent','debug','Template,\x20%s,\x20%s,\x20%s','stringify','error','code','message','info','catch','Template','findAll','options','where','include','map','model','attributes','GetTemplate','moment','bluebird','randomstring','ioredis'];(function(_0x279676,_0x5ab5eb){var _0x29aea5=function(_0x13d485){while(--_0x13d485){_0x279676['push'](_0x279676['shift']());}};_0x29aea5(++_0x5ab5eb);}(_0x62f0,0x1ae));var _0x062f=function(_0x427352,_0x1bce61){_0x427352=_0x427352-0x0;var _0x23e0e6=_0x62f0[_0x427352];return _0x23e0e6;};'use strict';var _=require('lodash');var util=require('util');var moment=require(_0x062f('0x0'));var BPromise=require(_0x062f('0x1'));var rs=require(_0x062f('0x2'));var fs=require('fs');var Redis=require(_0x062f('0x3'));var db=require(_0x062f('0x4'))['db'];var utils=require('../../config/utils');var logger=require(_0x062f('0x5'))(_0x062f('0x6'));var config=require(_0x062f('0x7'));var jayson=require(_0x062f('0x8'));var client=jayson[_0x062f('0x9')]['http']({'port':0x232a});function respondWithRpcPromise(_0x10f7a0,_0x582088,_0x1209f6){return new BPromise(function(_0x36dcc7,_0x3fb188){return client[_0x062f('0xa')](_0x10f7a0,_0x1209f6)[_0x062f('0xb')](function(_0x6810bb){logger['info'](_0x062f('0xc'),_0x582088,_0x062f('0xd'));logger[_0x062f('0xe')](_0x062f('0xf'),_0x582088,'request\x20sent',JSON[_0x062f('0x10')](_0x6810bb));if(_0x6810bb[_0x062f('0x11')]){if(_0x6810bb[_0x062f('0x11')][_0x062f('0x12')]===0x1f4){logger['error'](_0x062f('0xc'),_0x582088,_0x6810bb[_0x062f('0x11')][_0x062f('0x13')]);return _0x3fb188(_0x6810bb['error']['message']);}logger[_0x062f('0x11')](_0x062f('0xc'),_0x582088,_0x6810bb[_0x062f('0x11')][_0x062f('0x13')]);return _0x36dcc7(_0x6810bb[_0x062f('0x11')][_0x062f('0x13')]);}else{logger[_0x062f('0x14')]('Template,\x20%s,\x20%s',_0x582088,'request\x20sent');_0x36dcc7(_0x6810bb['result'][_0x062f('0x13')]);}})[_0x062f('0x15')](function(_0x573c45){logger[_0x062f('0x11')]('Template,\x20%s,\x20%s',_0x582088,_0x573c45);_0x3fb188(_0x573c45);});});}exports['GetTemplate']=function(_0x51f508){var _0xc57137=this;return new Promise(function(_0x20dd63,_0x280f1d){return db[_0x062f('0x16')][_0x062f('0x17')]({'raw':_0x51f508[_0x062f('0x18')]?_0x51f508[_0x062f('0x18')]['raw']===undefined?!![]:![]:!![],'where':_0x51f508['options']?_0x51f508[_0x062f('0x18')][_0x062f('0x19')]||null:null,'attributes':_0x51f508[_0x062f('0x18')]?_0x51f508['options']['attributes']||null:null,'limit':_0x51f508[_0x062f('0x18')]?_0x51f508[_0x062f('0x18')]['limit']||null:null,'include':_0x51f508[_0x062f('0x18')]?_0x51f508['options'][_0x062f('0x1a')]?_[_0x062f('0x1b')](_0x51f508[_0x062f('0x18')][_0x062f('0x1a')],function(_0x3f2500){return{'model':db[_0x3f2500[_0x062f('0x1c')]],'as':_0x3f2500['as'],'attributes':_0x3f2500[_0x062f('0x1d')],'include':_0x3f2500[_0x062f('0x1a')]?_[_0x062f('0x1b')](_0x3f2500[_0x062f('0x1a')],function(_0x50dd43){return{'model':db[_0x50dd43[_0x062f('0x1c')]],'as':_0x50dd43['as'],'attributes':_0x50dd43[_0x062f('0x1d')],'include':_0x50dd43[_0x062f('0x1a')]?_[_0x062f('0x1b')](_0x50dd43[_0x062f('0x1a')],function(_0x21d56a){return{'model':db[_0x21d56a[_0x062f('0x1c')]],'as':_0x21d56a['as'],'attributes':_0x21d56a[_0x062f('0x1d')]};}):[]};}):[]};}):[]:[]})[_0x062f('0xb')](function(_0x169ba9){logger[_0x062f('0x14')](_0x062f('0x1e'),_0x51f508);logger[_0x062f('0xe')]('GetTemplate',_0x51f508,JSON[_0x062f('0x10')](_0x169ba9));_0x20dd63(_0x169ba9);})[_0x062f('0x15')](function(_0x46830f){logger[_0x062f('0x11')](_0x062f('0x1e'),_0x46830f[_0x062f('0x13')],_0x51f508);_0x280f1d(_0xc57137[_0x062f('0x11')](0x1f4,_0x46830f['message']));});});};