Files
kieferrm 333d9a4053 Hello Copilot
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
2025-06-27 11:35:20 +02:00

25 lines
759 B
TypeScript

import type { RequestHandler } from '@sveltejs/kit';
import fs from 'fs';
import path from 'path';
export const POST: RequestHandler = async ({ request }) => {
const { respondentId, categories, notActionable, highlight } = await request.json();
const filePath = path.resolve('data/export.csv');
const csv = fs.readFileSync(filePath, 'utf-8');
const rows = csv.split('\n');
const headers = rows[0];
const data = rows.slice(1).map(row => {
const fields = row.split(',');
if (fields[0] === respondentId) {
return [
...fields.slice(0, 21),
categories.join('|'),
notActionable,
highlight
].join(',');
}
return row;
});
fs.writeFileSync(filePath, [headers, ...data].join('\n'));
return new Response(null, { status: 200 });
};