diff --git a/api/resolvers/item.js b/api/resolvers/item.js index daaa1d2b..1a2e5cf6 100644 --- a/api/resolvers/item.js +++ b/api/resolvers/item.js @@ -352,9 +352,11 @@ const createItem = async (parent, { title, url, text, parentId }, { me, models } throw new AuthenticationError('you must be logged in') } + console.log(me) + const [item] = await serialize(models, models.$queryRaw( `${SELECT} FROM create_item($1, $2, $3, $4, $5) AS "Item"`, - title, url, text, Number(parentId), me.id)) + title, url, text, Number(parentId), Number(me.id))) await createMentions(item, models) diff --git a/api/typeDefs/item.js b/api/typeDefs/item.js index 0397a744..9aa36d4a 100644 --- a/api/typeDefs/item.js +++ b/api/typeDefs/item.js @@ -9,6 +9,12 @@ export default gql` pageTitle(url: String!): String } + enum ItemAct { + VOTE + BOOST + TIP + } + extend type Mutation { createLink(title: String!, url: String): Item! updateLink(id: ID!, title: String!, url: String): Item! @@ -16,7 +22,7 @@ export default gql` updateDiscussion(id: ID!, title: String!, text: String): Item! createComment(text: String!, parentId: ID!): Item! updateComment(id: ID!, text: String!): Item! - act(id: ID!, act: String!, sats: Int): Int! + act(id: ID!, act: ItemAct!, sats: Int): Int! } type Items { diff --git a/components/upvote.js b/components/upvote.js index d5127481..3bd80c41 100644 --- a/components/upvote.js +++ b/components/upvote.js @@ -12,7 +12,7 @@ export default function UpVote ({ itemId, meSats, className }) { const [act] = useMutation( gql` mutation act($id: ID!, $sats: Int!) { - act(id: $id, act: 'VOTE', sats: $sats) + act(id: $id, act: VOTE, sats: $sats) }`, { update (cache, { data: { act } }) { // read in the cached object so we don't use meSats prop diff --git a/prisma/migrations/20210908193444_tips/migration.sql b/prisma/migrations/20210908193444_tips/migration.sql index 219f0b78..a0cad864 100644 --- a/prisma/migrations/20210908193444_tips/migration.sql +++ b/prisma/migrations/20210908193444_tips/migration.sql @@ -90,7 +90,9 @@ BEGIN END; $$; --- if user has free comments or posts, use that +-- make sure we nuke the old versions +DROP FUNCTION create_item(text,text,text,integer,text); + CREATE OR REPLACE FUNCTION create_item(title TEXT, url TEXT, text TEXT, parent_id INTEGER, user_id INTEGER) RETURNS "Item" LANGUAGE plpgsql @@ -104,14 +106,14 @@ DECLARE BEGIN PERFORM ASSERT_SERIALIZED(); - SELECT (msats / 1000), "freePosts", "freeComments" + SELECT (msats / 1000), id, "freePosts", "freeComments" INTO user_sats, free_posts, free_comments FROM users WHERE id = user_id; freebie := (parent_id IS NULL AND free_posts > 0) OR (parent_id IS NOT NULL AND free_comments > 0); IF NOT freebie AND 1 > user_sats THEN - RAISE EXCEPTION 'SN_INSUFFICIENT_FUNDS'; + RAISE EXCEPTION 'SN_INSUFFICIENT_FUNDS'; END IF; INSERT INTO "Item" (title, url, text, "userId", "parentId", created_at, updated_at)