"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.assertionsRouter = void 0;
const drizzle_orm_1 = require("drizzle-orm");
const express_1 = require("express");
const database_1 = require("../../database");
const tables_1 = require("../../database/tables");
const permissions_1 = require("../../util/config/permissions");
const permission_1 = require("../middlewares/permission");
exports.assertionsRouter = (0, express_1.Router)();
// Get all assertions
exports.assertionsRouter.get('/', (0, permission_1.hasPermission)(permissions_1.Permission.PROJECT_READ), async (req, res) => {
    try {
        const db = await (0, database_1.getDb)();
        const assertions = await db.select().from(tables_1.assertionsTable);
        res.json({ data: assertions });
    }
    catch (error) {
        console.error('Error fetching assertions:', error);
        res.status(500).json({ error: 'Failed to fetch assertions' });
    }
});
// Get assertions by group
exports.assertionsRouter.get('/group/:group', (0, permission_1.hasPermission)(permissions_1.Permission.PROJECT_READ), async (req, res) => {
    try {
        const db = await (0, database_1.getDb)();
        const assertions = await db
            .select()
            .from(tables_1.assertionsTable)
            .where((0, drizzle_orm_1.eq)(tables_1.assertionsTable.group, req.params.group));
        res.json({ data: assertions });
    }
    catch (error) {
        console.error('Error fetching assertions by group:', error);
        res.status(500).json({ error: 'Failed to fetch assertions by group' });
    }
});
//# sourceMappingURL=assertions.js.map