This commit is contained in:
seb
2026-07-06 01:31:11 +02:00
commit 917930d0fa
34 changed files with 2912 additions and 0 deletions

48
src/endpoints/order.js Normal file
View File

@@ -0,0 +1,48 @@
import { sendJson } from '../http.js';
import { logOrder } from '../order-log.js';
export const method = 'POST';
export const path = '/v1/order';
function parseBody(buffer) {
if (!buffer || !buffer.length) {
return null;
}
try {
return JSON.parse(buffer.toString('utf8'));
} catch {
return undefined;
}
}
function getOrders(body) {
if (!body || typeof body !== 'object') {
return [];
}
if (Array.isArray(body.orders)) {
return body.orders;
}
return [];
}
export async function handle(req, res) {
const body = parseBody(req.rawBody);
if (body === undefined) {
return sendJson(res, 500, []);
}
const orders = getOrders(body);
const results = orders.map((order) => {
logOrder(order);
const externalOrderId = String(order?.externalId ?? '');
return {
status: 'OK',
externalOrderId,
message: '',
};
});
return sendJson(res, 200, results);
}