diff --git a/src/types/election/approval.ts b/src/types/election/approval.ts index 3d121c1..524b1a2 100644 --- a/src/types/election/approval.ts +++ b/src/types/election/approval.ts @@ -26,7 +26,7 @@ export class ApprovalElection extends UnpublishedElection { public addQuestion( title: string | MultiLanguage, description: string | MultiLanguage, - choices: Array<{ title: string; value: number; meta?: CustomMeta } | Choice>, + choices: Array<{ title: string; value?: number; meta?: CustomMeta } | Choice>, meta?: CustomMeta ) { if (this.questions.length > 0) { @@ -36,9 +36,9 @@ export class ApprovalElection extends UnpublishedElection { return super.addQuestion( title, description, - choices.map((choice) => ({ + choices.map((choice, index) => ({ title: typeof choice.title === 'string' ? { default: choice.title } : choice.title, - value: choice.value, + value: choice.value ?? index, meta: choice.meta, })), meta diff --git a/src/types/election/budget.ts b/src/types/election/budget.ts index 799ad46..5cebe31 100644 --- a/src/types/election/budget.ts +++ b/src/types/election/budget.ts @@ -55,7 +55,7 @@ export class BudgetElection extends UnpublishedElection { public addQuestion( title: string | MultiLanguage, description: string | MultiLanguage, - choices: Array<{ title: string; value: number; meta?: CustomMeta } | Choice>, + choices: Array<{ title: string; value?: number; meta?: CustomMeta } | Choice>, meta?: CustomMeta ) { if (this.questions.length > 0) { @@ -65,9 +65,9 @@ export class BudgetElection extends UnpublishedElection { return super.addQuestion( title, description, - choices.map((choice) => ({ + choices.map((choice, index) => ({ title: typeof choice.title === 'string' ? { default: choice.title } : choice.title, - value: choice.value, + value: choice.value ?? index, meta: choice.meta, })), meta diff --git a/src/types/election/multichoice.ts b/src/types/election/multichoice.ts index a5bbe9d..7128adb 100644 --- a/src/types/election/multichoice.ts +++ b/src/types/election/multichoice.ts @@ -35,7 +35,7 @@ export class MultiChoiceElection extends UnpublishedElection { public addQuestion( title: string | MultiLanguage, description: string | MultiLanguage, - choices: Array<{ title: string; value: number; meta?: CustomMeta } | Choice>, + choices: Array<{ title: string; value?: number; meta?: CustomMeta } | Choice>, meta?: CustomMeta ) { if (this.questions.length > 0) { @@ -45,9 +45,9 @@ export class MultiChoiceElection extends UnpublishedElection { return super.addQuestion( title, description, - choices.map((choice) => ({ + choices.map((choice, index) => ({ title: typeof choice.title === 'string' ? { default: choice.title } : choice.title, - value: choice.value, + value: choice.value ?? index, meta: choice.meta, })), meta diff --git a/src/types/election/quadratic.ts b/src/types/election/quadratic.ts index 29fec34..747cf9b 100644 --- a/src/types/election/quadratic.ts +++ b/src/types/election/quadratic.ts @@ -60,7 +60,7 @@ export class QuadraticElection extends UnpublishedElection { public addQuestion( title: string | MultiLanguage, description: string | MultiLanguage, - choices: Array<{ title: string; value: number; meta?: CustomMeta } | Choice>, + choices: Array<{ title: string; value?: number; meta?: CustomMeta } | Choice>, meta?: CustomMeta ) { if (this.questions.length > 0) { @@ -70,9 +70,9 @@ export class QuadraticElection extends UnpublishedElection { return super.addQuestion( title, description, - choices.map((choice) => ({ + choices.map((choice, index) => ({ title: typeof choice.title === 'string' ? { default: choice.title } : choice.title, - value: choice.value, + value: choice.value ?? index, meta: choice.meta, })), meta diff --git a/src/types/election/unpublished.ts b/src/types/election/unpublished.ts index 2bc1a73..c041870 100644 --- a/src/types/election/unpublished.ts +++ b/src/types/election/unpublished.ts @@ -43,16 +43,16 @@ export class UnpublishedElection extends Election { public addQuestion( title: string | MultiLanguage, description: string | MultiLanguage, - choices: Array<{ title: string; value: number; meta?: CustomMeta } | Choice>, + choices: Array<{ title: string; value?: number; meta?: CustomMeta } | Choice>, meta?: CustomMeta ): UnpublishedElection { this._questions.push({ title: typeof title === 'string' ? { default: title } : title, description: typeof description === 'string' ? { default: description } : description, - choices: choices.map((choice) => { + choices: choices.map((choice, index) => { return { title: typeof choice.title === 'string' ? { default: choice.title } : choice.title, - value: choice.value, + value: choice.value ?? index, ...(choice.meta && { meta: choice.meta }), } as IChoice; }),