port-nimara-client-portal/server/api/unlink-berth-recommendation...

40 lines
1.1 KiB
TypeScript
Raw Normal View History

import { getNocoDbConfiguration } from "../utils/nocodb";
import { requireAuth } from "../utils/auth";
2025-06-03 17:57:08 +02:00
export default defineEventHandler(async (event) => {
console.log('[unlink-berth-recommendations] Request received');
2025-06-03 17:57:08 +02:00
// Check authentication (x-tag header OR Keycloak session)
await requireAuth(event);
2025-06-03 17:57:08 +02:00
const body = await readBody(event);
const { interestId, berthIds } = body;
if (!interestId || !berthIds || !Array.isArray(berthIds)) {
throw createError({
statusCode: 400,
statusMessage: "interestId and berthIds array are required"
});
}
const config = getNocoDbConfiguration();
const interestsTableId = "mbs9hjauug4eseo";
const berthRecommendationsLinkFieldId = "cgthyq2e95ajc52"; // Berth Recommendations field
// Format the berth IDs for the API
const berthRecords = berthIds.map(id => ({ Id: id }));
const result = await $fetch(
`${config.url}/api/v2/tables/${interestsTableId}/links/${berthRecommendationsLinkFieldId}/records/${interestId}`,
{
method: 'DELETE',
headers: {
"xc-token": config.token,
},
body: berthRecords,
}
);
return result;
});