Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/test/simulation/fixtures/codeMapper/index.ts
13399 views
1
import type { RequestHandler } from '@sveltejs/kit';
2
import fs from 'fs';
3
import path from 'path';
4
5
export const POST: RequestHandler = async ({ request }) => {
6
const { respondentId, categories, notActionable, highlight } = await request.json();
7
const filePath = path.resolve('data/export.csv');
8
const csv = fs.readFileSync(filePath, 'utf-8');
9
const rows = csv.split('\n');
10
const headers = rows[0];
11
const data = rows.slice(1).map(row => {
12
const fields = row.split(',');
13
if (fields[0] === respondentId) {
14
return [
15
...fields.slice(0, 21),
16
categories.join('|'),
17
notActionable,
18
highlight
19
].join(',');
20
}
21
return row;
22
});
23
fs.writeFileSync(filePath, [headers, ...data].join('\n'));
24
return new Response(null, { status: 200 });
25
};
26