import AcmeChallenge from "../../Models/DatabaseModels/AcmeChallenge";
import NotFoundException from "../../Types/Exception/NotFoundException";
import AcmeChallengeService from "../Services/AcmeChallengeService";
import Express from "../Utils/Express";
import Response from "../Utils/Response";
import BaseAPI from "./BaseAPI";
export default class AcmeChallengeAPI extends BaseAPI {
    constructor() {
        super(AcmeChallenge, AcmeChallengeService);
        this.wellKnownRouter = Express.getRouter();
        this.wellKnownRouter.get("/acme-challenge/.well-known/:token", async (req, res, next) => {
            try {
                const challenge = await AcmeChallengeService.findOneBy({
                    query: {
                        token: req.params["token"],
                    },
                    select: {
                        challenge: true,
                    },
                    props: {
                        isRoot: true,
                    },
                });
                if (!challenge) {
                    return next(new NotFoundException("Challenge not found"));
                }
                return Response.sendTextResponse(req, res, challenge.challenge);
            }
            catch (err) {
                return next(err);
            }
        });
        this.router.use("/", this.wellKnownRouter);
    }
    getWellKnownRouter() {
        return this.wellKnownRouter;
    }
}
//# sourceMappingURL=AcmeChallengeAPI.js.map