import { Router } from "express";
import { apiReturn } from "../utils/returnHelper.utils.js";
import { runDatamartQuery } from "./datamart.controller.js";

const r = Router();

type Options = {
	name: string;
	value: string;
};

r.get("/:name", async (req, res) => {
	const { name } = req.params;
	const options = req.query as Options;

	const dataRan = await runDatamartQuery({ name, options });
	return apiReturn(res, {
		success: dataRan.success,
		level: "info",
		module: "datamart",
		subModule: "query",
		message: dataRan.message,
		data: dataRan.data,
		status: 200,
	});
});

export default r;
