c9afdcb5e94bfb843a399fa77ac724852638dc23
[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 _0xf040=['ioredis','../../mysqldb','../../config/utils','../../config/logger','../../config/environment','jayson/promise','client','request','then','Template,\x20%s,\x20%s','request\x20sent','debug','Template,\x20%s,\x20%s,\x20%s','error','code','message','info','result','GetTemplate','findAll','options','raw','where','attributes','limit','include','model','map','catch','lodash','util','moment','bluebird','randomstring'];(function(_0x381188,_0x123b84){var _0x53598d=function(_0x59f3c6){while(--_0x59f3c6){_0x381188['push'](_0x381188['shift']());}};_0x53598d(++_0x123b84);}(_0xf040,0x193));var _0x0f04=function(_0x498219,_0x28eb06){_0x498219=_0x498219-0x0;var _0x1e04c6=_0xf040[_0x498219];return _0x1e04c6;};'use strict';var _=require(_0x0f04('0x0'));var util=require(_0x0f04('0x1'));var moment=require(_0x0f04('0x2'));var BPromise=require(_0x0f04('0x3'));var rs=require(_0x0f04('0x4'));var fs=require('fs');var Redis=require(_0x0f04('0x5'));var db=require(_0x0f04('0x6'))['db'];var utils=require(_0x0f04('0x7'));var logger=require(_0x0f04('0x8'))('rpc');var config=require(_0x0f04('0x9'));var jayson=require(_0x0f04('0xa'));var client=jayson[_0x0f04('0xb')]['http']({'port':0x232a});function respondWithRpcPromise(_0x502142,_0x41adda,_0x2754cf){return new BPromise(function(_0x376ec5,_0x500eb4){return client[_0x0f04('0xc')](_0x502142,_0x2754cf)[_0x0f04('0xd')](function(_0x2c7e97){logger['info'](_0x0f04('0xe'),_0x41adda,_0x0f04('0xf'));logger[_0x0f04('0x10')](_0x0f04('0x11'),_0x41adda,_0x0f04('0xf'),JSON['stringify'](_0x2c7e97));if(_0x2c7e97[_0x0f04('0x12')]){if(_0x2c7e97[_0x0f04('0x12')][_0x0f04('0x13')]===0x1f4){logger[_0x0f04('0x12')](_0x0f04('0xe'),_0x41adda,_0x2c7e97[_0x0f04('0x12')][_0x0f04('0x14')]);return _0x500eb4(_0x2c7e97['error']['message']);}logger[_0x0f04('0x12')](_0x0f04('0xe'),_0x41adda,_0x2c7e97['error'][_0x0f04('0x14')]);return _0x376ec5(_0x2c7e97[_0x0f04('0x12')]['message']);}else{logger[_0x0f04('0x15')](_0x0f04('0xe'),_0x41adda,'request\x20sent');_0x376ec5(_0x2c7e97[_0x0f04('0x16')][_0x0f04('0x14')]);}})['catch'](function(_0x43540e){logger[_0x0f04('0x12')]('Template,\x20%s,\x20%s',_0x41adda,_0x43540e);_0x500eb4(_0x43540e);});});}exports[_0x0f04('0x17')]=function(_0x19bd6d){var _0x1e59b1=this;return new Promise(function(_0x27f0c,_0x34e57a){return db['Template'][_0x0f04('0x18')]({'raw':_0x19bd6d[_0x0f04('0x19')]?_0x19bd6d[_0x0f04('0x19')][_0x0f04('0x1a')]===undefined?!![]:![]:!![],'where':_0x19bd6d['options']?_0x19bd6d[_0x0f04('0x19')][_0x0f04('0x1b')]||null:null,'attributes':_0x19bd6d['options']?_0x19bd6d[_0x0f04('0x19')][_0x0f04('0x1c')]||null:null,'limit':_0x19bd6d[_0x0f04('0x19')]?_0x19bd6d['options'][_0x0f04('0x1d')]||null:null,'include':_0x19bd6d[_0x0f04('0x19')]?_0x19bd6d[_0x0f04('0x19')][_0x0f04('0x1e')]?_['map'](_0x19bd6d[_0x0f04('0x19')][_0x0f04('0x1e')],function(_0x389d07){return{'model':db[_0x389d07[_0x0f04('0x1f')]],'as':_0x389d07['as'],'attributes':_0x389d07[_0x0f04('0x1c')],'include':_0x389d07[_0x0f04('0x1e')]?_[_0x0f04('0x20')](_0x389d07['include'],function(_0x17c7fe){return{'model':db[_0x17c7fe[_0x0f04('0x1f')]],'as':_0x17c7fe['as'],'attributes':_0x17c7fe[_0x0f04('0x1c')],'include':_0x17c7fe[_0x0f04('0x1e')]?_['map'](_0x17c7fe[_0x0f04('0x1e')],function(_0x34f06b){return{'model':db[_0x34f06b[_0x0f04('0x1f')]],'as':_0x34f06b['as'],'attributes':_0x34f06b['attributes']};}):[]};}):[]};}):[]:[]})['then'](function(_0x50c030){logger['info'](_0x0f04('0x17'),_0x19bd6d);logger[_0x0f04('0x10')](_0x0f04('0x17'),_0x19bd6d,JSON['stringify'](_0x50c030));_0x27f0c(_0x50c030);})[_0x0f04('0x21')](function(_0x58e4a2){logger['error'](_0x0f04('0x17'),_0x58e4a2[_0x0f04('0x14')],_0x19bd6d);_0x34e57a(_0x1e59b1['error'](0x1f4,_0x58e4a2[_0x0f04('0x14')]));});});};