Built motion from commit (unavailable).|2.4.4
[motion2.git] / server / config / schedule / automaticRenewSubscription.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 _0xaf83=['error','startSubscription','lodash','ioredis','../../mysqldb','../../config/environment','Setting','find','chatTimeout','ChatInteraction','findAll','lastMsgAt','then','update','system','timeout','format','YYYY-MM-DD\x20HH:mm:ss','chatInteraction:update','catch'];(function(_0x1e500e,_0x2c9d74){var _0x10dc5e=function(_0x354423){while(--_0x354423){_0x1e500e['push'](_0x1e500e['shift']());}};_0x10dc5e(++_0x2c9d74);}(_0xaf83,0x1ba));var _0x3af8=function(_0x2f78bd,_0x3c4b24){_0x2f78bd=_0x2f78bd-0x0;var _0x48383e=_0xaf83[_0x2f78bd];return _0x48383e;};'use strict';var _=require(_0x3af8('0x0'));var moment=require('moment');var Redis=require(_0x3af8('0x1'));var db=require(_0x3af8('0x2'))['db'];var config=require(_0x3af8('0x3'));function subscriptionsAutomatic(){var _0x1bda37=0x0;var _0x339b4f=[];return db[_0x3af8('0x4')][_0x3af8('0x5')]({'raw':!![],'attributes':['id',_0x3af8('0x6')],'where':{'id':0x1}})['then'](function(_0x78c608){_0x1bda37=_0x78c608[_0x3af8('0x6')];if(_0x1bda37){return db[_0x3af8('0x7')][_0x3af8('0x8')]({'raw':!![],'attributes':['id',_0x3af8('0x9')],'where':{'closed':![],'lastMsgAt':{'$lt':moment()['subtract'](_0x78c608[_0x3af8('0x6')],'minutes')}}});}else{return[];}})[_0x3af8('0xa')](function(_0x25c9d8){_0x339b4f=_0x25c9d8;if(_0x1bda37){return db[_0x3af8('0x7')][_0x3af8('0xb')]({'closeReason':_0x3af8('0xc'),'disposition':_0x3af8('0xd'),'closed':!![],'closedAt':moment()[_0x3af8('0xe')](_0x3af8('0xf'))},{'where':{'id':_['map'](_0x339b4f||[],'id')}});}})[_0x3af8('0xa')](function(_0x1bffa2){for(var _0x229122=0x0;_0x229122<_0x339b4f['length'];_0x229122++){io['emit'](_0x3af8('0x10'),{'id':_0x339b4f[_0x229122]['id'],'closed':!![]});}})[_0x3af8('0x11')](function(_0x4e038d){console[_0x3af8('0x12')](_0x4e038d);});}exports[_0x3af8('0x13')]=function(){setInterval(function(){return subscriptionsAutomatic();},0x3c*0x3e8);return subscriptionsAutomatic();};