Skip to content

Commit

Permalink
feat: invoice paid event
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeWasTakenn committed Sep 2, 2024
1 parent 44161ac commit 794cd8e
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions server/accounts/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ export async function UpdateInvoice(invoiceId: number, charId: number) {
if (!player?.charId) return 'no_charId';

const invoice = await db.row<{ amount: number; payerId?: number; toAccount: number }>(
'SELECT `amount`, `payerId`, `toAccount` FROM `accounts_invoices` WHERE `id` = ?',
'SELECT * FROM `accounts_invoices` WHERE `id` = ?',
[invoiceId]
);

Expand All @@ -308,11 +308,19 @@ export async function UpdateInvoice(invoiceId: number, charId: number) {

if (!removedBalance || typeof removedBalance === 'string') return removedBalance;

return db.update('UPDATE `accounts_invoices` SET `payerId` = ?, `paidAt` = ? WHERE `id` = ?', [
const invoiceUpdated = db.update('UPDATE `accounts_invoices` SET `payerId` = ?, `paidAt` = ? WHERE `id` = ?', [
player.charId,
new Date(),
invoiceId,
]);

if (!invoiceUpdated) return invoiceUpdated;

invoice.payerId = charId;

emit('ox:invoicePaid', invoice);

return true;
}

export async function CreateInvoice(invoice: OxCreateInvoice) {
Expand Down

0 comments on commit 794cd8e

Please sign in to comment.