73 lines
2.6 KiB
JavaScript
73 lines
2.6 KiB
JavaScript
"use strict";
|
|
var __extends = (this && this.__extends) || function (d, b) {
|
|
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
|
function __() { this.constructor = d; }
|
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
};
|
|
var route_1 = require("./route");
|
|
var redis = require("redis");
|
|
var PravilaRoute = (function (_super) {
|
|
__extends(PravilaRoute, _super);
|
|
function PravilaRoute() {
|
|
return _super.call(this) || this;
|
|
}
|
|
PravilaRoute.create = function (router) {
|
|
console.log("[PravilaRoute::create] Creating pravila route.");
|
|
router.get("/pravila", function (req, res, next) {
|
|
new PravilaRoute().pravila(req, res, next);
|
|
});
|
|
router.post("/pravila/filtri/add", function (req, res, next) {
|
|
new PravilaRoute().pravilaAdd(req, res, next);
|
|
});
|
|
router.get("/pravila/filtri/delete/:id", function (req, res, next) {
|
|
new PravilaRoute().pravilaDelete(req, res, next);
|
|
});
|
|
var client = redis.createClient();
|
|
};
|
|
PravilaRoute.prototype.pravila = function (req, res, next) {
|
|
var _this = this;
|
|
this.title = "Pravila";
|
|
PravilaRoute.client.lrange('filtri', 0, -1, function (err, result) {
|
|
if (err) {
|
|
console.log(err);
|
|
}
|
|
else {
|
|
var options = {
|
|
"message": "Welcome to the Tour of Heros! Pravila"
|
|
};
|
|
_this.render(req, res, "pravila", { seznamFiltrov: result });
|
|
}
|
|
});
|
|
};
|
|
PravilaRoute.prototype.pravilaDelete = function (req, res, next) {
|
|
this.title = "Pravila";
|
|
PravilaRoute.client.lset('filtri', req.params.id, '__deleted__', function (err, result) {
|
|
console.log(req.baseUrl);
|
|
if (err) {
|
|
console.log(err);
|
|
}
|
|
});
|
|
PravilaRoute.client.lrem('filtri', 0, '__deleted__', function (err, result) {
|
|
if (err) {
|
|
console.log(err);
|
|
}
|
|
});
|
|
res.redirect('/pravila');
|
|
};
|
|
PravilaRoute.prototype.pravilaAdd = function (req, res, next) {
|
|
this.title = "Pravila";
|
|
console.log(req.baseUrl);
|
|
PravilaRoute.client.lpush('filtri', req.body.filtri, function (err, result) {
|
|
if (err) {
|
|
console.log(err);
|
|
}
|
|
else {
|
|
res.redirect('/pravila');
|
|
}
|
|
});
|
|
};
|
|
return PravilaRoute;
|
|
}(route_1.BaseRoute));
|
|
PravilaRoute.client = redis.createClient();
|
|
exports.PravilaRoute = PravilaRoute;
|