Skip to content

Commit

Permalink
Added new metadata fields for all type of elections
Browse files Browse the repository at this point in the history
  • Loading branch information
marcvelmer committed Oct 30, 2024
1 parent 2ef5b8a commit 0ca2258
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/types/election/approval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class ApprovalElection extends UnpublishedElection {
public addQuestion(
title: string | MultiLanguage<string>,
description: string | MultiLanguage<string>,
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) {
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/types/election/budget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class BudgetElection extends UnpublishedElection {
public addQuestion(
title: string | MultiLanguage<string>,
description: string | MultiLanguage<string>,
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) {
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/types/election/multichoice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class MultiChoiceElection extends UnpublishedElection {
public addQuestion(
title: string | MultiLanguage<string>,
description: string | MultiLanguage<string>,
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) {
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/types/election/quadratic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class QuadraticElection extends UnpublishedElection {
public addQuestion(
title: string | MultiLanguage<string>,
description: string | MultiLanguage<string>,
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) {
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/types/election/unpublished.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@ export class UnpublishedElection extends Election {
public addQuestion(
title: string | MultiLanguage<string>,
description: string | MultiLanguage<string>,
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;
}),
Expand Down

0 comments on commit 0ca2258

Please sign in to comment.