38 lines
1.0 KiB
TypeScript
38 lines
1.0 KiB
TypeScript
export default defineEventHandler(async (event) => {
|
|
const xTagHeader = getRequestHeader(event, "x-tag");
|
|
|
|
if (!xTagHeader || xTagHeader !== "094ut234") {
|
|
throw createError({ statusCode: 401, statusMessage: "unauthenticated" });
|
|
}
|
|
|
|
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 berthsLinkFieldId = "cj7v7bb9pa5eyo3"; // Berths 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/${berthsLinkFieldId}/records/${interestId}`,
|
|
{
|
|
method: 'DELETE',
|
|
headers: {
|
|
"xc-token": config.token,
|
|
},
|
|
body: berthRecords,
|
|
}
|
|
);
|
|
|
|
return result;
|
|
});
|