Built motion from commit (unavailable).|2.5.6
[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 _0x5a43=['findAll','options','raw','attributes','limit','include','map','model','then','lodash','util','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/logger','rpc','jayson/promise','http','request','info','Template,\x20%s,\x20%s','request\x20sent','debug','Template,\x20%s,\x20%s,\x20%s','stringify','code','error','message','result','catch','GetTemplate','Template'];(function(_0x77e7e8,_0x5a319f){var _0x205a3e=function(_0x2a0454){while(--_0x2a0454){_0x77e7e8['push'](_0x77e7e8['shift']());}};_0x205a3e(++_0x5a319f);}(_0x5a43,0x153));var _0x35a4=function(_0x5a3cda,_0x598f21){_0x5a3cda=_0x5a3cda-0x0;var _0x2cad47=_0x5a43[_0x5a3cda];return _0x2cad47;};'use strict';var _=require(_0x35a4('0x0'));var util=require(_0x35a4('0x1'));var moment=require('moment');var BPromise=require('bluebird');var rs=require(_0x35a4('0x2'));var fs=require('fs');var Redis=require(_0x35a4('0x3'));var db=require(_0x35a4('0x4'))['db'];var utils=require(_0x35a4('0x5'));var logger=require(_0x35a4('0x6'))(_0x35a4('0x7'));var config=require('../../config/environment');var jayson=require(_0x35a4('0x8'));var client=jayson['client'][_0x35a4('0x9')]({'port':0x232a});function respondWithRpcPromise(_0x1b2ff6,_0x28cc2d,_0x22111e){return new BPromise(function(_0x23bf42,_0x5333a0){return client[_0x35a4('0xa')](_0x1b2ff6,_0x22111e)['then'](function(_0x317888){logger[_0x35a4('0xb')](_0x35a4('0xc'),_0x28cc2d,_0x35a4('0xd'));logger[_0x35a4('0xe')](_0x35a4('0xf'),_0x28cc2d,_0x35a4('0xd'),JSON[_0x35a4('0x10')](_0x317888));if(_0x317888['error']){if(_0x317888['error'][_0x35a4('0x11')]===0x1f4){logger['error'](_0x35a4('0xc'),_0x28cc2d,_0x317888[_0x35a4('0x12')][_0x35a4('0x13')]);return _0x5333a0(_0x317888['error']['message']);}logger[_0x35a4('0x12')]('Template,\x20%s,\x20%s',_0x28cc2d,_0x317888[_0x35a4('0x12')][_0x35a4('0x13')]);return _0x23bf42(_0x317888['error'][_0x35a4('0x13')]);}else{logger['info']('Template,\x20%s,\x20%s',_0x28cc2d,_0x35a4('0xd'));_0x23bf42(_0x317888[_0x35a4('0x14')][_0x35a4('0x13')]);}})[_0x35a4('0x15')](function(_0x2551e3){logger[_0x35a4('0x12')]('Template,\x20%s,\x20%s',_0x28cc2d,_0x2551e3);_0x5333a0(_0x2551e3);});});}exports[_0x35a4('0x16')]=function(_0x89dbee){var _0x26dfa5=this;return new Promise(function(_0x585e80,_0x26a495){return db[_0x35a4('0x17')][_0x35a4('0x18')]({'raw':_0x89dbee['options']?_0x89dbee[_0x35a4('0x19')][_0x35a4('0x1a')]===undefined?!![]:![]:!![],'where':_0x89dbee[_0x35a4('0x19')]?_0x89dbee[_0x35a4('0x19')]['where']||null:null,'attributes':_0x89dbee[_0x35a4('0x19')]?_0x89dbee[_0x35a4('0x19')][_0x35a4('0x1b')]||null:null,'limit':_0x89dbee[_0x35a4('0x19')]?_0x89dbee[_0x35a4('0x19')][_0x35a4('0x1c')]||null:null,'include':_0x89dbee[_0x35a4('0x19')]?_0x89dbee[_0x35a4('0x19')][_0x35a4('0x1d')]?_[_0x35a4('0x1e')](_0x89dbee[_0x35a4('0x19')]['include'],function(_0x3a1a53){return{'model':db[_0x3a1a53['model']],'as':_0x3a1a53['as'],'attributes':_0x3a1a53[_0x35a4('0x1b')],'include':_0x3a1a53['include']?_[_0x35a4('0x1e')](_0x3a1a53[_0x35a4('0x1d')],function(_0x398171){return{'model':db[_0x398171[_0x35a4('0x1f')]],'as':_0x398171['as'],'attributes':_0x398171['attributes'],'include':_0x398171['include']?_['map'](_0x398171[_0x35a4('0x1d')],function(_0x13004a){return{'model':db[_0x13004a[_0x35a4('0x1f')]],'as':_0x13004a['as'],'attributes':_0x13004a[_0x35a4('0x1b')]};}):[]};}):[]};}):[]:[]})[_0x35a4('0x20')](function(_0xc342c3){logger[_0x35a4('0xb')]('GetTemplate',_0x89dbee);logger[_0x35a4('0xe')](_0x35a4('0x16'),_0x89dbee,JSON[_0x35a4('0x10')](_0xc342c3));_0x585e80(_0xc342c3);})['catch'](function(_0x301ec9){logger[_0x35a4('0x12')](_0x35a4('0x16'),_0x301ec9[_0x35a4('0x13')],_0x89dbee);_0x26a495(_0x26dfa5['error'](0x1f4,_0x301ec9[_0x35a4('0x13')]));});});};