589f52ef96feb21072c2f8b6d090525be85bd728
[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 _0x3ea0=['GetTemplate','options','raw','limit','include','map','model','attributes','lodash','util','bluebird','randomstring','ioredis','../../config/utils','../../config/logger','rpc','jayson/promise','client','http','request','then','info','Template,\x20%s,\x20%s','request\x20sent','debug','error','code','message','result'];(function(_0x42160f,_0x29ffd2){var _0x992d2a=function(_0x379a6a){while(--_0x379a6a){_0x42160f['push'](_0x42160f['shift']());}};_0x992d2a(++_0x29ffd2);}(_0x3ea0,0x1bb));var _0x03ea=function(_0x1c1798,_0x24812b){_0x1c1798=_0x1c1798-0x0;var _0x4f235e=_0x3ea0[_0x1c1798];return _0x4f235e;};'use strict';var _=require(_0x03ea('0x0'));var util=require(_0x03ea('0x1'));var moment=require('moment');var BPromise=require(_0x03ea('0x2'));var rs=require(_0x03ea('0x3'));var fs=require('fs');var Redis=require(_0x03ea('0x4'));var db=require('../../mysqldb')['db'];var utils=require(_0x03ea('0x5'));var logger=require(_0x03ea('0x6'))(_0x03ea('0x7'));var config=require('../../config/environment');var jayson=require(_0x03ea('0x8'));var client=jayson[_0x03ea('0x9')][_0x03ea('0xa')]({'port':0x232a});function respondWithRpcPromise(_0x2ba302,_0x10f541,_0x4aa57c){return new BPromise(function(_0x3b38d3,_0x5d4d72){return client[_0x03ea('0xb')](_0x2ba302,_0x4aa57c)[_0x03ea('0xc')](function(_0x213a43){logger[_0x03ea('0xd')](_0x03ea('0xe'),_0x10f541,_0x03ea('0xf'));logger[_0x03ea('0x10')]('Template,\x20%s,\x20%s,\x20%s',_0x10f541,_0x03ea('0xf'),JSON['stringify'](_0x213a43));if(_0x213a43['error']){if(_0x213a43[_0x03ea('0x11')][_0x03ea('0x12')]===0x1f4){logger[_0x03ea('0x11')](_0x03ea('0xe'),_0x10f541,_0x213a43[_0x03ea('0x11')][_0x03ea('0x13')]);return _0x5d4d72(_0x213a43[_0x03ea('0x11')][_0x03ea('0x13')]);}logger[_0x03ea('0x11')]('Template,\x20%s,\x20%s',_0x10f541,_0x213a43[_0x03ea('0x11')][_0x03ea('0x13')]);return _0x3b38d3(_0x213a43['error']['message']);}else{logger[_0x03ea('0xd')](_0x03ea('0xe'),_0x10f541,_0x03ea('0xf'));_0x3b38d3(_0x213a43[_0x03ea('0x14')][_0x03ea('0x13')]);}})['catch'](function(_0x1aebed){logger[_0x03ea('0x11')](_0x03ea('0xe'),_0x10f541,_0x1aebed);_0x5d4d72(_0x1aebed);});});}exports[_0x03ea('0x15')]=function(_0x26ada3){var _0x123032=this;return new Promise(function(_0xa3771f,_0x4662b6){return db['Template']['findAll']({'raw':_0x26ada3[_0x03ea('0x16')]?_0x26ada3[_0x03ea('0x16')][_0x03ea('0x17')]===undefined?!![]:![]:!![],'where':_0x26ada3[_0x03ea('0x16')]?_0x26ada3['options']['where']||null:null,'attributes':_0x26ada3[_0x03ea('0x16')]?_0x26ada3[_0x03ea('0x16')]['attributes']||null:null,'limit':_0x26ada3[_0x03ea('0x16')]?_0x26ada3[_0x03ea('0x16')][_0x03ea('0x18')]||null:null,'include':_0x26ada3[_0x03ea('0x16')]?_0x26ada3['options'][_0x03ea('0x19')]?_[_0x03ea('0x1a')](_0x26ada3[_0x03ea('0x16')]['include'],function(_0x2149f5){return{'model':db[_0x2149f5[_0x03ea('0x1b')]],'as':_0x2149f5['as'],'attributes':_0x2149f5[_0x03ea('0x1c')],'include':_0x2149f5[_0x03ea('0x19')]?_[_0x03ea('0x1a')](_0x2149f5[_0x03ea('0x19')],function(_0x3693f7){return{'model':db[_0x3693f7[_0x03ea('0x1b')]],'as':_0x3693f7['as'],'attributes':_0x3693f7[_0x03ea('0x1c')],'include':_0x3693f7[_0x03ea('0x19')]?_[_0x03ea('0x1a')](_0x3693f7[_0x03ea('0x19')],function(_0x21757e){return{'model':db[_0x21757e[_0x03ea('0x1b')]],'as':_0x21757e['as'],'attributes':_0x21757e[_0x03ea('0x1c')]};}):[]};}):[]};}):[]:[]})['then'](function(_0x4304f1){logger[_0x03ea('0xd')](_0x03ea('0x15'),_0x26ada3);logger['debug']('GetTemplate',_0x26ada3,JSON['stringify'](_0x4304f1));_0xa3771f(_0x4304f1);})['catch'](function(_0x40769c){logger[_0x03ea('0x11')](_0x03ea('0x15'),_0x40769c[_0x03ea('0x13')],_0x26ada3);_0x4662b6(_0x123032[_0x03ea('0x11')](0x1f4,_0x40769c[_0x03ea('0x13')]));});});};