2025-06-17 05:33:00 +10:00
|
|
|
// Copyright 2025 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import { sql } from '../util';
|
|
|
|
|
|
|
|
import type { DonationReceipt } from '../../types/Donations';
|
|
|
|
import type { ReadableDB, WritableDB } from '../Interface';
|
|
|
|
|
|
|
|
export function getAllDonationReceipts(db: ReadableDB): Array<DonationReceipt> {
|
|
|
|
const donationReceipts = db
|
|
|
|
.prepare('SELECT * FROM donationReceipts ORDER BY timestamp DESC;')
|
2025-07-02 06:33:36 +10:00
|
|
|
.all<DonationReceipt>();
|
2025-06-17 05:33:00 +10:00
|
|
|
|
2025-07-02 06:33:36 +10:00
|
|
|
return donationReceipts;
|
2025-06-17 05:33:00 +10:00
|
|
|
}
|
|
|
|
export function getDonationReceiptById(
|
|
|
|
db: ReadableDB,
|
|
|
|
id: string
|
|
|
|
): DonationReceipt | undefined {
|
|
|
|
const [query, parameters] =
|
|
|
|
sql`SELECT * FROM donationReceipts WHERE id = ${id}`;
|
2025-07-02 06:33:36 +10:00
|
|
|
return db.prepare(query).get<DonationReceipt>(parameters);
|
2025-06-17 05:33:00 +10:00
|
|
|
}
|
|
|
|
export function _deleteAllDonationReceipts(db: WritableDB): void {
|
|
|
|
db.prepare('DELETE FROM donationReceipts;').run();
|
|
|
|
}
|
|
|
|
export function deleteDonationReceiptById(db: WritableDB, id: string): void {
|
|
|
|
const [query, parameters] =
|
|
|
|
sql`DELETE FROM donationReceipts WHERE id = ${id};`;
|
|
|
|
db.prepare(query).run(parameters);
|
|
|
|
}
|
|
|
|
export function createDonationReceipt(
|
|
|
|
db: WritableDB,
|
|
|
|
receipt: DonationReceipt
|
|
|
|
): void {
|
|
|
|
db.prepare(
|
|
|
|
`
|
|
|
|
INSERT INTO donationReceipts(
|
|
|
|
id,
|
|
|
|
currencyType,
|
|
|
|
paymentAmount,
|
|
|
|
timestamp
|
|
|
|
) VALUES (
|
|
|
|
$id,
|
|
|
|
$currencyType,
|
|
|
|
$paymentAmount,
|
|
|
|
$timestamp
|
|
|
|
);
|
|
|
|
`
|
2025-07-02 06:33:36 +10:00
|
|
|
).run(receipt);
|
2025-06-17 05:33:00 +10:00
|
|
|
}
|