import {Application, RouteRecord, FrontendOrBackendSession, HandlerCallback} from "pinus";
import {checkEvent} from '../../../services/eventSercive';
import { refresh } from '../../../services/refreshService';
module.exports = function(app: Application) {
    return new Filter(app);
}

var Filter = function(this: any, app: Application) {
    this.app = app;
};

Filter.prototype.before = function (routeRecord: RouteRecord, msg: any, session: FrontendOrBackendSession, next: HandlerCallback) {
    
    next(null);
};

Filter.prototype.after = function (err: Error, routeRecord: RouteRecord, msg: any, session: FrontendOrBackendSession, resp: any, next: HandlerCallback) {
    //刷新
    refresh(session);
    return checkEvent(session).then(()=>{
        next(err);
    }).catch(e => {
        console.error(e);
        next(err);
    });    // 奇遇本检查
};