d7e2c86acd191efe388f118fe66483818d953609
[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 _0x1ed5=['moment','bluebird','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/logger','rpc','../../config/environment','jayson/promise','client','http','request','then','Template,\x20%s,\x20%s','request\x20sent','debug','error','code','message','info','result','catch','Template','findAll','options','where','limit','include','map','model','attributes','GetTemplate','stringify','lodash','util'];(function(_0x390cba,_0x5f043d){var _0x17eb37=function(_0x256e2a){while(--_0x256e2a){_0x390cba['push'](_0x390cba['shift']());}};_0x17eb37(++_0x5f043d);}(_0x1ed5,0x1ae));var _0x51ed=function(_0x108de9,_0x59c896){_0x108de9=_0x108de9-0x0;var _0x3038af=_0x1ed5[_0x108de9];return _0x3038af;};'use strict';var _=require(_0x51ed('0x0'));var util=require(_0x51ed('0x1'));var moment=require(_0x51ed('0x2'));var BPromise=require(_0x51ed('0x3'));var rs=require(_0x51ed('0x4'));var fs=require('fs');var Redis=require(_0x51ed('0x5'));var db=require(_0x51ed('0x6'))['db'];var utils=require(_0x51ed('0x7'));var logger=require(_0x51ed('0x8'))(_0x51ed('0x9'));var config=require(_0x51ed('0xa'));var jayson=require(_0x51ed('0xb'));var client=jayson[_0x51ed('0xc')][_0x51ed('0xd')]({'port':0x232a});function respondWithRpcPromise(_0x21dbae,_0x587cb0,_0x59824f){return new BPromise(function(_0x165a53,_0x48c509){return client[_0x51ed('0xe')](_0x21dbae,_0x59824f)[_0x51ed('0xf')](function(_0x522881){logger['info'](_0x51ed('0x10'),_0x587cb0,_0x51ed('0x11'));logger[_0x51ed('0x12')]('Template,\x20%s,\x20%s,\x20%s',_0x587cb0,'request\x20sent',JSON['stringify'](_0x522881));if(_0x522881[_0x51ed('0x13')]){if(_0x522881[_0x51ed('0x13')][_0x51ed('0x14')]===0x1f4){logger[_0x51ed('0x13')]('Template,\x20%s,\x20%s',_0x587cb0,_0x522881['error'][_0x51ed('0x15')]);return _0x48c509(_0x522881[_0x51ed('0x13')][_0x51ed('0x15')]);}logger[_0x51ed('0x13')]('Template,\x20%s,\x20%s',_0x587cb0,_0x522881[_0x51ed('0x13')][_0x51ed('0x15')]);return _0x165a53(_0x522881[_0x51ed('0x13')][_0x51ed('0x15')]);}else{logger[_0x51ed('0x16')](_0x51ed('0x10'),_0x587cb0,'request\x20sent');_0x165a53(_0x522881[_0x51ed('0x17')][_0x51ed('0x15')]);}})[_0x51ed('0x18')](function(_0xaa7ec){logger['error']('Template,\x20%s,\x20%s',_0x587cb0,_0xaa7ec);_0x48c509(_0xaa7ec);});});}exports['GetTemplate']=function(_0xcadc48){var _0x21e248=this;return new Promise(function(_0x4135f6,_0x38f20e){return db[_0x51ed('0x19')][_0x51ed('0x1a')]({'raw':_0xcadc48[_0x51ed('0x1b')]?_0xcadc48[_0x51ed('0x1b')]['raw']===undefined?!![]:![]:!![],'where':_0xcadc48[_0x51ed('0x1b')]?_0xcadc48[_0x51ed('0x1b')][_0x51ed('0x1c')]||null:null,'attributes':_0xcadc48['options']?_0xcadc48['options']['attributes']||null:null,'limit':_0xcadc48['options']?_0xcadc48['options'][_0x51ed('0x1d')]||null:null,'include':_0xcadc48[_0x51ed('0x1b')]?_0xcadc48['options'][_0x51ed('0x1e')]?_[_0x51ed('0x1f')](_0xcadc48[_0x51ed('0x1b')][_0x51ed('0x1e')],function(_0x214066){return{'model':db[_0x214066[_0x51ed('0x20')]],'as':_0x214066['as'],'attributes':_0x214066[_0x51ed('0x21')],'include':_0x214066[_0x51ed('0x1e')]?_['map'](_0x214066[_0x51ed('0x1e')],function(_0x4c634c){return{'model':db[_0x4c634c['model']],'as':_0x4c634c['as'],'attributes':_0x4c634c['attributes'],'include':_0x4c634c[_0x51ed('0x1e')]?_[_0x51ed('0x1f')](_0x4c634c[_0x51ed('0x1e')],function(_0x5ee7f6){return{'model':db[_0x5ee7f6[_0x51ed('0x20')]],'as':_0x5ee7f6['as'],'attributes':_0x5ee7f6[_0x51ed('0x21')]};}):[]};}):[]};}):[]:[]})[_0x51ed('0xf')](function(_0x4c2ab0){logger['info'](_0x51ed('0x22'),_0xcadc48);logger[_0x51ed('0x12')](_0x51ed('0x22'),_0xcadc48,JSON[_0x51ed('0x23')](_0x4c2ab0));_0x4135f6(_0x4c2ab0);})[_0x51ed('0x18')](function(_0x5f3479){logger[_0x51ed('0x13')](_0x51ed('0x22'),_0x5f3479[_0x51ed('0x15')],_0xcadc48);_0x38f20e(_0x21e248[_0x51ed('0x13')](0x1f4,_0x5f3479['message']));});});};