Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: check space and proposal exist #734

Merged
merged 1 commit into from
Oct 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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