7102709e740ff6d78c41364d7bcef8a351f35394
[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 _0xdb76=['client','http','request','then','info','request\x20sent','Template,\x20%s,\x20%s,\x20%s','error','code','message','Template,\x20%s,\x20%s','result','Template','options','raw','attributes','limit','include','map','model','GetTemplate','debug','stringify','catch','lodash','util','moment','bluebird','randomstring','ioredis','../../config/utils','../../config/logger','rpc','../../config/environment'];(function(_0x39154b,_0x2180cd){var _0x7ace85=function(_0x4d9cf8){while(--_0x4d9cf8){_0x39154b['push'](_0x39154b['shift']());}};_0x7ace85(++_0x2180cd);}(_0xdb76,0x1f4));var _0x6db7=function(_0x2d8429,_0x2a6c57){_0x2d8429=_0x2d8429-0x0;var _0x4a889e=_0xdb76[_0x2d8429];return _0x4a889e;};'use strict';var _=require(_0x6db7('0x0'));var util=require(_0x6db7('0x1'));var moment=require(_0x6db7('0x2'));var BPromise=require(_0x6db7('0x3'));var rs=require(_0x6db7('0x4'));var fs=require('fs');var Redis=require(_0x6db7('0x5'));var db=require('../../mysqldb')['db'];var utils=require(_0x6db7('0x6'));var logger=require(_0x6db7('0x7'))(_0x6db7('0x8'));var config=require(_0x6db7('0x9'));var jayson=require('jayson/promise');var client=jayson[_0x6db7('0xa')][_0x6db7('0xb')]({'port':0x232a});function respondWithRpcPromise(_0x9ff5,_0xd96c54,_0x58bc89){return new BPromise(function(_0x4c77f6,_0x5c9ad5){return client[_0x6db7('0xc')](_0x9ff5,_0x58bc89)[_0x6db7('0xd')](function(_0x40c9d8){logger[_0x6db7('0xe')]('Template,\x20%s,\x20%s',_0xd96c54,_0x6db7('0xf'));logger['debug'](_0x6db7('0x10'),_0xd96c54,'request\x20sent',JSON['stringify'](_0x40c9d8));if(_0x40c9d8[_0x6db7('0x11')]){if(_0x40c9d8[_0x6db7('0x11')][_0x6db7('0x12')]===0x1f4){logger['error']('Template,\x20%s,\x20%s',_0xd96c54,_0x40c9d8[_0x6db7('0x11')][_0x6db7('0x13')]);return _0x5c9ad5(_0x40c9d8['error'][_0x6db7('0x13')]);}logger[_0x6db7('0x11')](_0x6db7('0x14'),_0xd96c54,_0x40c9d8[_0x6db7('0x11')][_0x6db7('0x13')]);return _0x4c77f6(_0x40c9d8[_0x6db7('0x11')][_0x6db7('0x13')]);}else{logger[_0x6db7('0xe')](_0x6db7('0x14'),_0xd96c54,_0x6db7('0xf'));_0x4c77f6(_0x40c9d8[_0x6db7('0x15')][_0x6db7('0x13')]);}})['catch'](function(_0x2df971){logger[_0x6db7('0x11')](_0x6db7('0x14'),_0xd96c54,_0x2df971);_0x5c9ad5(_0x2df971);});});}exports['GetTemplate']=function(_0x175dbd){var _0x1ad0f1=this;return new Promise(function(_0x1343e8,_0x5e9d85){return db[_0x6db7('0x16')]['findAll']({'raw':_0x175dbd[_0x6db7('0x17')]?_0x175dbd[_0x6db7('0x17')][_0x6db7('0x18')]===undefined?!![]:![]:!![],'where':_0x175dbd['options']?_0x175dbd[_0x6db7('0x17')]['where']||null:null,'attributes':_0x175dbd[_0x6db7('0x17')]?_0x175dbd[_0x6db7('0x17')][_0x6db7('0x19')]||null:null,'limit':_0x175dbd[_0x6db7('0x17')]?_0x175dbd[_0x6db7('0x17')][_0x6db7('0x1a')]||null:null,'include':_0x175dbd[_0x6db7('0x17')]?_0x175dbd['options'][_0x6db7('0x1b')]?_[_0x6db7('0x1c')](_0x175dbd[_0x6db7('0x17')][_0x6db7('0x1b')],function(_0x4e24e5){return{'model':db[_0x4e24e5[_0x6db7('0x1d')]],'as':_0x4e24e5['as'],'attributes':_0x4e24e5[_0x6db7('0x19')],'include':_0x4e24e5[_0x6db7('0x1b')]?_[_0x6db7('0x1c')](_0x4e24e5[_0x6db7('0x1b')],function(_0x576c38){return{'model':db[_0x576c38[_0x6db7('0x1d')]],'as':_0x576c38['as'],'attributes':_0x576c38[_0x6db7('0x19')],'include':_0x576c38[_0x6db7('0x1b')]?_[_0x6db7('0x1c')](_0x576c38['include'],function(_0x5ebb1b){return{'model':db[_0x5ebb1b['model']],'as':_0x5ebb1b['as'],'attributes':_0x5ebb1b[_0x6db7('0x19')]};}):[]};}):[]};}):[]:[]})[_0x6db7('0xd')](function(_0xf87272){logger[_0x6db7('0xe')](_0x6db7('0x1e'),_0x175dbd);logger[_0x6db7('0x1f')](_0x6db7('0x1e'),_0x175dbd,JSON[_0x6db7('0x20')](_0xf87272));_0x1343e8(_0xf87272);})[_0x6db7('0x21')](function(_0x5bf6cf){logger[_0x6db7('0x11')](_0x6db7('0x1e'),_0x5bf6cf[_0x6db7('0x13')],_0x175dbd);_0x5e9d85(_0x1ad0f1[_0x6db7('0x11')](0x1f4,_0x5bf6cf[_0x6db7('0x13')]));});});};