bcdd1fbb883969eb164b1ff9ccc0ed5b1d8faaff
[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 _0x34d1=['findAll','options','raw','where','attributes','limit','model','map','include','catch','moment','bluebird','randomstring','ioredis','../../mysqldb','../../config/utils','jayson/promise','client','then','info','Template,\x20%s,\x20%s','request\x20sent','debug','Template,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','GetTemplate','Template'];(function(_0x376eeb,_0x26b365){var _0x32a930=function(_0x4e27d2){while(--_0x4e27d2){_0x376eeb['push'](_0x376eeb['shift']());}};_0x32a930(++_0x26b365);}(_0x34d1,0x19d));var _0x134d=function(_0x90c039,_0xb75bb5){_0x90c039=_0x90c039-0x0;var _0x4b741c=_0x34d1[_0x90c039];return _0x4b741c;};'use strict';var _=require('lodash');var util=require('util');var moment=require(_0x134d('0x0'));var BPromise=require(_0x134d('0x1'));var rs=require(_0x134d('0x2'));var fs=require('fs');var Redis=require(_0x134d('0x3'));var db=require(_0x134d('0x4'))['db'];var utils=require(_0x134d('0x5'));var logger=require('../../config/logger')('rpc');var config=require('../../config/environment');var jayson=require(_0x134d('0x6'));var client=jayson[_0x134d('0x7')]['http']({'port':0x232a});function respondWithRpcPromise(_0x2fd1ca,_0x4f2bc3,_0xf2f9e1){return new BPromise(function(_0x206f41,_0x3ba90b){return client['request'](_0x2fd1ca,_0xf2f9e1)[_0x134d('0x8')](function(_0xb3a238){logger[_0x134d('0x9')](_0x134d('0xa'),_0x4f2bc3,_0x134d('0xb'));logger[_0x134d('0xc')](_0x134d('0xd'),_0x4f2bc3,_0x134d('0xb'),JSON[_0x134d('0xe')](_0xb3a238));if(_0xb3a238[_0x134d('0xf')]){if(_0xb3a238['error'][_0x134d('0x10')]===0x1f4){logger[_0x134d('0xf')](_0x134d('0xa'),_0x4f2bc3,_0xb3a238['error'][_0x134d('0x11')]);return _0x3ba90b(_0xb3a238[_0x134d('0xf')][_0x134d('0x11')]);}logger[_0x134d('0xf')]('Template,\x20%s,\x20%s',_0x4f2bc3,_0xb3a238[_0x134d('0xf')]['message']);return _0x206f41(_0xb3a238['error']['message']);}else{logger[_0x134d('0x9')](_0x134d('0xa'),_0x4f2bc3,'request\x20sent');_0x206f41(_0xb3a238[_0x134d('0x12')][_0x134d('0x11')]);}})['catch'](function(_0x26202b){logger[_0x134d('0xf')](_0x134d('0xa'),_0x4f2bc3,_0x26202b);_0x3ba90b(_0x26202b);});});}exports[_0x134d('0x13')]=function(_0x570052){var _0x4682e9=this;return new Promise(function(_0x19ab9d,_0x4df323){return db[_0x134d('0x14')][_0x134d('0x15')]({'raw':_0x570052['options']?_0x570052[_0x134d('0x16')][_0x134d('0x17')]===undefined?!![]:![]:!![],'where':_0x570052[_0x134d('0x16')]?_0x570052[_0x134d('0x16')][_0x134d('0x18')]||null:null,'attributes':_0x570052['options']?_0x570052[_0x134d('0x16')][_0x134d('0x19')]||null:null,'limit':_0x570052[_0x134d('0x16')]?_0x570052['options'][_0x134d('0x1a')]||null:null,'include':_0x570052[_0x134d('0x16')]?_0x570052['options']['include']?_['map'](_0x570052[_0x134d('0x16')]['include'],function(_0x274b6f){return{'model':db[_0x274b6f[_0x134d('0x1b')]],'as':_0x274b6f['as'],'attributes':_0x274b6f[_0x134d('0x19')],'include':_0x274b6f['include']?_[_0x134d('0x1c')](_0x274b6f['include'],function(_0x13497f){return{'model':db[_0x13497f[_0x134d('0x1b')]],'as':_0x13497f['as'],'attributes':_0x13497f['attributes'],'include':_0x13497f[_0x134d('0x1d')]?_['map'](_0x13497f[_0x134d('0x1d')],function(_0x1fe70f){return{'model':db[_0x1fe70f[_0x134d('0x1b')]],'as':_0x1fe70f['as'],'attributes':_0x1fe70f[_0x134d('0x19')]};}):[]};}):[]};}):[]:[]})['then'](function(_0x25e544){logger[_0x134d('0x9')](_0x134d('0x13'),_0x570052);logger['debug'](_0x134d('0x13'),_0x570052,JSON[_0x134d('0xe')](_0x25e544));_0x19ab9d(_0x25e544);})[_0x134d('0x1e')](function(_0x5c9b58){logger[_0x134d('0xf')](_0x134d('0x13'),_0x5c9b58[_0x134d('0x11')],_0x570052);_0x4df323(_0x4682e9[_0x134d('0xf')](0x1f4,_0x5c9b58[_0x134d('0x11')]));});});};