Built motion from commit d1eab355.|2.6.28
[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 _0x1971=['Template,\x20%s,\x20%s','Template,\x20%s,\x20%s,\x20%s','request\x20sent','error','code','message','catch','GetTemplate','Template','findAll','options','raw','where','attributes','limit','map','include','model','debug','stringify','lodash','util','moment','bluebird','ioredis','../../mysqldb','rpc','../../config/environment','jayson/promise','client','http','request','then','info'];(function(_0x21aec3,_0x5c97e9){var _0x288bbc=function(_0x2283fe){while(--_0x2283fe){_0x21aec3['push'](_0x21aec3['shift']());}};_0x288bbc(++_0x5c97e9);}(_0x1971,0x18a));var _0x1197=function(_0x4b2863,_0x494899){_0x4b2863=_0x4b2863-0x0;var _0x567d67=_0x1971[_0x4b2863];return _0x567d67;};'use strict';var _=require(_0x1197('0x0'));var util=require(_0x1197('0x1'));var moment=require(_0x1197('0x2'));var BPromise=require(_0x1197('0x3'));var rs=require('randomstring');var fs=require('fs');var Redis=require(_0x1197('0x4'));var db=require(_0x1197('0x5'))['db'];var utils=require('../../config/utils');var logger=require('../../config/logger')(_0x1197('0x6'));var config=require(_0x1197('0x7'));var jayson=require(_0x1197('0x8'));var client=jayson[_0x1197('0x9')][_0x1197('0xa')]({'port':0x232a});function respondWithRpcPromise(_0x189054,_0x4b6268,_0x58c558){return new BPromise(function(_0x13a67e,_0x49a5e5){return client[_0x1197('0xb')](_0x189054,_0x58c558)[_0x1197('0xc')](function(_0x3a0ec7){logger[_0x1197('0xd')](_0x1197('0xe'),_0x4b6268,'request\x20sent');logger['debug'](_0x1197('0xf'),_0x4b6268,_0x1197('0x10'),JSON['stringify'](_0x3a0ec7));if(_0x3a0ec7[_0x1197('0x11')]){if(_0x3a0ec7[_0x1197('0x11')][_0x1197('0x12')]===0x1f4){logger[_0x1197('0x11')]('Template,\x20%s,\x20%s',_0x4b6268,_0x3a0ec7[_0x1197('0x11')][_0x1197('0x13')]);return _0x49a5e5(_0x3a0ec7[_0x1197('0x11')][_0x1197('0x13')]);}logger[_0x1197('0x11')](_0x1197('0xe'),_0x4b6268,_0x3a0ec7['error'][_0x1197('0x13')]);return _0x13a67e(_0x3a0ec7[_0x1197('0x11')][_0x1197('0x13')]);}else{logger[_0x1197('0xd')]('Template,\x20%s,\x20%s',_0x4b6268,_0x1197('0x10'));_0x13a67e(_0x3a0ec7['result'][_0x1197('0x13')]);}})[_0x1197('0x14')](function(_0xfd3950){logger[_0x1197('0x11')](_0x1197('0xe'),_0x4b6268,_0xfd3950);_0x49a5e5(_0xfd3950);});});}exports[_0x1197('0x15')]=function(_0x17b1ce){var _0x57c4a0=this;return new Promise(function(_0x67c54,_0x241fdd){return db[_0x1197('0x16')][_0x1197('0x17')]({'raw':_0x17b1ce[_0x1197('0x18')]?_0x17b1ce[_0x1197('0x18')][_0x1197('0x19')]===undefined?!![]:![]:!![],'where':_0x17b1ce[_0x1197('0x18')]?_0x17b1ce[_0x1197('0x18')][_0x1197('0x1a')]||null:null,'attributes':_0x17b1ce[_0x1197('0x18')]?_0x17b1ce[_0x1197('0x18')][_0x1197('0x1b')]||null:null,'limit':_0x17b1ce[_0x1197('0x18')]?_0x17b1ce[_0x1197('0x18')][_0x1197('0x1c')]||null:null,'include':_0x17b1ce[_0x1197('0x18')]?_0x17b1ce[_0x1197('0x18')]['include']?_[_0x1197('0x1d')](_0x17b1ce['options'][_0x1197('0x1e')],function(_0x413093){return{'model':db[_0x413093[_0x1197('0x1f')]],'as':_0x413093['as'],'attributes':_0x413093[_0x1197('0x1b')],'include':_0x413093[_0x1197('0x1e')]?_[_0x1197('0x1d')](_0x413093[_0x1197('0x1e')],function(_0xfb133a){return{'model':db[_0xfb133a[_0x1197('0x1f')]],'as':_0xfb133a['as'],'attributes':_0xfb133a[_0x1197('0x1b')],'include':_0xfb133a['include']?_[_0x1197('0x1d')](_0xfb133a[_0x1197('0x1e')],function(_0x444492){return{'model':db[_0x444492[_0x1197('0x1f')]],'as':_0x444492['as'],'attributes':_0x444492[_0x1197('0x1b')]};}):[]};}):[]};}):[]:[]})[_0x1197('0xc')](function(_0x368e36){logger[_0x1197('0xd')](_0x1197('0x15'),_0x17b1ce);logger[_0x1197('0x20')](_0x1197('0x15'),_0x17b1ce,JSON[_0x1197('0x21')](_0x368e36));_0x67c54(_0x368e36);})[_0x1197('0x14')](function(_0x11f002){logger['error'](_0x1197('0x15'),_0x11f002[_0x1197('0x13')],_0x17b1ce);_0x241fdd(_0x57c4a0['error'](0x1f4,_0x11f002['message']));});});};