decidim-vocdoni / decidim-module-vocdoni

(WIP) A module for Decidim that brings an elections component based on the Vocdoni SDK and API
GNU Affero General Public License v3.0
7 stars 0 forks source link

Set-up an election on Vocdoni API #9

Closed andreslucena closed 1 year ago

andreslucena commented 1 year ago

Ref.: VOC-ADM-05

As an administrator I want to set-up the configured election on Vocdoni API.

For this I need an interface similar to what Decidim implements in decidim-elections, where the button for setting up the election isn't shown if the different validations aren't fulfilled (ie a Question doesn't have at least two Answers, an Election doesn't have any Question, the Organization has a wallet created, etc).

For setting this up we'll use the Vocdoni JavaScript SDK, with all the metadata added on VOC-ADM-01, VOC-ADM-02 and VOC-ADM-03. The signer will be the Organization wallet from VOC-ADM-04.

As an example of how this can be implemented, you can see the TypeScript example in the vocdoni-sdk repository. Check if there is any more recent and relevant example on that repository as it's currently being developed.

This is the relevant snippet with the metadata for the Election and Questions (VOC-ADM-01 and VOC-ADM-02).

import { Election } from '@vocdoni/sdk';

const createElection = (census, electionType?) => {
  const endDate = new Date();
  endDate.setHours(endDate.getHours() + 10);

  const election = new Election({
    title: 'Election title',
    description: 'Election description',
    header: 'https://source.unsplash.com/random',
    streamUri: 'https://source.unsplash.com/random',
    endDate: endDate.getTime(),
    census,
    electionType: electionType ?? null,
  });

  election.addQuestion('This is a title', 'This is a description', [
    {
      title: 'Option 1',
      value: 0,
    },
    {
      title: 'Option 2',
      value: 1,
    },
  ]);

  return election;
};