Built motion from commit ffdca78c.|2.6.24
[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 _0x301e=['code','Template,\x20%s,\x20%s','message','catch','GetTemplate','Template','options','raw','attributes','limit','include','map','model','debug','lodash','util','moment','randomstring','ioredis','../../config/utils','../../config/logger','rpc','../../config/environment','jayson/promise','http','request','then','info','request\x20sent','Template,\x20%s,\x20%s,\x20%s','stringify','error'];(function(_0x31cb5f,_0x2df766){var _0x586042=function(_0x53c807){while(--_0x53c807){_0x31cb5f['push'](_0x31cb5f['shift']());}};_0x586042(++_0x2df766);}(_0x301e,0x6e));var _0xe301=function(_0x47a46f,_0x10bc11){_0x47a46f=_0x47a46f-0x0;var _0x584748=_0x301e[_0x47a46f];return _0x584748;};'use strict';var _=require(_0xe301('0x0'));var util=require(_0xe301('0x1'));var moment=require(_0xe301('0x2'));var BPromise=require('bluebird');var rs=require(_0xe301('0x3'));var fs=require('fs');var Redis=require(_0xe301('0x4'));var db=require('../../mysqldb')['db'];var utils=require(_0xe301('0x5'));var logger=require(_0xe301('0x6'))(_0xe301('0x7'));var config=require(_0xe301('0x8'));var jayson=require(_0xe301('0x9'));var client=jayson['client'][_0xe301('0xa')]({'port':0x232a});function respondWithRpcPromise(_0x230946,_0x3edea1,_0x36357d){return new BPromise(function(_0x3cc54c,_0x305ea1){return client[_0xe301('0xb')](_0x230946,_0x36357d)[_0xe301('0xc')](function(_0xaa4b2){logger[_0xe301('0xd')]('Template,\x20%s,\x20%s',_0x3edea1,_0xe301('0xe'));logger['debug'](_0xe301('0xf'),_0x3edea1,'request\x20sent',JSON[_0xe301('0x10')](_0xaa4b2));if(_0xaa4b2[_0xe301('0x11')]){if(_0xaa4b2[_0xe301('0x11')][_0xe301('0x12')]===0x1f4){logger[_0xe301('0x11')](_0xe301('0x13'),_0x3edea1,_0xaa4b2[_0xe301('0x11')]['message']);return _0x305ea1(_0xaa4b2[_0xe301('0x11')][_0xe301('0x14')]);}logger[_0xe301('0x11')](_0xe301('0x13'),_0x3edea1,_0xaa4b2[_0xe301('0x11')][_0xe301('0x14')]);return _0x3cc54c(_0xaa4b2[_0xe301('0x11')][_0xe301('0x14')]);}else{logger[_0xe301('0xd')](_0xe301('0x13'),_0x3edea1,_0xe301('0xe'));_0x3cc54c(_0xaa4b2['result']['message']);}})[_0xe301('0x15')](function(_0x33b871){logger['error'](_0xe301('0x13'),_0x3edea1,_0x33b871);_0x305ea1(_0x33b871);});});}exports[_0xe301('0x16')]=function(_0x57b2cf){var _0x39ab16=this;return new Promise(function(_0x40673a,_0x29098a){return db[_0xe301('0x17')]['findAll']({'raw':_0x57b2cf[_0xe301('0x18')]?_0x57b2cf['options'][_0xe301('0x19')]===undefined?!![]:![]:!![],'where':_0x57b2cf[_0xe301('0x18')]?_0x57b2cf[_0xe301('0x18')]['where']||null:null,'attributes':_0x57b2cf['options']?_0x57b2cf['options'][_0xe301('0x1a')]||null:null,'limit':_0x57b2cf['options']?_0x57b2cf[_0xe301('0x18')][_0xe301('0x1b')]||null:null,'include':_0x57b2cf['options']?_0x57b2cf[_0xe301('0x18')][_0xe301('0x1c')]?_[_0xe301('0x1d')](_0x57b2cf[_0xe301('0x18')][_0xe301('0x1c')],function(_0xa8cf12){return{'model':db[_0xa8cf12[_0xe301('0x1e')]],'as':_0xa8cf12['as'],'attributes':_0xa8cf12[_0xe301('0x1a')],'include':_0xa8cf12[_0xe301('0x1c')]?_[_0xe301('0x1d')](_0xa8cf12['include'],function(_0x195f1d){return{'model':db[_0x195f1d[_0xe301('0x1e')]],'as':_0x195f1d['as'],'attributes':_0x195f1d[_0xe301('0x1a')],'include':_0x195f1d[_0xe301('0x1c')]?_[_0xe301('0x1d')](_0x195f1d[_0xe301('0x1c')],function(_0x51d848){return{'model':db[_0x51d848[_0xe301('0x1e')]],'as':_0x51d848['as'],'attributes':_0x51d848['attributes']};}):[]};}):[]};}):[]:[]})[_0xe301('0xc')](function(_0x2214f8){logger[_0xe301('0xd')](_0xe301('0x16'),_0x57b2cf);logger[_0xe301('0x1f')]('GetTemplate',_0x57b2cf,JSON[_0xe301('0x10')](_0x2214f8));_0x40673a(_0x2214f8);})['catch'](function(_0x337f7e){logger[_0xe301('0x11')](_0xe301('0x16'),_0x337f7e['message'],_0x57b2cf);_0x29098a(_0x39ab16[_0xe301('0x11')](0x1f4,_0x337f7e[_0xe301('0x14')]));});});};