Built motion from commit (unavailable).|2.4.18
[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 _0x0f92=['stringify','error','code','Template,\x20%s,\x20%s','message','result','catch','findAll','options','where','attributes','limit','include','model','map','GetTemplate','debug','util','moment','bluebird','randomstring','../../mysqldb','../../config/logger','rpc','../../config/environment','http','request','then','info','request\x20sent','Template,\x20%s,\x20%s,\x20%s'];(function(_0x40ef08,_0x6d88f1){var _0x451bb6=function(_0x596c26){while(--_0x596c26){_0x40ef08['push'](_0x40ef08['shift']());}};_0x451bb6(++_0x6d88f1);}(_0x0f92,0x1c3));var _0x20f9=function(_0x5f27fb,_0x250dc4){_0x5f27fb=_0x5f27fb-0x0;var _0x26cf50=_0x0f92[_0x5f27fb];return _0x26cf50;};'use strict';var _=require('lodash');var util=require(_0x20f9('0x0'));var moment=require(_0x20f9('0x1'));var BPromise=require(_0x20f9('0x2'));var rs=require(_0x20f9('0x3'));var fs=require('fs');var Redis=require('ioredis');var db=require(_0x20f9('0x4'))['db'];var utils=require('../../config/utils');var logger=require(_0x20f9('0x5'))(_0x20f9('0x6'));var config=require(_0x20f9('0x7'));var jayson=require('jayson/promise');var client=jayson['client'][_0x20f9('0x8')]({'port':0x232a});function respondWithRpcPromise(_0x26229d,_0x96d6a3,_0x18fad9){return new BPromise(function(_0x3eee1e,_0x22ef54){return client[_0x20f9('0x9')](_0x26229d,_0x18fad9)[_0x20f9('0xa')](function(_0x1ed2f9){logger[_0x20f9('0xb')]('Template,\x20%s,\x20%s',_0x96d6a3,_0x20f9('0xc'));logger['debug'](_0x20f9('0xd'),_0x96d6a3,_0x20f9('0xc'),JSON[_0x20f9('0xe')](_0x1ed2f9));if(_0x1ed2f9[_0x20f9('0xf')]){if(_0x1ed2f9[_0x20f9('0xf')][_0x20f9('0x10')]===0x1f4){logger[_0x20f9('0xf')](_0x20f9('0x11'),_0x96d6a3,_0x1ed2f9['error'][_0x20f9('0x12')]);return _0x22ef54(_0x1ed2f9[_0x20f9('0xf')][_0x20f9('0x12')]);}logger[_0x20f9('0xf')]('Template,\x20%s,\x20%s',_0x96d6a3,_0x1ed2f9[_0x20f9('0xf')][_0x20f9('0x12')]);return _0x3eee1e(_0x1ed2f9['error']['message']);}else{logger['info'](_0x20f9('0x11'),_0x96d6a3,_0x20f9('0xc'));_0x3eee1e(_0x1ed2f9[_0x20f9('0x13')][_0x20f9('0x12')]);}})[_0x20f9('0x14')](function(_0x56ffbd){logger[_0x20f9('0xf')](_0x20f9('0x11'),_0x96d6a3,_0x56ffbd);_0x22ef54(_0x56ffbd);});});}exports['GetTemplate']=function(_0x45e320){var _0xadee79=this;return new Promise(function(_0x282771,_0x2520c4){return db['Template'][_0x20f9('0x15')]({'raw':_0x45e320[_0x20f9('0x16')]?_0x45e320[_0x20f9('0x16')]['raw']===undefined?!![]:![]:!![],'where':_0x45e320['options']?_0x45e320[_0x20f9('0x16')][_0x20f9('0x17')]||null:null,'attributes':_0x45e320[_0x20f9('0x16')]?_0x45e320[_0x20f9('0x16')][_0x20f9('0x18')]||null:null,'limit':_0x45e320['options']?_0x45e320[_0x20f9('0x16')][_0x20f9('0x19')]||null:null,'include':_0x45e320['options']?_0x45e320[_0x20f9('0x16')][_0x20f9('0x1a')]?_['map'](_0x45e320['options'][_0x20f9('0x1a')],function(_0x276c80){return{'model':db[_0x276c80[_0x20f9('0x1b')]],'as':_0x276c80['as'],'attributes':_0x276c80[_0x20f9('0x18')],'include':_0x276c80[_0x20f9('0x1a')]?_['map'](_0x276c80['include'],function(_0x40090c){return{'model':db[_0x40090c[_0x20f9('0x1b')]],'as':_0x40090c['as'],'attributes':_0x40090c['attributes'],'include':_0x40090c[_0x20f9('0x1a')]?_[_0x20f9('0x1c')](_0x40090c[_0x20f9('0x1a')],function(_0x91171){return{'model':db[_0x91171[_0x20f9('0x1b')]],'as':_0x91171['as'],'attributes':_0x91171['attributes']};}):[]};}):[]};}):[]:[]})[_0x20f9('0xa')](function(_0x3b3f1f){logger[_0x20f9('0xb')](_0x20f9('0x1d'),_0x45e320);logger[_0x20f9('0x1e')]('GetTemplate',_0x45e320,JSON['stringify'](_0x3b3f1f));_0x282771(_0x3b3f1f);})[_0x20f9('0x14')](function(_0x53782e){logger[_0x20f9('0xf')](_0x20f9('0x1d'),_0x53782e[_0x20f9('0x12')],_0x45e320);_0x2520c4(_0xadee79['error'](0x1f4,_0x53782e[_0x20f9('0x12')]));});});};