Skip to content

Commit

Permalink
fix: check space and proposal exist (#734)
Browse files Browse the repository at this point in the history
  • Loading branch information
wa0x6e authored Oct 28, 2023
1 parent d5667f0 commit 7e6cc67
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/graphql/operations/vp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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, {
Expand Down

0 comments on commit 7e6cc67

Please sign in to comment.