712faa7e1e560fe4d502a20fb6444d2d0e742006
[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 _0x62b9=['../../mysqldb','../../config/utils','rpc','../../config/environment','jayson/promise','client','http','request','then','info','Template,\x20%s,\x20%s','request\x20sent','debug','Template,\x20%s,\x20%s,\x20%s','error','code','message','result','catch','GetTemplate','Template','findAll','options','where','attributes','limit','include','model','map','stringify','util','moment','bluebird'];(function(_0x4045d1,_0x5d14bf){var _0x50764c=function(_0x244610){while(--_0x244610){_0x4045d1['push'](_0x4045d1['shift']());}};_0x50764c(++_0x5d14bf);}(_0x62b9,0x168));var _0x962b=function(_0x1d8a23,_0x1cea94){_0x1d8a23=_0x1d8a23-0x0;var _0x5ad274=_0x62b9[_0x1d8a23];return _0x5ad274;};'use strict';var _=require('lodash');var util=require(_0x962b('0x0'));var moment=require(_0x962b('0x1'));var BPromise=require(_0x962b('0x2'));var rs=require('randomstring');var fs=require('fs');var Redis=require('ioredis');var db=require(_0x962b('0x3'))['db'];var utils=require(_0x962b('0x4'));var logger=require('../../config/logger')(_0x962b('0x5'));var config=require(_0x962b('0x6'));var jayson=require(_0x962b('0x7'));var client=jayson[_0x962b('0x8')][_0x962b('0x9')]({'port':0x232a});function respondWithRpcPromise(_0x24eaee,_0x424072,_0x1b072c){return new BPromise(function(_0x325684,_0x223111){return client[_0x962b('0xa')](_0x24eaee,_0x1b072c)[_0x962b('0xb')](function(_0x8e1ef8){logger[_0x962b('0xc')](_0x962b('0xd'),_0x424072,_0x962b('0xe'));logger[_0x962b('0xf')](_0x962b('0x10'),_0x424072,'request\x20sent',JSON['stringify'](_0x8e1ef8));if(_0x8e1ef8['error']){if(_0x8e1ef8[_0x962b('0x11')][_0x962b('0x12')]===0x1f4){logger['error'](_0x962b('0xd'),_0x424072,_0x8e1ef8[_0x962b('0x11')]['message']);return _0x223111(_0x8e1ef8['error'][_0x962b('0x13')]);}logger[_0x962b('0x11')]('Template,\x20%s,\x20%s',_0x424072,_0x8e1ef8[_0x962b('0x11')][_0x962b('0x13')]);return _0x325684(_0x8e1ef8[_0x962b('0x11')][_0x962b('0x13')]);}else{logger[_0x962b('0xc')]('Template,\x20%s,\x20%s',_0x424072,_0x962b('0xe'));_0x325684(_0x8e1ef8[_0x962b('0x14')]['message']);}})[_0x962b('0x15')](function(_0x2b8924){logger[_0x962b('0x11')](_0x962b('0xd'),_0x424072,_0x2b8924);_0x223111(_0x2b8924);});});}exports[_0x962b('0x16')]=function(_0xa253d7){var _0x2d7449=this;return new Promise(function(_0x1289a4,_0x363780){return db[_0x962b('0x17')][_0x962b('0x18')]({'raw':_0xa253d7['options']?_0xa253d7[_0x962b('0x19')]['raw']===undefined?!![]:![]:!![],'where':_0xa253d7[_0x962b('0x19')]?_0xa253d7['options'][_0x962b('0x1a')]||null:null,'attributes':_0xa253d7[_0x962b('0x19')]?_0xa253d7[_0x962b('0x19')][_0x962b('0x1b')]||null:null,'limit':_0xa253d7[_0x962b('0x19')]?_0xa253d7[_0x962b('0x19')][_0x962b('0x1c')]||null:null,'include':_0xa253d7['options']?_0xa253d7[_0x962b('0x19')][_0x962b('0x1d')]?_['map'](_0xa253d7[_0x962b('0x19')][_0x962b('0x1d')],function(_0x1fb8a1){return{'model':db[_0x1fb8a1['model']],'as':_0x1fb8a1['as'],'attributes':_0x1fb8a1[_0x962b('0x1b')],'include':_0x1fb8a1[_0x962b('0x1d')]?_['map'](_0x1fb8a1[_0x962b('0x1d')],function(_0x433529){return{'model':db[_0x433529[_0x962b('0x1e')]],'as':_0x433529['as'],'attributes':_0x433529['attributes'],'include':_0x433529[_0x962b('0x1d')]?_[_0x962b('0x1f')](_0x433529[_0x962b('0x1d')],function(_0x2d433f){return{'model':db[_0x2d433f[_0x962b('0x1e')]],'as':_0x2d433f['as'],'attributes':_0x2d433f[_0x962b('0x1b')]};}):[]};}):[]};}):[]:[]})['then'](function(_0x4881eb){logger[_0x962b('0xc')](_0x962b('0x16'),_0xa253d7);logger[_0x962b('0xf')](_0x962b('0x16'),_0xa253d7,JSON[_0x962b('0x20')](_0x4881eb));_0x1289a4(_0x4881eb);})['catch'](function(_0x5e669d){logger['error'](_0x962b('0x16'),_0x5e669d[_0x962b('0x13')],_0xa253d7);_0x363780(_0x2d7449[_0x962b('0x11')](0x1f4,_0x5e669d[_0x962b('0x13')]));});});};