ec21059254d7170822a43969f047d1c8a87ed8aa
[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 _0xff73=['model','attributes','debug','lodash','util','moment','bluebird','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/logger','../../config/environment','jayson/promise','client','request','then','info','request\x20sent','Template,\x20%s,\x20%s,\x20%s','stringify','error','code','Template,\x20%s,\x20%s','message','result','catch','GetTemplate','Template','findAll','options','raw','where','limit','include','map'];(function(_0x53f847,_0x189330){var _0x2aae1c=function(_0x13c4b4){while(--_0x13c4b4){_0x53f847['push'](_0x53f847['shift']());}};_0x2aae1c(++_0x189330);}(_0xff73,0x6f));var _0x3ff7=function(_0x34105a,_0xb17783){_0x34105a=_0x34105a-0x0;var _0x3c53f9=_0xff73[_0x34105a];return _0x3c53f9;};'use strict';var _=require(_0x3ff7('0x0'));var util=require(_0x3ff7('0x1'));var moment=require(_0x3ff7('0x2'));var BPromise=require(_0x3ff7('0x3'));var rs=require(_0x3ff7('0x4'));var fs=require('fs');var Redis=require(_0x3ff7('0x5'));var db=require(_0x3ff7('0x6'))['db'];var utils=require(_0x3ff7('0x7'));var logger=require(_0x3ff7('0x8'))('rpc');var config=require(_0x3ff7('0x9'));var jayson=require(_0x3ff7('0xa'));var client=jayson[_0x3ff7('0xb')]['http']({'port':0x232a});function respondWithRpcPromise(_0x590a1c,_0x4ce2c6,_0xdf1fd9){return new BPromise(function(_0x49c4cc,_0xd636ad){return client[_0x3ff7('0xc')](_0x590a1c,_0xdf1fd9)[_0x3ff7('0xd')](function(_0x548eae){logger[_0x3ff7('0xe')]('Template,\x20%s,\x20%s',_0x4ce2c6,_0x3ff7('0xf'));logger['debug'](_0x3ff7('0x10'),_0x4ce2c6,_0x3ff7('0xf'),JSON[_0x3ff7('0x11')](_0x548eae));if(_0x548eae['error']){if(_0x548eae[_0x3ff7('0x12')][_0x3ff7('0x13')]===0x1f4){logger[_0x3ff7('0x12')](_0x3ff7('0x14'),_0x4ce2c6,_0x548eae[_0x3ff7('0x12')][_0x3ff7('0x15')]);return _0xd636ad(_0x548eae[_0x3ff7('0x12')]['message']);}logger['error'](_0x3ff7('0x14'),_0x4ce2c6,_0x548eae['error'][_0x3ff7('0x15')]);return _0x49c4cc(_0x548eae[_0x3ff7('0x12')][_0x3ff7('0x15')]);}else{logger[_0x3ff7('0xe')](_0x3ff7('0x14'),_0x4ce2c6,'request\x20sent');_0x49c4cc(_0x548eae[_0x3ff7('0x16')][_0x3ff7('0x15')]);}})[_0x3ff7('0x17')](function(_0x312c21){logger[_0x3ff7('0x12')](_0x3ff7('0x14'),_0x4ce2c6,_0x312c21);_0xd636ad(_0x312c21);});});}exports[_0x3ff7('0x18')]=function(_0x480db3){var _0x4bfe74=this;return new Promise(function(_0x432ea8,_0x49636a){return db[_0x3ff7('0x19')][_0x3ff7('0x1a')]({'raw':_0x480db3[_0x3ff7('0x1b')]?_0x480db3[_0x3ff7('0x1b')][_0x3ff7('0x1c')]===undefined?!![]:![]:!![],'where':_0x480db3[_0x3ff7('0x1b')]?_0x480db3[_0x3ff7('0x1b')][_0x3ff7('0x1d')]||null:null,'attributes':_0x480db3[_0x3ff7('0x1b')]?_0x480db3[_0x3ff7('0x1b')]['attributes']||null:null,'limit':_0x480db3[_0x3ff7('0x1b')]?_0x480db3[_0x3ff7('0x1b')][_0x3ff7('0x1e')]||null:null,'include':_0x480db3[_0x3ff7('0x1b')]?_0x480db3[_0x3ff7('0x1b')][_0x3ff7('0x1f')]?_[_0x3ff7('0x20')](_0x480db3['options'][_0x3ff7('0x1f')],function(_0x23409e){return{'model':db[_0x23409e[_0x3ff7('0x21')]],'as':_0x23409e['as'],'attributes':_0x23409e[_0x3ff7('0x22')],'include':_0x23409e[_0x3ff7('0x1f')]?_[_0x3ff7('0x20')](_0x23409e[_0x3ff7('0x1f')],function(_0xfb96d){return{'model':db[_0xfb96d[_0x3ff7('0x21')]],'as':_0xfb96d['as'],'attributes':_0xfb96d[_0x3ff7('0x22')],'include':_0xfb96d[_0x3ff7('0x1f')]?_[_0x3ff7('0x20')](_0xfb96d['include'],function(_0x22ec38){return{'model':db[_0x22ec38['model']],'as':_0x22ec38['as'],'attributes':_0x22ec38[_0x3ff7('0x22')]};}):[]};}):[]};}):[]:[]})[_0x3ff7('0xd')](function(_0x313fd6){logger['info'](_0x3ff7('0x18'),_0x480db3);logger[_0x3ff7('0x23')]('GetTemplate',_0x480db3,JSON[_0x3ff7('0x11')](_0x313fd6));_0x432ea8(_0x313fd6);})['catch'](function(_0xdc83b5){logger[_0x3ff7('0x12')](_0x3ff7('0x18'),_0xdc83b5[_0x3ff7('0x15')],_0x480db3);_0x49636a(_0x4bfe74[_0x3ff7('0x12')](0x1f4,_0xdc83b5[_0x3ff7('0x15')]));});});};