6b2e56b629a358bf8ce383dd14e7a6280877af03
[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 _0xbdbe=['util','moment','bluebird','randomstring','ioredis','../../mysqldb','../../config/logger','rpc','jayson/promise','http','request','then','info','Template,\x20%s,\x20%s','request\x20sent','debug','Template,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','catch','Template','findAll','options','raw','attributes','limit','include','map','model','GetTemplate','lodash'];(function(_0x12a2a6,_0x374ff1){var _0x1754ae=function(_0x49d787){while(--_0x49d787){_0x12a2a6['push'](_0x12a2a6['shift']());}};_0x1754ae(++_0x374ff1);}(_0xbdbe,0x153));var _0xebdb=function(_0x40a045,_0x516f0e){_0x40a045=_0x40a045-0x0;var _0x1a687c=_0xbdbe[_0x40a045];return _0x1a687c;};'use strict';var _=require(_0xebdb('0x0'));var util=require(_0xebdb('0x1'));var moment=require(_0xebdb('0x2'));var BPromise=require(_0xebdb('0x3'));var rs=require(_0xebdb('0x4'));var fs=require('fs');var Redis=require(_0xebdb('0x5'));var db=require(_0xebdb('0x6'))['db'];var utils=require('../../config/utils');var logger=require(_0xebdb('0x7'))(_0xebdb('0x8'));var config=require('../../config/environment');var jayson=require(_0xebdb('0x9'));var client=jayson['client'][_0xebdb('0xa')]({'port':0x232a});function respondWithRpcPromise(_0x16404c,_0x193e88,_0x1cb876){return new BPromise(function(_0x1afe4c,_0x5cadc8){return client[_0xebdb('0xb')](_0x16404c,_0x1cb876)[_0xebdb('0xc')](function(_0x21ffab){logger[_0xebdb('0xd')](_0xebdb('0xe'),_0x193e88,_0xebdb('0xf'));logger[_0xebdb('0x10')](_0xebdb('0x11'),_0x193e88,_0xebdb('0xf'),JSON[_0xebdb('0x12')](_0x21ffab));if(_0x21ffab['error']){if(_0x21ffab[_0xebdb('0x13')][_0xebdb('0x14')]===0x1f4){logger[_0xebdb('0x13')](_0xebdb('0xe'),_0x193e88,_0x21ffab[_0xebdb('0x13')][_0xebdb('0x15')]);return _0x5cadc8(_0x21ffab[_0xebdb('0x13')][_0xebdb('0x15')]);}logger[_0xebdb('0x13')](_0xebdb('0xe'),_0x193e88,_0x21ffab[_0xebdb('0x13')][_0xebdb('0x15')]);return _0x1afe4c(_0x21ffab[_0xebdb('0x13')]['message']);}else{logger[_0xebdb('0xd')](_0xebdb('0xe'),_0x193e88,_0xebdb('0xf'));_0x1afe4c(_0x21ffab[_0xebdb('0x16')][_0xebdb('0x15')]);}})[_0xebdb('0x17')](function(_0x40eefa){logger['error'](_0xebdb('0xe'),_0x193e88,_0x40eefa);_0x5cadc8(_0x40eefa);});});}exports['GetTemplate']=function(_0x51d670){var _0x2ea004=this;return new Promise(function(_0x363d2e,_0x3926c6){return db[_0xebdb('0x18')][_0xebdb('0x19')]({'raw':_0x51d670['options']?_0x51d670[_0xebdb('0x1a')][_0xebdb('0x1b')]===undefined?!![]:![]:!![],'where':_0x51d670[_0xebdb('0x1a')]?_0x51d670[_0xebdb('0x1a')]['where']||null:null,'attributes':_0x51d670[_0xebdb('0x1a')]?_0x51d670[_0xebdb('0x1a')][_0xebdb('0x1c')]||null:null,'limit':_0x51d670[_0xebdb('0x1a')]?_0x51d670['options'][_0xebdb('0x1d')]||null:null,'include':_0x51d670['options']?_0x51d670[_0xebdb('0x1a')][_0xebdb('0x1e')]?_[_0xebdb('0x1f')](_0x51d670[_0xebdb('0x1a')][_0xebdb('0x1e')],function(_0x2887ac){return{'model':db[_0x2887ac[_0xebdb('0x20')]],'as':_0x2887ac['as'],'attributes':_0x2887ac['attributes'],'include':_0x2887ac['include']?_[_0xebdb('0x1f')](_0x2887ac['include'],function(_0x1a99ac){return{'model':db[_0x1a99ac[_0xebdb('0x20')]],'as':_0x1a99ac['as'],'attributes':_0x1a99ac[_0xebdb('0x1c')],'include':_0x1a99ac[_0xebdb('0x1e')]?_[_0xebdb('0x1f')](_0x1a99ac[_0xebdb('0x1e')],function(_0xeb4356){return{'model':db[_0xeb4356[_0xebdb('0x20')]],'as':_0xeb4356['as'],'attributes':_0xeb4356[_0xebdb('0x1c')]};}):[]};}):[]};}):[]:[]})['then'](function(_0x59a4b2){logger['info'](_0xebdb('0x21'),_0x51d670);logger[_0xebdb('0x10')](_0xebdb('0x21'),_0x51d670,JSON[_0xebdb('0x12')](_0x59a4b2));_0x363d2e(_0x59a4b2);})[_0xebdb('0x17')](function(_0x50074b){logger[_0xebdb('0x13')](_0xebdb('0x21'),_0x50074b[_0xebdb('0x15')],_0x51d670);_0x3926c6(_0x2ea004[_0xebdb('0x13')](0x1f4,_0x50074b[_0xebdb('0x15')]));});});};