50 lines
2.6 KiB
JavaScript
50 lines
2.6 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.createFunding = createFunding;
|
|
exports.listFunding = listFunding;
|
|
exports.findFundingById = findFundingById;
|
|
exports.confirmFunding = confirmFunding;
|
|
exports.cancelFunding = cancelFunding;
|
|
const connection_1 = require("../db/connection");
|
|
const crypto_1 = require("../utils/crypto");
|
|
async function createFunding(input) {
|
|
const rows = await (0, connection_1.query)(`INSERT INTO exchange_funding (wallet_type_id, direction, amount, status, from_address, to_address, notes_encrypted, approved_by, requested_by)
|
|
VALUES ($1, $2, $3, 'pending', $4, $5, $6, $7, $8)
|
|
RETURNING *, amount::text`, [
|
|
input.walletTypeId,
|
|
input.direction,
|
|
input.amount.toString(),
|
|
input.fromAddress ?? null,
|
|
input.toAddress ?? null,
|
|
input.notes ? (0, crypto_1.encryptSensitive)(input.notes) : null,
|
|
input.approvedBy ?? null,
|
|
input.requestedBy ?? null,
|
|
]);
|
|
return rows[0];
|
|
}
|
|
async function listFunding(opts) {
|
|
const limit = Math.min(opts.limit ?? 50, 100);
|
|
const offset = Math.max(opts.offset ?? 0, 0);
|
|
const where = opts.status ? 'WHERE status = $1' : '';
|
|
const countParams = opts.status ? [opts.status] : [];
|
|
const countRows = await (0, connection_1.query)(`SELECT COUNT(*)::text AS count FROM exchange_funding ${where}`, countParams);
|
|
const items = opts.status
|
|
? await (0, connection_1.query)(`SELECT *, amount::text FROM exchange_funding WHERE status = $1 ORDER BY created_at DESC LIMIT $2 OFFSET $3`, [opts.status, limit, offset])
|
|
: await (0, connection_1.query)(`SELECT *, amount::text FROM exchange_funding ORDER BY created_at DESC LIMIT $1 OFFSET $2`, [limit, offset]);
|
|
return { items, total: Number(countRows[0]?.count ?? 0) };
|
|
}
|
|
async function findFundingById(id) {
|
|
const rows = await (0, connection_1.query)('SELECT *, amount::text FROM exchange_funding WHERE id = $1', [id]);
|
|
return rows[0] ?? null;
|
|
}
|
|
async function confirmFunding(id, blockchainTxId, approvedBy) {
|
|
const rows = await (0, connection_1.query)(`UPDATE exchange_funding
|
|
SET status = 'completed', blockchain_tx_id = $2, approved_by = $3, updated_at = NOW()
|
|
WHERE id = $1 AND status = 'pending'
|
|
RETURNING *, amount::text`, [id, blockchainTxId, approvedBy]);
|
|
return rows[0] ?? null;
|
|
}
|
|
async function cancelFunding(id) {
|
|
await (0, connection_1.query)(`UPDATE exchange_funding SET status = 'cancelled', updated_at = NOW() WHERE id = $1 AND status = 'pending'`, [id]);
|
|
}
|
|
//# sourceMappingURL=exchangeFundingRepository.js.map
|