Skip to content

Commit

Permalink
feat(flag proposal): add ability to flag proposal (#679)
Browse files Browse the repository at this point in the history
* feat(flag proposal): add ability to flag proposal

* fix(mysql): fix error in schema
  • Loading branch information
Todmy authored Sep 28, 2023
1 parent c9a0e5e commit 928a0e2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/graphql/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,12 @@ export function formatUser(user) {

function isFlaggedProposal(proposal) {
const flaggedLinksRegex = new RegExp(flaggedLinks.join('|'), 'i');
return flaggedProposals?.includes(proposal.id) || flaggedLinksRegex.test(proposal.body);
return (
// TODO: remove this check once flagged proposals are migrated to hub db via script
flaggedProposals?.includes(proposal.id) ||
flaggedLinksRegex.test(proposal.body) ||
proposal.flagged
);
}

export function formatProposal(proposal) {
Expand Down
6 changes: 4 additions & 2 deletions src/graphql/operations/proposals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,15 @@ export default async function (parent, args) {
params.push(verifiedSpaces);
}

// TODO: remove part `p.id IN (?)` when flagged proposals are moved from laser DB to snapshot-sequencer DB
if (where.flagged === true && flaggedProposals.length > 0) {
searchSql += ' AND p.id IN (?)';
searchSql += ' AND (p.id IN (?) OR p.flagged = 1)';
params.push(flaggedProposals);
}

// TODO: remove part `p.id NOT IN (?)` when flagged proposals are moved from laser DB to snapshot-sequencer DB
if (where.flagged === false && flaggedProposals.length > 0) {
searchSql += ' AND p.id NOT IN (?)';
searchSql += ' AND (p.id NOT IN (?) AND p.flagged = 0)';
params.push(flaggedProposals);
}

Expand Down
4 changes: 3 additions & 1 deletion src/helpers/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ CREATE TABLE proposals (
scores_total DECIMAL(64,30) NOT NULL,
scores_updated INT(11) NOT NULL,
votes INT(12) NOT NULL,
flagged INT NOT NULL DEFAULT 0,
PRIMARY KEY (id),
INDEX ipfs (ipfs),
INDEX author (author),
Expand All @@ -57,7 +58,8 @@ CREATE TABLE proposals (
INDEX app (app),
INDEX scores_state (scores_state),
INDEX scores_updated (scores_updated),
INDEX votes (votes)
INDEX votes (votes),
INDEX flagged (flagged)
);

CREATE TABLE votes (
Expand Down

0 comments on commit 928a0e2

Please sign in to comment.