version endpoint

This commit is contained in:
Fran Jurmanović
2023-10-02 21:34:48 +02:00
parent c07e743480
commit 224c2f32c7
2 changed files with 16 additions and 14 deletions

View File

@@ -1,11 +1,9 @@
{
"name": "scheduled",
"version": "0.0.1",
"name": "legica-dana",
"version": "0.7.0",
"main": "src/app.ts",
"scripts": {
"start": "bun src/app.ts",
"dev": "nodemon app.ts",
"build": "tsc --build"
"start": "bun src/app.ts"
},
"author": "Fran Jurmanović <fjurma12@outlook.com>",
"license": "MIT",

View File

@@ -4,7 +4,7 @@ import axios from "axios";
import cheerio from "cheerio";
import { Express } from "express";
import { IController, Legica } from "@models";
import { config } from "@constants";
import { APP_VERSION, config } from "@constants";
class ClientController implements IController {
private legicaTask: cron.CronJob | null = null;
@@ -25,6 +25,18 @@ class ClientController implements IController {
res.send(this.legicaTask?.running);
});
this.app.get("/next", (_, res) => {
if (!this.legicaTask?.running) {
res.status(400).send("Task is not running.");
} else {
res.send(this.legicaTask.nextDate().toISO());
}
});
this.app.get("/version", (_, res) => {
res.send(APP_VERSION);
});
this.app.post("/start", (_, res) => {
if (this.legicaTask?.running) {
res.status(400).send("Task already running.");
@@ -43,14 +55,6 @@ class ClientController implements IController {
}
});
this.app.get("/next", (_, res) => {
if (!this.legicaTask?.running) {
res.status(400).send("Task is not running.");
} else {
res.send(this.legicaTask.nextDate().toISO());
}
});
this.app.post("/post-next", async (_, res) => {
try {
await this.sendNextMessage();