fix donation func typo
This commit is contained in:
parent
bf02ee35b9
commit
388f5ce9b4
|
@ -0,0 +1,25 @@
|
|||
CREATE OR REPLACE FUNCTION donate(sats INTEGER, user_id INTEGER)
|
||||
RETURNS INTEGER
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
DECLARE
|
||||
user_sats INTEGER;
|
||||
BEGIN
|
||||
PERFORM ASSERT_SERIALIZED();
|
||||
|
||||
SELECT msats / 1000
|
||||
INTO user_sats
|
||||
FROM users WHERE id = user_id;
|
||||
|
||||
IF sats > user_sats THEN
|
||||
RAISE EXCEPTION 'SN_INSUFFICIENT_FUNDS';
|
||||
END IF;
|
||||
|
||||
UPDATE users SET msats = msats - (sats * 1000) WHERE id = user_id;
|
||||
|
||||
INSERT INTO "Donation" (sats, "userId", created_at, updated_at)
|
||||
VALUES (sats, user_id, now_utc(), now_utc());
|
||||
|
||||
RETURN sats;
|
||||
END;
|
||||
$$;
|
Loading…
Reference in New Issue