add earned sats to items
This commit is contained in:
parent
fbd746b023
commit
d948a653c9
|
@ -106,7 +106,7 @@ export default {
|
|||
if (meFull.noteItemSats) {
|
||||
queries.push(
|
||||
`(SELECT "Item".id::TEXT, MAX("ItemAct".created_at) AS "sortTime",
|
||||
floor(sum("ItemAct".msats)/1000) as "earnedSats", 'Votification' AS type
|
||||
MAX("Item".msats/1000) as "earnedSats", 'Votification' AS type
|
||||
FROM "Item"
|
||||
JOIN "ItemAct" ON "ItemAct"."itemId" = "Item".id
|
||||
WHERE "ItemAct"."userId" <> $1
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
CREATE OR REPLACE FUNCTION earn(user_id INTEGER, earn_msats BIGINT, created_at TIMESTAMP(3),
|
||||
type "EarnType", type_id INTEGER, rank INTEGER)
|
||||
RETURNS void AS $$
|
||||
DECLARE
|
||||
BEGIN
|
||||
PERFORM ASSERT_SERIALIZED();
|
||||
-- insert into earn
|
||||
INSERT INTO "Earn" (msats, "userId", created_at, type, "typeId", rank)
|
||||
VALUES (earn_msats, user_id, created_at, type, type_id, rank);
|
||||
|
||||
-- give the user the sats
|
||||
UPDATE users
|
||||
SET msats = msats + earn_msats, "stackedMsats" = "stackedMsats" + earn_msats
|
||||
WHERE id = user_id;
|
||||
|
||||
IF type = 'POST' OR type = 'COMMENT' THEN
|
||||
PERFORM sats_after_tip(type_id, NULL, earn_msats);
|
||||
END IF;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
Loading…
Reference in New Issue