fix for overloaded pgpsql function
This commit is contained in:
parent
93428e3183
commit
f23da4397f
|
@ -352,9 +352,11 @@ const createItem = async (parent, { title, url, text, parentId }, { me, models }
|
||||||
throw new AuthenticationError('you must be logged in')
|
throw new AuthenticationError('you must be logged in')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(me)
|
||||||
|
|
||||||
const [item] = await serialize(models, models.$queryRaw(
|
const [item] = await serialize(models, models.$queryRaw(
|
||||||
`${SELECT} FROM create_item($1, $2, $3, $4, $5) AS "Item"`,
|
`${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)
|
await createMentions(item, models)
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,12 @@ export default gql`
|
||||||
pageTitle(url: String!): String
|
pageTitle(url: String!): String
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum ItemAct {
|
||||||
|
VOTE
|
||||||
|
BOOST
|
||||||
|
TIP
|
||||||
|
}
|
||||||
|
|
||||||
extend type Mutation {
|
extend type Mutation {
|
||||||
createLink(title: String!, url: String): Item!
|
createLink(title: String!, url: String): Item!
|
||||||
updateLink(id: ID!, 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!
|
updateDiscussion(id: ID!, title: String!, text: String): Item!
|
||||||
createComment(text: String!, parentId: ID!): Item!
|
createComment(text: String!, parentId: ID!): Item!
|
||||||
updateComment(id: ID!, text: String!): 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 {
|
type Items {
|
||||||
|
|
|
@ -12,7 +12,7 @@ export default function UpVote ({ itemId, meSats, className }) {
|
||||||
const [act] = useMutation(
|
const [act] = useMutation(
|
||||||
gql`
|
gql`
|
||||||
mutation act($id: ID!, $sats: Int!) {
|
mutation act($id: ID!, $sats: Int!) {
|
||||||
act(id: $id, act: 'VOTE', sats: $sats)
|
act(id: $id, act: VOTE, sats: $sats)
|
||||||
}`, {
|
}`, {
|
||||||
update (cache, { data: { act } }) {
|
update (cache, { data: { act } }) {
|
||||||
// read in the cached object so we don't use meSats prop
|
// read in the cached object so we don't use meSats prop
|
||||||
|
|
|
@ -90,7 +90,9 @@ BEGIN
|
||||||
END;
|
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)
|
CREATE OR REPLACE FUNCTION create_item(title TEXT, url TEXT, text TEXT, parent_id INTEGER, user_id INTEGER)
|
||||||
RETURNS "Item"
|
RETURNS "Item"
|
||||||
LANGUAGE plpgsql
|
LANGUAGE plpgsql
|
||||||
|
@ -104,14 +106,14 @@ DECLARE
|
||||||
BEGIN
|
BEGIN
|
||||||
PERFORM ASSERT_SERIALIZED();
|
PERFORM ASSERT_SERIALIZED();
|
||||||
|
|
||||||
SELECT (msats / 1000), "freePosts", "freeComments"
|
SELECT (msats / 1000), id, "freePosts", "freeComments"
|
||||||
INTO user_sats, free_posts, free_comments
|
INTO user_sats, free_posts, free_comments
|
||||||
FROM users WHERE id = user_id;
|
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);
|
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
|
IF NOT freebie AND 1 > user_sats THEN
|
||||||
RAISE EXCEPTION 'SN_INSUFFICIENT_FUNDS';
|
RAISE EXCEPTION 'SN_INSUFFICIENT_FUNDS';
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
INSERT INTO "Item" (title, url, text, "userId", "parentId", created_at, updated_at)
|
INSERT INTO "Item" (title, url, text, "userId", "parentId", created_at, updated_at)
|
||||||
|
|
Loading…
Reference in New Issue