Built motion from commit e6806ed6.|2.6.0
[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 _0xa693=['../../config/environment','jayson/promise','client','http','info','request\x20sent','debug','Template,\x20%s,\x20%s,\x20%s','stringify','error','code','Template,\x20%s,\x20%s','message','result','catch','GetTemplate','Template','findAll','options','raw','attributes','include','map','model','lodash','util','moment','bluebird','randomstring','ioredis','rpc'];(function(_0x498020,_0x1e3b70){var _0x13e169=function(_0x128525){while(--_0x128525){_0x498020['push'](_0x498020['shift']());}};_0x13e169(++_0x1e3b70);}(_0xa693,0xf1));var _0x3a69=function(_0x1f0679,_0x53d43c){_0x1f0679=_0x1f0679-0x0;var _0x3dc3a4=_0xa693[_0x1f0679];return _0x3dc3a4;};'use strict';var _=require(_0x3a69('0x0'));var util=require(_0x3a69('0x1'));var moment=require(_0x3a69('0x2'));var BPromise=require(_0x3a69('0x3'));var rs=require(_0x3a69('0x4'));var fs=require('fs');var Redis=require(_0x3a69('0x5'));var db=require('../../mysqldb')['db'];var utils=require('../../config/utils');var logger=require('../../config/logger')(_0x3a69('0x6'));var config=require(_0x3a69('0x7'));var jayson=require(_0x3a69('0x8'));var client=jayson[_0x3a69('0x9')][_0x3a69('0xa')]({'port':0x232a});function respondWithRpcPromise(_0x125226,_0x290e84,_0x5e7d90){return new BPromise(function(_0x1d564b,_0x2b8e2e){return client['request'](_0x125226,_0x5e7d90)['then'](function(_0x4e65a5){logger[_0x3a69('0xb')]('Template,\x20%s,\x20%s',_0x290e84,_0x3a69('0xc'));logger[_0x3a69('0xd')](_0x3a69('0xe'),_0x290e84,_0x3a69('0xc'),JSON[_0x3a69('0xf')](_0x4e65a5));if(_0x4e65a5['error']){if(_0x4e65a5[_0x3a69('0x10')][_0x3a69('0x11')]===0x1f4){logger['error'](_0x3a69('0x12'),_0x290e84,_0x4e65a5[_0x3a69('0x10')][_0x3a69('0x13')]);return _0x2b8e2e(_0x4e65a5[_0x3a69('0x10')][_0x3a69('0x13')]);}logger[_0x3a69('0x10')](_0x3a69('0x12'),_0x290e84,_0x4e65a5[_0x3a69('0x10')][_0x3a69('0x13')]);return _0x1d564b(_0x4e65a5[_0x3a69('0x10')][_0x3a69('0x13')]);}else{logger[_0x3a69('0xb')]('Template,\x20%s,\x20%s',_0x290e84,'request\x20sent');_0x1d564b(_0x4e65a5[_0x3a69('0x14')][_0x3a69('0x13')]);}})[_0x3a69('0x15')](function(_0x24fb29){logger[_0x3a69('0x10')](_0x3a69('0x12'),_0x290e84,_0x24fb29);_0x2b8e2e(_0x24fb29);});});}exports[_0x3a69('0x16')]=function(_0x224c7c){var _0xeb9c93=this;return new Promise(function(_0xff2a8a,_0x5ebc15){return db[_0x3a69('0x17')][_0x3a69('0x18')]({'raw':_0x224c7c[_0x3a69('0x19')]?_0x224c7c['options'][_0x3a69('0x1a')]===undefined?!![]:![]:!![],'where':_0x224c7c[_0x3a69('0x19')]?_0x224c7c['options']['where']||null:null,'attributes':_0x224c7c['options']?_0x224c7c[_0x3a69('0x19')][_0x3a69('0x1b')]||null:null,'limit':_0x224c7c['options']?_0x224c7c[_0x3a69('0x19')]['limit']||null:null,'include':_0x224c7c[_0x3a69('0x19')]?_0x224c7c['options'][_0x3a69('0x1c')]?_[_0x3a69('0x1d')](_0x224c7c[_0x3a69('0x19')]['include'],function(_0x473984){return{'model':db[_0x473984[_0x3a69('0x1e')]],'as':_0x473984['as'],'attributes':_0x473984[_0x3a69('0x1b')],'include':_0x473984['include']?_['map'](_0x473984['include'],function(_0x186ca3){return{'model':db[_0x186ca3[_0x3a69('0x1e')]],'as':_0x186ca3['as'],'attributes':_0x186ca3['attributes'],'include':_0x186ca3[_0x3a69('0x1c')]?_[_0x3a69('0x1d')](_0x186ca3[_0x3a69('0x1c')],function(_0xfa5706){return{'model':db[_0xfa5706[_0x3a69('0x1e')]],'as':_0xfa5706['as'],'attributes':_0xfa5706[_0x3a69('0x1b')]};}):[]};}):[]};}):[]:[]})['then'](function(_0x2f694f){logger[_0x3a69('0xb')](_0x3a69('0x16'),_0x224c7c);logger[_0x3a69('0xd')](_0x3a69('0x16'),_0x224c7c,JSON[_0x3a69('0xf')](_0x2f694f));_0xff2a8a(_0x2f694f);})[_0x3a69('0x15')](function(_0x4e679f){logger[_0x3a69('0x10')]('GetTemplate',_0x4e679f[_0x3a69('0x13')],_0x224c7c);_0x5ebc15(_0xeb9c93[_0x3a69('0x10')](0x1f4,_0x4e679f[_0x3a69('0x13')]));});});};