import ProjectOidcService from "../Services/ProjectOidcService";
import Response from "../Utils/Response";
import BaseAPI from "./BaseAPI";
import { LIMIT_PER_PROJECT } from "../../Types/Database/LimitMax";
import BadDataException from "../../Types/Exception/BadDataException";
import ObjectID from "../../Types/ObjectID";
import PositiveNumber from "../../Types/PositiveNumber";
import ProjectOIDC from "../../Models/DatabaseModels/ProjectOidc";
export default class ProjectOidcAPI extends BaseAPI {
    constructor() {
        var _a;
        super(ProjectOIDC, ProjectOidcService);
        // OIDC Fetch API
        this.router.post(`${(_a = new this.entityType()
            .getCrudApiPath()) === null || _a === void 0 ? void 0 : _a.toString()}/:projectId/oidc-list`, async (req, res, next) => {
            try {
                const projectId = new ObjectID(req.params["projectId"]);
                if (!projectId) {
                    return Response.sendErrorResponse(req, res, new BadDataException("Invalid project id."));
                }
                const oidc = await this.service.findBy({
                    query: {
                        projectId: projectId,
                        isEnabled: true,
                    },
                    limit: LIMIT_PER_PROJECT,
                    skip: 0,
                    select: {
                        name: true,
                        description: true,
                        _id: true,
                    },
                    props: {
                        isRoot: true,
                    },
                });
                return Response.sendEntityArrayResponse(req, res, oidc, new PositiveNumber(oidc.length), ProjectOIDC);
            }
            catch (err) {
                return next(err);
            }
        });
    }
}
//# sourceMappingURL=ProjectOIDC.js.map