Built motion from commit (unavailable).|2.5.19
[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 _0x61a4=['../../mysqldb','../../config/utils','../../config/logger','rpc','../../config/environment','jayson/promise','http','then','Template,\x20%s,\x20%s','debug','Template,\x20%s,\x20%s,\x20%s','request\x20sent','stringify','error','code','message','info','result','GetTemplate','Template','findAll','options','raw','where','attributes','limit','include','map','model','catch','util','moment','ioredis'];(function(_0x864548,_0xfd2b6f){var _0x4af523=function(_0x311eaa){while(--_0x311eaa){_0x864548['push'](_0x864548['shift']());}};_0x4af523(++_0xfd2b6f);}(_0x61a4,0xc3));var _0x461a=function(_0x322628,_0x2e8c6e){_0x322628=_0x322628-0x0;var _0x43e1c4=_0x61a4[_0x322628];return _0x43e1c4;};'use strict';var _=require('lodash');var util=require(_0x461a('0x0'));var moment=require(_0x461a('0x1'));var BPromise=require('bluebird');var rs=require('randomstring');var fs=require('fs');var Redis=require(_0x461a('0x2'));var db=require(_0x461a('0x3'))['db'];var utils=require(_0x461a('0x4'));var logger=require(_0x461a('0x5'))(_0x461a('0x6'));var config=require(_0x461a('0x7'));var jayson=require(_0x461a('0x8'));var client=jayson['client'][_0x461a('0x9')]({'port':0x232a});function respondWithRpcPromise(_0x26120f,_0x7d9377,_0x3d897c){return new BPromise(function(_0x30219b,_0x5b648d){return client['request'](_0x26120f,_0x3d897c)[_0x461a('0xa')](function(_0x562bd7){logger['info'](_0x461a('0xb'),_0x7d9377,'request\x20sent');logger[_0x461a('0xc')](_0x461a('0xd'),_0x7d9377,_0x461a('0xe'),JSON[_0x461a('0xf')](_0x562bd7));if(_0x562bd7['error']){if(_0x562bd7[_0x461a('0x10')][_0x461a('0x11')]===0x1f4){logger['error'](_0x461a('0xb'),_0x7d9377,_0x562bd7[_0x461a('0x10')][_0x461a('0x12')]);return _0x5b648d(_0x562bd7[_0x461a('0x10')][_0x461a('0x12')]);}logger[_0x461a('0x10')]('Template,\x20%s,\x20%s',_0x7d9377,_0x562bd7['error'][_0x461a('0x12')]);return _0x30219b(_0x562bd7[_0x461a('0x10')][_0x461a('0x12')]);}else{logger[_0x461a('0x13')](_0x461a('0xb'),_0x7d9377,_0x461a('0xe'));_0x30219b(_0x562bd7[_0x461a('0x14')][_0x461a('0x12')]);}})['catch'](function(_0x4b90f2){logger['error'](_0x461a('0xb'),_0x7d9377,_0x4b90f2);_0x5b648d(_0x4b90f2);});});}exports[_0x461a('0x15')]=function(_0x594f39){var _0x9ecdc9=this;return new Promise(function(_0x3c94ec,_0x17e9b0){return db[_0x461a('0x16')][_0x461a('0x17')]({'raw':_0x594f39['options']?_0x594f39[_0x461a('0x18')][_0x461a('0x19')]===undefined?!![]:![]:!![],'where':_0x594f39[_0x461a('0x18')]?_0x594f39[_0x461a('0x18')][_0x461a('0x1a')]||null:null,'attributes':_0x594f39[_0x461a('0x18')]?_0x594f39['options'][_0x461a('0x1b')]||null:null,'limit':_0x594f39[_0x461a('0x18')]?_0x594f39[_0x461a('0x18')][_0x461a('0x1c')]||null:null,'include':_0x594f39[_0x461a('0x18')]?_0x594f39[_0x461a('0x18')][_0x461a('0x1d')]?_[_0x461a('0x1e')](_0x594f39[_0x461a('0x18')]['include'],function(_0x22cc4b){return{'model':db[_0x22cc4b[_0x461a('0x1f')]],'as':_0x22cc4b['as'],'attributes':_0x22cc4b[_0x461a('0x1b')],'include':_0x22cc4b['include']?_[_0x461a('0x1e')](_0x22cc4b[_0x461a('0x1d')],function(_0x47d3fc){return{'model':db[_0x47d3fc[_0x461a('0x1f')]],'as':_0x47d3fc['as'],'attributes':_0x47d3fc[_0x461a('0x1b')],'include':_0x47d3fc[_0x461a('0x1d')]?_[_0x461a('0x1e')](_0x47d3fc[_0x461a('0x1d')],function(_0x2e9a8a){return{'model':db[_0x2e9a8a[_0x461a('0x1f')]],'as':_0x2e9a8a['as'],'attributes':_0x2e9a8a[_0x461a('0x1b')]};}):[]};}):[]};}):[]:[]})['then'](function(_0x13459b){logger[_0x461a('0x13')]('GetTemplate',_0x594f39);logger[_0x461a('0xc')]('GetTemplate',_0x594f39,JSON[_0x461a('0xf')](_0x13459b));_0x3c94ec(_0x13459b);})[_0x461a('0x20')](function(_0x1efba2){logger[_0x461a('0x10')](_0x461a('0x15'),_0x1efba2[_0x461a('0x12')],_0x594f39);_0x17e9b0(_0x9ecdc9[_0x461a('0x10')](0x1f4,_0x1efba2[_0x461a('0x12')]));});});};