8ebacdc7312f505c193d9131fbace17f10c7e63d
[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 _0x7150=['include','map','model','info','util','moment','bluebird','randomstring','../../mysqldb','../../config/utils','../../config/logger','rpc','../../config/environment','http','request','then','Template,\x20%s,\x20%s','request\x20sent','debug','stringify','error','code','message','result','catch','GetTemplate','Template','options','raw','where','attributes','limit'];(function(_0x480c06,_0x42694a){var _0xcef5b6=function(_0xf25c44){while(--_0xf25c44){_0x480c06['push'](_0x480c06['shift']());}};_0xcef5b6(++_0x42694a);}(_0x7150,0xc4));var _0x0715=function(_0x26b409,_0x385d5b){_0x26b409=_0x26b409-0x0;var _0x3a629e=_0x7150[_0x26b409];return _0x3a629e;};'use strict';var _=require('lodash');var util=require(_0x0715('0x0'));var moment=require(_0x0715('0x1'));var BPromise=require(_0x0715('0x2'));var rs=require(_0x0715('0x3'));var fs=require('fs');var Redis=require('ioredis');var db=require(_0x0715('0x4'))['db'];var utils=require(_0x0715('0x5'));var logger=require(_0x0715('0x6'))(_0x0715('0x7'));var config=require(_0x0715('0x8'));var jayson=require('jayson/promise');var client=jayson['client'][_0x0715('0x9')]({'port':0x232a});function respondWithRpcPromise(_0x5baf33,_0x1da0ee,_0x32903f){return new BPromise(function(_0x162648,_0xdd2d91){return client[_0x0715('0xa')](_0x5baf33,_0x32903f)[_0x0715('0xb')](function(_0x47ece1){logger['info'](_0x0715('0xc'),_0x1da0ee,_0x0715('0xd'));logger[_0x0715('0xe')]('Template,\x20%s,\x20%s,\x20%s',_0x1da0ee,_0x0715('0xd'),JSON[_0x0715('0xf')](_0x47ece1));if(_0x47ece1[_0x0715('0x10')]){if(_0x47ece1[_0x0715('0x10')][_0x0715('0x11')]===0x1f4){logger[_0x0715('0x10')](_0x0715('0xc'),_0x1da0ee,_0x47ece1[_0x0715('0x10')][_0x0715('0x12')]);return _0xdd2d91(_0x47ece1[_0x0715('0x10')][_0x0715('0x12')]);}logger['error'](_0x0715('0xc'),_0x1da0ee,_0x47ece1[_0x0715('0x10')][_0x0715('0x12')]);return _0x162648(_0x47ece1[_0x0715('0x10')][_0x0715('0x12')]);}else{logger['info']('Template,\x20%s,\x20%s',_0x1da0ee,_0x0715('0xd'));_0x162648(_0x47ece1[_0x0715('0x13')][_0x0715('0x12')]);}})[_0x0715('0x14')](function(_0x204276){logger[_0x0715('0x10')](_0x0715('0xc'),_0x1da0ee,_0x204276);_0xdd2d91(_0x204276);});});}exports[_0x0715('0x15')]=function(_0x2308b2){var _0x3e0b8b=this;return new Promise(function(_0x3ec671,_0x535a76){return db[_0x0715('0x16')]['findAll']({'raw':_0x2308b2[_0x0715('0x17')]?_0x2308b2[_0x0715('0x17')][_0x0715('0x18')]===undefined?!![]:![]:!![],'where':_0x2308b2[_0x0715('0x17')]?_0x2308b2[_0x0715('0x17')][_0x0715('0x19')]||null:null,'attributes':_0x2308b2[_0x0715('0x17')]?_0x2308b2['options'][_0x0715('0x1a')]||null:null,'limit':_0x2308b2[_0x0715('0x17')]?_0x2308b2[_0x0715('0x17')][_0x0715('0x1b')]||null:null,'include':_0x2308b2[_0x0715('0x17')]?_0x2308b2['options'][_0x0715('0x1c')]?_[_0x0715('0x1d')](_0x2308b2['options'][_0x0715('0x1c')],function(_0x297caf){return{'model':db[_0x297caf[_0x0715('0x1e')]],'as':_0x297caf['as'],'attributes':_0x297caf[_0x0715('0x1a')],'include':_0x297caf[_0x0715('0x1c')]?_[_0x0715('0x1d')](_0x297caf[_0x0715('0x1c')],function(_0x3111fa){return{'model':db[_0x3111fa[_0x0715('0x1e')]],'as':_0x3111fa['as'],'attributes':_0x3111fa['attributes'],'include':_0x3111fa['include']?_[_0x0715('0x1d')](_0x3111fa[_0x0715('0x1c')],function(_0xbf4409){return{'model':db[_0xbf4409['model']],'as':_0xbf4409['as'],'attributes':_0xbf4409['attributes']};}):[]};}):[]};}):[]:[]})[_0x0715('0xb')](function(_0xc78123){logger[_0x0715('0x1f')]('GetTemplate',_0x2308b2);logger[_0x0715('0xe')](_0x0715('0x15'),_0x2308b2,JSON['stringify'](_0xc78123));_0x3ec671(_0xc78123);})[_0x0715('0x14')](function(_0x40eee5){logger['error']('GetTemplate',_0x40eee5[_0x0715('0x12')],_0x2308b2);_0x535a76(_0x3e0b8b[_0x0715('0x10')](0x1f4,_0x40eee5[_0x0715('0x12')]));});});};