import { Get, JsonController } from 'routing-controllers';
import { OpenAPI } from 'routing-controllers-openapi';
import { getConnection } from 'typeorm';
import { config } from '../config';

@JsonController()
export class StatusController {

    @Get('/status')
    @OpenAPI({ description: "A very basic status/health endpoint that just checks if the database connection is available. <br> The available information depth will be expanded later." })
    get() {
        let connection;
        try {
            connection = getConnection();
        } catch {
            throw new Error("sth is wrong, i can feel it....");
        }
        return {
            "controllers": "✔",
            "database connection": "✔"
        };
    }

    @Get('/version')
    @OpenAPI({ description: "A very basic endpoint that just returns the curent package version." })
    getVersion() {
        return {
            "version": config.version
        }
    }
}