Built motion from commit 753c950e.|2.5.42
[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 _0xbf13=['request\x20sent','stringify','error','code','message','result','GetTemplate','Template','options','raw','where','limit','include','map','model','attributes','debug','lodash','util','moment','bluebird','ioredis','../../config/utils','rpc','client','request','then','info','Template,\x20%s,\x20%s'];(function(_0x2e63c3,_0x28fcb0){var _0x3d259b=function(_0x537542){while(--_0x537542){_0x2e63c3['push'](_0x2e63c3['shift']());}};_0x3d259b(++_0x28fcb0);}(_0xbf13,0x1e1));var _0x3bf1=function(_0x527058,_0x297d58){_0x527058=_0x527058-0x0;var _0x3d7ef5=_0xbf13[_0x527058];return _0x3d7ef5;};'use strict';var _=require(_0x3bf1('0x0'));var util=require(_0x3bf1('0x1'));var moment=require(_0x3bf1('0x2'));var BPromise=require(_0x3bf1('0x3'));var rs=require('randomstring');var fs=require('fs');var Redis=require(_0x3bf1('0x4'));var db=require('../../mysqldb')['db'];var utils=require(_0x3bf1('0x5'));var logger=require('../../config/logger')(_0x3bf1('0x6'));var config=require('../../config/environment');var jayson=require('jayson/promise');var client=jayson[_0x3bf1('0x7')]['http']({'port':0x232a});function respondWithRpcPromise(_0x281163,_0xf6291e,_0xc61f1a){return new BPromise(function(_0x5f0116,_0x38c623){return client[_0x3bf1('0x8')](_0x281163,_0xc61f1a)[_0x3bf1('0x9')](function(_0x31d2c9){logger[_0x3bf1('0xa')](_0x3bf1('0xb'),_0xf6291e,_0x3bf1('0xc'));logger['debug']('Template,\x20%s,\x20%s,\x20%s',_0xf6291e,_0x3bf1('0xc'),JSON[_0x3bf1('0xd')](_0x31d2c9));if(_0x31d2c9['error']){if(_0x31d2c9[_0x3bf1('0xe')][_0x3bf1('0xf')]===0x1f4){logger[_0x3bf1('0xe')]('Template,\x20%s,\x20%s',_0xf6291e,_0x31d2c9['error'][_0x3bf1('0x10')]);return _0x38c623(_0x31d2c9[_0x3bf1('0xe')][_0x3bf1('0x10')]);}logger[_0x3bf1('0xe')](_0x3bf1('0xb'),_0xf6291e,_0x31d2c9[_0x3bf1('0xe')][_0x3bf1('0x10')]);return _0x5f0116(_0x31d2c9[_0x3bf1('0xe')]['message']);}else{logger['info'](_0x3bf1('0xb'),_0xf6291e,_0x3bf1('0xc'));_0x5f0116(_0x31d2c9[_0x3bf1('0x11')]['message']);}})['catch'](function(_0x403be0){logger['error']('Template,\x20%s,\x20%s',_0xf6291e,_0x403be0);_0x38c623(_0x403be0);});});}exports[_0x3bf1('0x12')]=function(_0x5ecd87){var _0x43388a=this;return new Promise(function(_0x4ba0df,_0x584986){return db[_0x3bf1('0x13')]['findAll']({'raw':_0x5ecd87[_0x3bf1('0x14')]?_0x5ecd87[_0x3bf1('0x14')][_0x3bf1('0x15')]===undefined?!![]:![]:!![],'where':_0x5ecd87[_0x3bf1('0x14')]?_0x5ecd87[_0x3bf1('0x14')][_0x3bf1('0x16')]||null:null,'attributes':_0x5ecd87[_0x3bf1('0x14')]?_0x5ecd87[_0x3bf1('0x14')]['attributes']||null:null,'limit':_0x5ecd87[_0x3bf1('0x14')]?_0x5ecd87['options'][_0x3bf1('0x17')]||null:null,'include':_0x5ecd87[_0x3bf1('0x14')]?_0x5ecd87[_0x3bf1('0x14')][_0x3bf1('0x18')]?_[_0x3bf1('0x19')](_0x5ecd87[_0x3bf1('0x14')][_0x3bf1('0x18')],function(_0x194d06){return{'model':db[_0x194d06[_0x3bf1('0x1a')]],'as':_0x194d06['as'],'attributes':_0x194d06[_0x3bf1('0x1b')],'include':_0x194d06[_0x3bf1('0x18')]?_[_0x3bf1('0x19')](_0x194d06[_0x3bf1('0x18')],function(_0x46bae6){return{'model':db[_0x46bae6['model']],'as':_0x46bae6['as'],'attributes':_0x46bae6[_0x3bf1('0x1b')],'include':_0x46bae6[_0x3bf1('0x18')]?_[_0x3bf1('0x19')](_0x46bae6[_0x3bf1('0x18')],function(_0x1aa639){return{'model':db[_0x1aa639[_0x3bf1('0x1a')]],'as':_0x1aa639['as'],'attributes':_0x1aa639[_0x3bf1('0x1b')]};}):[]};}):[]};}):[]:[]})[_0x3bf1('0x9')](function(_0x789e73){logger[_0x3bf1('0xa')](_0x3bf1('0x12'),_0x5ecd87);logger[_0x3bf1('0x1c')](_0x3bf1('0x12'),_0x5ecd87,JSON[_0x3bf1('0xd')](_0x789e73));_0x4ba0df(_0x789e73);})['catch'](function(_0x4fecec){logger['error'](_0x3bf1('0x12'),_0x4fecec['message'],_0x5ecd87);_0x584986(_0x43388a[_0x3bf1('0xe')](0x1f4,_0x4fecec['message']));});});};