only queue autowithdraw if a wallet is enabled
This commit is contained in:
parent
b6e4f97668
commit
6dedda577b
@ -0,0 +1,23 @@
|
|||||||
|
CREATE OR REPLACE FUNCTION user_auto_withdraw() RETURNS TRIGGER AS $$
|
||||||
|
DECLARE
|
||||||
|
BEGIN
|
||||||
|
INSERT INTO pgboss.job (name, data)
|
||||||
|
SELECT 'autoWithdraw', jsonb_build_object('id', NEW.id)
|
||||||
|
-- only if there isn't already a pending job for this user
|
||||||
|
WHERE NOT EXISTS (
|
||||||
|
SELECT *
|
||||||
|
FROM pgboss.job
|
||||||
|
WHERE name = 'autoWithdraw'
|
||||||
|
AND data->>'id' = NEW.id::TEXT
|
||||||
|
AND state = 'created'
|
||||||
|
)
|
||||||
|
-- and they have an attached wallet (currently all are received only)
|
||||||
|
AND EXISTS (
|
||||||
|
SELECT *
|
||||||
|
FROM "Wallet"
|
||||||
|
WHERE "userId" = NEW.id
|
||||||
|
AND enabled = TRUE
|
||||||
|
);
|
||||||
|
RETURN NEW;
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE plpgsql;
|
Loading…
x
Reference in New Issue
Block a user