b5f9a2a225233073bfd8b8bd8e1a9ded7774b5ab
[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 _0xba6f=['catch','lodash','util','moment','bluebird','../../config/utils','../../config/logger','../../config/environment','jayson/promise','client','http','then','info','Template,\x20%s,\x20%s','request\x20sent','debug','Template,\x20%s,\x20%s,\x20%s','stringify','error','message','result','GetTemplate','Template','findAll','raw','options','attributes','include','model','map'];(function(_0xccb4e7,_0x418ce4){var _0x1ab90c=function(_0x19cc83){while(--_0x19cc83){_0xccb4e7['push'](_0xccb4e7['shift']());}};_0x1ab90c(++_0x418ce4);}(_0xba6f,0xb5));var _0xfba6=function(_0x25b854,_0x2e19ff){_0x25b854=_0x25b854-0x0;var _0x35bcd8=_0xba6f[_0x25b854];return _0x35bcd8;};'use strict';var _=require(_0xfba6('0x0'));var util=require(_0xfba6('0x1'));var moment=require(_0xfba6('0x2'));var BPromise=require(_0xfba6('0x3'));var rs=require('randomstring');var fs=require('fs');var Redis=require('ioredis');var db=require('../../mysqldb')['db'];var utils=require(_0xfba6('0x4'));var logger=require(_0xfba6('0x5'))('rpc');var config=require(_0xfba6('0x6'));var jayson=require(_0xfba6('0x7'));var client=jayson[_0xfba6('0x8')][_0xfba6('0x9')]({'port':0x232a});function respondWithRpcPromise(_0x23a8fc,_0x343847,_0x125e02){return new BPromise(function(_0x54f268,_0x1937f4){return client['request'](_0x23a8fc,_0x125e02)[_0xfba6('0xa')](function(_0x53fcdc){logger[_0xfba6('0xb')](_0xfba6('0xc'),_0x343847,_0xfba6('0xd'));logger[_0xfba6('0xe')](_0xfba6('0xf'),_0x343847,_0xfba6('0xd'),JSON[_0xfba6('0x10')](_0x53fcdc));if(_0x53fcdc[_0xfba6('0x11')]){if(_0x53fcdc[_0xfba6('0x11')]['code']===0x1f4){logger[_0xfba6('0x11')](_0xfba6('0xc'),_0x343847,_0x53fcdc[_0xfba6('0x11')][_0xfba6('0x12')]);return _0x1937f4(_0x53fcdc[_0xfba6('0x11')]['message']);}logger[_0xfba6('0x11')](_0xfba6('0xc'),_0x343847,_0x53fcdc[_0xfba6('0x11')][_0xfba6('0x12')]);return _0x54f268(_0x53fcdc['error'][_0xfba6('0x12')]);}else{logger[_0xfba6('0xb')](_0xfba6('0xc'),_0x343847,_0xfba6('0xd'));_0x54f268(_0x53fcdc[_0xfba6('0x13')][_0xfba6('0x12')]);}})['catch'](function(_0x47350e){logger[_0xfba6('0x11')](_0xfba6('0xc'),_0x343847,_0x47350e);_0x1937f4(_0x47350e);});});}exports[_0xfba6('0x14')]=function(_0x471f38){var _0x2a75ed=this;return new Promise(function(_0x4e56eb,_0x470fa0){return db[_0xfba6('0x15')][_0xfba6('0x16')]({'raw':_0x471f38['options']?_0x471f38['options'][_0xfba6('0x17')]===undefined?!![]:![]:!![],'where':_0x471f38[_0xfba6('0x18')]?_0x471f38[_0xfba6('0x18')]['where']||null:null,'attributes':_0x471f38[_0xfba6('0x18')]?_0x471f38[_0xfba6('0x18')][_0xfba6('0x19')]||null:null,'limit':_0x471f38[_0xfba6('0x18')]?_0x471f38[_0xfba6('0x18')]['limit']||null:null,'include':_0x471f38[_0xfba6('0x18')]?_0x471f38[_0xfba6('0x18')]['include']?_['map'](_0x471f38[_0xfba6('0x18')][_0xfba6('0x1a')],function(_0x52885e){return{'model':db[_0x52885e[_0xfba6('0x1b')]],'as':_0x52885e['as'],'attributes':_0x52885e[_0xfba6('0x19')],'include':_0x52885e[_0xfba6('0x1a')]?_[_0xfba6('0x1c')](_0x52885e[_0xfba6('0x1a')],function(_0x357a1d){return{'model':db[_0x357a1d[_0xfba6('0x1b')]],'as':_0x357a1d['as'],'attributes':_0x357a1d[_0xfba6('0x19')],'include':_0x357a1d['include']?_[_0xfba6('0x1c')](_0x357a1d['include'],function(_0x363aa2){return{'model':db[_0x363aa2['model']],'as':_0x363aa2['as'],'attributes':_0x363aa2[_0xfba6('0x19')]};}):[]};}):[]};}):[]:[]})[_0xfba6('0xa')](function(_0x26f2af){logger[_0xfba6('0xb')]('GetTemplate',_0x471f38);logger[_0xfba6('0xe')]('GetTemplate',_0x471f38,JSON[_0xfba6('0x10')](_0x26f2af));_0x4e56eb(_0x26f2af);})[_0xfba6('0x1d')](function(_0x5f08fd){logger[_0xfba6('0x11')]('GetTemplate',_0x5f08fd[_0xfba6('0x12')],_0x471f38);_0x470fa0(_0x2a75ed[_0xfba6('0x11')](0x1f4,_0x5f08fd['message']));});});};