Update acuc-cache-clear.ts

This commit is contained in:
Nicolas 2024-10-22 20:42:59 -03:00
parent 6ed3104eb6
commit d375bca167

View File

@ -1,15 +1,22 @@
import { Request, Response } from "express"; import { Request, Response } from "express";
import { supabase_service } from "../../../services/supabase"; import { supabase_service } from "../../../services/supabase";
import { clearACUC } from "../../auth"; import { clearACUC } from "../../auth";
import { Logger } from "../../../lib/logger";
export async function acucCacheClearController(req: Request, res: Response) { export async function acucCacheClearController(req: Request, res: Response) {
try {
const team_id: string = req.body.team_id; const team_id: string = req.body.team_id;
const keys = await supabase_service.from("api_keys") const keys = await supabase_service
.from("api_keys")
.select("*") .select("*")
.eq("team_id", team_id); .eq("team_id", team_id);
await Promise.all(keys.data.map(x => clearACUC(x.key))); await Promise.all(keys.data.map((x) => clearACUC(x.key)));
res.json({ ok: true }); res.json({ ok: true });
} catch (error) {
Logger.error(`Error clearing ACUC cache via API route: ${error}`);
res.status(500).json({ error: "Internal server error" });
}
} }