26 lines
958 B
JavaScript
26 lines
958 B
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.readIdempotencyKey = readIdempotencyKey;
|
|
exports.sendPlaceBetResult = sendPlaceBetResult;
|
|
/** Reads Idempotency-Key header or body field for async bet deduplication. */
|
|
function readIdempotencyKey(req, body) {
|
|
const header = req.headers['idempotency-key'];
|
|
if (typeof header === 'string' && header.trim())
|
|
return header.trim();
|
|
const fromBody = body?.idempotencyKey;
|
|
if (typeof fromBody === 'string' && fromBody.trim())
|
|
return fromBody.trim();
|
|
return undefined;
|
|
}
|
|
/** Sends placeBet result with 201 (sync) or 202 (queued). */
|
|
function sendPlaceBetResult(res, result) {
|
|
if (result.status === 'queued') {
|
|
res.status(202).json({
|
|
status: 'queued',
|
|
idempotencyKey: result.idempotencyKey,
|
|
});
|
|
return;
|
|
}
|
|
res.status(201).json(result.bet);
|
|
}
|
|
//# sourceMappingURL=placeBetResponse.js.map
|