75fc25e268e202f5fbaeaf41112d9039818d89ec
[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 _0x4e57=['include','map','model','util','moment','randomstring','ioredis','../../config/logger','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','stringify','error','code','message','result','catch','GetTemplate','Template','findAll','options','where','attributes','limit'];(function(_0x14add3,_0x13ce8d){var _0x4a174f=function(_0x2b3ed7){while(--_0x2b3ed7){_0x14add3['push'](_0x14add3['shift']());}};_0x4a174f(++_0x13ce8d);}(_0x4e57,0x12c));var _0x74e5=function(_0x3bb367,_0x322abf){_0x3bb367=_0x3bb367-0x0;var _0xab6c49=_0x4e57[_0x3bb367];return _0xab6c49;};'use strict';var _=require('lodash');var util=require(_0x74e5('0x0'));var moment=require(_0x74e5('0x1'));var BPromise=require('bluebird');var rs=require(_0x74e5('0x2'));var fs=require('fs');var Redis=require(_0x74e5('0x3'));var db=require('../../mysqldb')['db'];var utils=require('../../config/utils');var logger=require(_0x74e5('0x4'))(_0x74e5('0x5'));var config=require(_0x74e5('0x6'));var jayson=require(_0x74e5('0x7'));var client=jayson[_0x74e5('0x8')][_0x74e5('0x9')]({'port':0x232a});function respondWithRpcPromise(_0x5920ec,_0x4cb3a5,_0xb4662d){return new BPromise(function(_0x1944d6,_0x203755){return client[_0x74e5('0xa')](_0x5920ec,_0xb4662d)[_0x74e5('0xb')](function(_0x1777a5){logger[_0x74e5('0xc')](_0x74e5('0xd'),_0x4cb3a5,_0x74e5('0xe'));logger[_0x74e5('0xf')](_0x74e5('0x10'),_0x4cb3a5,'request\x20sent',JSON[_0x74e5('0x11')](_0x1777a5));if(_0x1777a5['error']){if(_0x1777a5[_0x74e5('0x12')][_0x74e5('0x13')]===0x1f4){logger[_0x74e5('0x12')](_0x74e5('0xd'),_0x4cb3a5,_0x1777a5['error'][_0x74e5('0x14')]);return _0x203755(_0x1777a5['error'][_0x74e5('0x14')]);}logger['error'](_0x74e5('0xd'),_0x4cb3a5,_0x1777a5[_0x74e5('0x12')]['message']);return _0x1944d6(_0x1777a5['error']['message']);}else{logger[_0x74e5('0xc')]('Template,\x20%s,\x20%s',_0x4cb3a5,_0x74e5('0xe'));_0x1944d6(_0x1777a5[_0x74e5('0x15')][_0x74e5('0x14')]);}})[_0x74e5('0x16')](function(_0x8d0df0){logger[_0x74e5('0x12')](_0x74e5('0xd'),_0x4cb3a5,_0x8d0df0);_0x203755(_0x8d0df0);});});}exports[_0x74e5('0x17')]=function(_0x510d0b){var _0x3627f9=this;return new Promise(function(_0x65763d,_0xcbb441){return db[_0x74e5('0x18')][_0x74e5('0x19')]({'raw':_0x510d0b[_0x74e5('0x1a')]?_0x510d0b[_0x74e5('0x1a')]['raw']===undefined?!![]:![]:!![],'where':_0x510d0b[_0x74e5('0x1a')]?_0x510d0b[_0x74e5('0x1a')][_0x74e5('0x1b')]||null:null,'attributes':_0x510d0b[_0x74e5('0x1a')]?_0x510d0b[_0x74e5('0x1a')][_0x74e5('0x1c')]||null:null,'limit':_0x510d0b[_0x74e5('0x1a')]?_0x510d0b[_0x74e5('0x1a')][_0x74e5('0x1d')]||null:null,'include':_0x510d0b['options']?_0x510d0b[_0x74e5('0x1a')][_0x74e5('0x1e')]?_[_0x74e5('0x1f')](_0x510d0b[_0x74e5('0x1a')][_0x74e5('0x1e')],function(_0x2afe6c){return{'model':db[_0x2afe6c['model']],'as':_0x2afe6c['as'],'attributes':_0x2afe6c[_0x74e5('0x1c')],'include':_0x2afe6c[_0x74e5('0x1e')]?_[_0x74e5('0x1f')](_0x2afe6c[_0x74e5('0x1e')],function(_0x412c49){return{'model':db[_0x412c49[_0x74e5('0x20')]],'as':_0x412c49['as'],'attributes':_0x412c49[_0x74e5('0x1c')],'include':_0x412c49[_0x74e5('0x1e')]?_[_0x74e5('0x1f')](_0x412c49[_0x74e5('0x1e')],function(_0x219307){return{'model':db[_0x219307['model']],'as':_0x219307['as'],'attributes':_0x219307[_0x74e5('0x1c')]};}):[]};}):[]};}):[]:[]})[_0x74e5('0xb')](function(_0xef9800){logger[_0x74e5('0xc')](_0x74e5('0x17'),_0x510d0b);logger[_0x74e5('0xf')](_0x74e5('0x17'),_0x510d0b,JSON['stringify'](_0xef9800));_0x65763d(_0xef9800);})[_0x74e5('0x16')](function(_0x260dca){logger[_0x74e5('0x12')](_0x74e5('0x17'),_0x260dca[_0x74e5('0x14')],_0x510d0b);_0xcbb441(_0x3627f9['error'](0x1f4,_0x260dca['message']));});});};