16066de0e375412a987ad9b4d36f1a88fa8ab242
[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 _0x1179=['debug','Template,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','catch','GetTemplate','Template','findAll','options','raw','where','limit','include','model','map','attributes','lodash','bluebird','randomstring','ioredis','../../config/utils','../../config/logger','jayson/promise','client','request','then','info','Template,\x20%s,\x20%s','request\x20sent'];(function(_0x526a46,_0x119cc9){var _0x299cab=function(_0x49722b){while(--_0x49722b){_0x526a46['push'](_0x526a46['shift']());}};_0x299cab(++_0x119cc9);}(_0x1179,0x93));var _0x9117=function(_0x1d090a,_0x355f6b){_0x1d090a=_0x1d090a-0x0;var _0x2301a1=_0x1179[_0x1d090a];return _0x2301a1;};'use strict';var _=require(_0x9117('0x0'));var util=require('util');var moment=require('moment');var BPromise=require(_0x9117('0x1'));var rs=require(_0x9117('0x2'));var fs=require('fs');var Redis=require(_0x9117('0x3'));var db=require('../../mysqldb')['db'];var utils=require(_0x9117('0x4'));var logger=require(_0x9117('0x5'))('rpc');var config=require('../../config/environment');var jayson=require(_0x9117('0x6'));var client=jayson[_0x9117('0x7')]['http']({'port':0x232a});function respondWithRpcPromise(_0x695b3e,_0x3853dd,_0x589e0b){return new BPromise(function(_0x223e1f,_0x30bd0f){return client[_0x9117('0x8')](_0x695b3e,_0x589e0b)[_0x9117('0x9')](function(_0x5d5a6c){logger[_0x9117('0xa')](_0x9117('0xb'),_0x3853dd,_0x9117('0xc'));logger[_0x9117('0xd')](_0x9117('0xe'),_0x3853dd,_0x9117('0xc'),JSON[_0x9117('0xf')](_0x5d5a6c));if(_0x5d5a6c[_0x9117('0x10')]){if(_0x5d5a6c[_0x9117('0x10')][_0x9117('0x11')]===0x1f4){logger[_0x9117('0x10')](_0x9117('0xb'),_0x3853dd,_0x5d5a6c['error'][_0x9117('0x12')]);return _0x30bd0f(_0x5d5a6c[_0x9117('0x10')]['message']);}logger['error'](_0x9117('0xb'),_0x3853dd,_0x5d5a6c[_0x9117('0x10')]['message']);return _0x223e1f(_0x5d5a6c[_0x9117('0x10')]['message']);}else{logger[_0x9117('0xa')](_0x9117('0xb'),_0x3853dd,'request\x20sent');_0x223e1f(_0x5d5a6c[_0x9117('0x13')][_0x9117('0x12')]);}})[_0x9117('0x14')](function(_0x257127){logger['error']('Template,\x20%s,\x20%s',_0x3853dd,_0x257127);_0x30bd0f(_0x257127);});});}exports[_0x9117('0x15')]=function(_0x4b9b72){var _0x23ac6b=this;return new Promise(function(_0x5c3925,_0x7fd59f){return db[_0x9117('0x16')][_0x9117('0x17')]({'raw':_0x4b9b72[_0x9117('0x18')]?_0x4b9b72[_0x9117('0x18')][_0x9117('0x19')]===undefined?!![]:![]:!![],'where':_0x4b9b72[_0x9117('0x18')]?_0x4b9b72[_0x9117('0x18')][_0x9117('0x1a')]||null:null,'attributes':_0x4b9b72[_0x9117('0x18')]?_0x4b9b72['options']['attributes']||null:null,'limit':_0x4b9b72[_0x9117('0x18')]?_0x4b9b72['options'][_0x9117('0x1b')]||null:null,'include':_0x4b9b72[_0x9117('0x18')]?_0x4b9b72['options'][_0x9117('0x1c')]?_['map'](_0x4b9b72[_0x9117('0x18')][_0x9117('0x1c')],function(_0x5f18a7){return{'model':db[_0x5f18a7[_0x9117('0x1d')]],'as':_0x5f18a7['as'],'attributes':_0x5f18a7['attributes'],'include':_0x5f18a7['include']?_[_0x9117('0x1e')](_0x5f18a7[_0x9117('0x1c')],function(_0x3ea4ad){return{'model':db[_0x3ea4ad['model']],'as':_0x3ea4ad['as'],'attributes':_0x3ea4ad[_0x9117('0x1f')],'include':_0x3ea4ad[_0x9117('0x1c')]?_[_0x9117('0x1e')](_0x3ea4ad[_0x9117('0x1c')],function(_0x272fc1){return{'model':db[_0x272fc1[_0x9117('0x1d')]],'as':_0x272fc1['as'],'attributes':_0x272fc1[_0x9117('0x1f')]};}):[]};}):[]};}):[]:[]})[_0x9117('0x9')](function(_0x14f738){logger[_0x9117('0xa')]('GetTemplate',_0x4b9b72);logger[_0x9117('0xd')](_0x9117('0x15'),_0x4b9b72,JSON[_0x9117('0xf')](_0x14f738));_0x5c3925(_0x14f738);})[_0x9117('0x14')](function(_0x15b45d){logger[_0x9117('0x10')](_0x9117('0x15'),_0x15b45d[_0x9117('0x12')],_0x4b9b72);_0x7fd59f(_0x23ac6b[_0x9117('0x10')](0x1f4,_0x15b45d[_0x9117('0x12')]));});});};