48b4602dbac17ea5fd602161ae816ede6bee15ac
[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 _0xfcaf=['request\x20sent','stringify','error','message','GetTemplate','Template','options','where','attributes','limit','include','model','map','lodash','util','moment','bluebird','randomstring','../../mysqldb','../../config/utils','rpc','jayson/promise','client','http','then','info','Template,\x20%s,\x20%s','debug','Template,\x20%s,\x20%s,\x20%s'];(function(_0x542588,_0x4305c9){var _0xf24784=function(_0x13ea9d){while(--_0x13ea9d){_0x542588['push'](_0x542588['shift']());}};_0xf24784(++_0x4305c9);}(_0xfcaf,0x1c0));var _0xffca=function(_0x241b5a,_0x5ac06c){_0x241b5a=_0x241b5a-0x0;var _0x49fff8=_0xfcaf[_0x241b5a];return _0x49fff8;};'use strict';var _=require(_0xffca('0x0'));var util=require(_0xffca('0x1'));var moment=require(_0xffca('0x2'));var BPromise=require(_0xffca('0x3'));var rs=require(_0xffca('0x4'));var fs=require('fs');var Redis=require('ioredis');var db=require(_0xffca('0x5'))['db'];var utils=require(_0xffca('0x6'));var logger=require('../../config/logger')(_0xffca('0x7'));var config=require('../../config/environment');var jayson=require(_0xffca('0x8'));var client=jayson[_0xffca('0x9')][_0xffca('0xa')]({'port':0x232a});function respondWithRpcPromise(_0x3a865a,_0x2a6c16,_0x6261f2){return new BPromise(function(_0x15711d,_0x5965f8){return client['request'](_0x3a865a,_0x6261f2)[_0xffca('0xb')](function(_0x503dc2){logger[_0xffca('0xc')](_0xffca('0xd'),_0x2a6c16,'request\x20sent');logger[_0xffca('0xe')](_0xffca('0xf'),_0x2a6c16,_0xffca('0x10'),JSON[_0xffca('0x11')](_0x503dc2));if(_0x503dc2[_0xffca('0x12')]){if(_0x503dc2[_0xffca('0x12')]['code']===0x1f4){logger[_0xffca('0x12')](_0xffca('0xd'),_0x2a6c16,_0x503dc2['error']['message']);return _0x5965f8(_0x503dc2['error'][_0xffca('0x13')]);}logger[_0xffca('0x12')](_0xffca('0xd'),_0x2a6c16,_0x503dc2[_0xffca('0x12')][_0xffca('0x13')]);return _0x15711d(_0x503dc2['error'][_0xffca('0x13')]);}else{logger['info'](_0xffca('0xd'),_0x2a6c16,'request\x20sent');_0x15711d(_0x503dc2['result'][_0xffca('0x13')]);}})['catch'](function(_0x582729){logger['error'](_0xffca('0xd'),_0x2a6c16,_0x582729);_0x5965f8(_0x582729);});});}exports[_0xffca('0x14')]=function(_0x4a0603){var _0x372abc=this;return new Promise(function(_0x5601ff,_0x5a4fc5){return db[_0xffca('0x15')]['findAll']({'raw':_0x4a0603[_0xffca('0x16')]?_0x4a0603[_0xffca('0x16')]['raw']===undefined?!![]:![]:!![],'where':_0x4a0603['options']?_0x4a0603['options'][_0xffca('0x17')]||null:null,'attributes':_0x4a0603[_0xffca('0x16')]?_0x4a0603['options'][_0xffca('0x18')]||null:null,'limit':_0x4a0603['options']?_0x4a0603[_0xffca('0x16')][_0xffca('0x19')]||null:null,'include':_0x4a0603[_0xffca('0x16')]?_0x4a0603[_0xffca('0x16')][_0xffca('0x1a')]?_['map'](_0x4a0603[_0xffca('0x16')][_0xffca('0x1a')],function(_0xd75cfa){return{'model':db[_0xd75cfa[_0xffca('0x1b')]],'as':_0xd75cfa['as'],'attributes':_0xd75cfa[_0xffca('0x18')],'include':_0xd75cfa[_0xffca('0x1a')]?_[_0xffca('0x1c')](_0xd75cfa['include'],function(_0x3a9f92){return{'model':db[_0x3a9f92['model']],'as':_0x3a9f92['as'],'attributes':_0x3a9f92['attributes'],'include':_0x3a9f92[_0xffca('0x1a')]?_[_0xffca('0x1c')](_0x3a9f92[_0xffca('0x1a')],function(_0xafc56c){return{'model':db[_0xafc56c[_0xffca('0x1b')]],'as':_0xafc56c['as'],'attributes':_0xafc56c['attributes']};}):[]};}):[]};}):[]:[]})[_0xffca('0xb')](function(_0xfc0fb1){logger[_0xffca('0xc')](_0xffca('0x14'),_0x4a0603);logger[_0xffca('0xe')]('GetTemplate',_0x4a0603,JSON[_0xffca('0x11')](_0xfc0fb1));_0x5601ff(_0xfc0fb1);})['catch'](function(_0x36aab9){logger[_0xffca('0x12')](_0xffca('0x14'),_0x36aab9[_0xffca('0x13')],_0x4a0603);_0x5a4fc5(_0x372abc['error'](0x1f4,_0x36aab9['message']));});});};