Built motion from commit b5996064.|2.6.21
[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 _0x6739=['request\x20sent','Template,\x20%s,\x20%s,\x20%s','stringify','error','code','message','GetTemplate','Template','findAll','options','raw','where','attributes','limit','include','map','model','debug','catch','lodash','util','moment','bluebird','randomstring','ioredis','../../config/logger','../../config/environment','http','request','then','info','Template,\x20%s,\x20%s'];(function(_0xe9f57f,_0x2d13f6){var _0x1c3bb2=function(_0x34c6e6){while(--_0x34c6e6){_0xe9f57f['push'](_0xe9f57f['shift']());}};_0x1c3bb2(++_0x2d13f6);}(_0x6739,0xd3));var _0x9673=function(_0x4e77a9,_0xee8933){_0x4e77a9=_0x4e77a9-0x0;var _0x1ba13b=_0x6739[_0x4e77a9];return _0x1ba13b;};'use strict';var _=require(_0x9673('0x0'));var util=require(_0x9673('0x1'));var moment=require(_0x9673('0x2'));var BPromise=require(_0x9673('0x3'));var rs=require(_0x9673('0x4'));var fs=require('fs');var Redis=require(_0x9673('0x5'));var db=require('../../mysqldb')['db'];var utils=require('../../config/utils');var logger=require(_0x9673('0x6'))('rpc');var config=require(_0x9673('0x7'));var jayson=require('jayson/promise');var client=jayson['client'][_0x9673('0x8')]({'port':0x232a});function respondWithRpcPromise(_0x3ad052,_0x3f82df,_0x4981d9){return new BPromise(function(_0x4e1dd5,_0x39b0f0){return client[_0x9673('0x9')](_0x3ad052,_0x4981d9)[_0x9673('0xa')](function(_0x509966){logger[_0x9673('0xb')](_0x9673('0xc'),_0x3f82df,_0x9673('0xd'));logger['debug'](_0x9673('0xe'),_0x3f82df,_0x9673('0xd'),JSON[_0x9673('0xf')](_0x509966));if(_0x509966[_0x9673('0x10')]){if(_0x509966['error'][_0x9673('0x11')]===0x1f4){logger[_0x9673('0x10')](_0x9673('0xc'),_0x3f82df,_0x509966[_0x9673('0x10')]['message']);return _0x39b0f0(_0x509966[_0x9673('0x10')][_0x9673('0x12')]);}logger['error'](_0x9673('0xc'),_0x3f82df,_0x509966[_0x9673('0x10')][_0x9673('0x12')]);return _0x4e1dd5(_0x509966['error'][_0x9673('0x12')]);}else{logger['info'](_0x9673('0xc'),_0x3f82df,'request\x20sent');_0x4e1dd5(_0x509966['result'][_0x9673('0x12')]);}})['catch'](function(_0x3d5642){logger[_0x9673('0x10')]('Template,\x20%s,\x20%s',_0x3f82df,_0x3d5642);_0x39b0f0(_0x3d5642);});});}exports[_0x9673('0x13')]=function(_0x46d721){var _0x45015b=this;return new Promise(function(_0x403942,_0x431564){return db[_0x9673('0x14')][_0x9673('0x15')]({'raw':_0x46d721[_0x9673('0x16')]?_0x46d721[_0x9673('0x16')][_0x9673('0x17')]===undefined?!![]:![]:!![],'where':_0x46d721['options']?_0x46d721[_0x9673('0x16')][_0x9673('0x18')]||null:null,'attributes':_0x46d721['options']?_0x46d721[_0x9673('0x16')][_0x9673('0x19')]||null:null,'limit':_0x46d721['options']?_0x46d721[_0x9673('0x16')][_0x9673('0x1a')]||null:null,'include':_0x46d721[_0x9673('0x16')]?_0x46d721['options'][_0x9673('0x1b')]?_[_0x9673('0x1c')](_0x46d721[_0x9673('0x16')][_0x9673('0x1b')],function(_0x5528d7){return{'model':db[_0x5528d7[_0x9673('0x1d')]],'as':_0x5528d7['as'],'attributes':_0x5528d7['attributes'],'include':_0x5528d7[_0x9673('0x1b')]?_[_0x9673('0x1c')](_0x5528d7[_0x9673('0x1b')],function(_0x1a8bc4){return{'model':db[_0x1a8bc4[_0x9673('0x1d')]],'as':_0x1a8bc4['as'],'attributes':_0x1a8bc4[_0x9673('0x19')],'include':_0x1a8bc4[_0x9673('0x1b')]?_[_0x9673('0x1c')](_0x1a8bc4[_0x9673('0x1b')],function(_0x4f7473){return{'model':db[_0x4f7473[_0x9673('0x1d')]],'as':_0x4f7473['as'],'attributes':_0x4f7473[_0x9673('0x19')]};}):[]};}):[]};}):[]:[]})['then'](function(_0x4c3dde){logger[_0x9673('0xb')](_0x9673('0x13'),_0x46d721);logger[_0x9673('0x1e')](_0x9673('0x13'),_0x46d721,JSON['stringify'](_0x4c3dde));_0x403942(_0x4c3dde);})[_0x9673('0x1f')](function(_0x49455d){logger[_0x9673('0x10')]('GetTemplate',_0x49455d[_0x9673('0x12')],_0x46d721);_0x431564(_0x45015b[_0x9673('0x10')](0x1f4,_0x49455d[_0x9673('0x12')]));});});};