From 7e6cc67059aa008f3cf1d7bb8155dd41c2453aea Mon Sep 17 00:00:00 2001 From: Wan <495709+wa0x6e@users.noreply.github.com> Date: Sat, 28 Oct 2023 12:16:54 +0700 Subject: [PATCH] fix: check space and proposal exist (#734) --- src/graphql/operations/vp.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/graphql/operations/vp.ts b/src/graphql/operations/vp.ts index 7c90ef23..4e71601e 100644 --- a/src/graphql/operations/vp.ts +++ b/src/graphql/operations/vp.ts @@ -5,9 +5,13 @@ const scoreAPIUrl = process.env.SCORE_API_URL || 'https://score.snapshot.org'; export default async function (_parent, { voter, space, proposal }) { if (proposal) { - const query = `SELECT * FROM proposals WHERE id = ?`; + const query = `SELECT * FROM proposals WHERE id = ? LIMIT 1`; const [p] = await db.queryAsync(query, [proposal]); + if (!p) { + return Promise.reject(new Error('proposal not found')); + } + return await snapshot.utils.getVp( voter, p.network, @@ -20,6 +24,11 @@ export default async function (_parent, { voter, space, proposal }) { } else if (space) { const query = `SELECT settings FROM spaces WHERE id = ? AND deleted = 0 LIMIT 1`; let [s] = await db.queryAsync(query, [space]); + + if (!s) { + return Promise.reject(new Error('space not found')); + } + s = JSON.parse(s.settings); return await snapshot.utils.getVp(voter, s.network, s.strategies, 'latest', space, false, {