From 9951318180b7e9ced61a0b8d36fd26c7846865e2 Mon Sep 17 00:00:00 2001 From: lxgr-linux Date: Tue, 24 Jan 2023 16:06:15 +0100 Subject: [PATCH] #135 Added Council.ts and fixed small bug --- src/components/elements/CouncilComponent.vue | 3 + src/model/Council.js | 50 ++++++++++++++++ src/model/Council.ts | 60 ++++++++++++++++++++ src/model/User.js | 4 +- src/model/User.ts | 4 +- 5 files changed, 119 insertions(+), 2 deletions(-) create mode 100644 src/model/Council.js create mode 100644 src/model/Council.ts diff --git a/src/components/elements/CouncilComponent.vue b/src/components/elements/CouncilComponent.vue index 95e34b75..b12ff297 100644 --- a/src/components/elements/CouncilComponent.vue +++ b/src/components/elements/CouncilComponent.vue @@ -2,10 +2,12 @@
{ + return WrapHashResponse.from(resp); + }); + council.clearResponses = json.clearResponses?.map(resp => { + return WrapClearResponse.from(resp); + }); + council.treasury = Coin_1.Coin.from(json.treasury); + council.status = CouncelingStatus[json.status]; + return council; + } +} +exports.Council = Council; +class WrapClearResponse { + static from(json) { + return Object.assign(new WrapClearResponse(), json); + } +} +class WrapHashResponse { + static from(json) { + return Object.assign(new WrapHashResponse(), json); + } +} +var Response; +(function (Response) { + Response[Response["Yes"] = 0] = "Yes"; + Response[Response["No"] = 1] = "No"; + Response[Response["Suggestion"] = 2] = "Suggestion"; +})(Response || (Response = {})); +var CouncelingStatus; +(function (CouncelingStatus) { + CouncelingStatus[CouncelingStatus["councilDoesNotExist"] = 0] = "councilDoesNotExist"; + CouncelingStatus[CouncelingStatus["councilOpen"] = 1] = "councilOpen"; + CouncelingStatus[CouncelingStatus["councilCreated"] = 2] = "councilCreated"; + CouncelingStatus[CouncelingStatus["councilClosed"] = 3] = "councilClosed"; + CouncelingStatus[CouncelingStatus["commited"] = 4] = "commited"; + CouncelingStatus[CouncelingStatus["revealed"] = 5] = "revealed"; + CouncelingStatus[CouncelingStatus["suggestionsMade"] = 6] = "suggestionsMade"; +})(CouncelingStatus || (CouncelingStatus = {})); diff --git a/src/model/Council.ts b/src/model/Council.ts new file mode 100644 index 00000000..c391a068 --- /dev/null +++ b/src/model/Council.ts @@ -0,0 +1,60 @@ +import { Coin } from "./Coin"; + +export class Council { + cardId: number + voters: Array + hashResponses: Array = [] + clearResponses: Array = [] + treasury: Coin + status: CouncelingStatus + trialStart: number + + static from(json) { + let council = Object.assign(new Council(), json); + console.log(json) + council.hoshResponses = json.hoshResponses?.map(resp => { + return WrapHashResponse.from(resp) + }) + council.clearResponses = json.clearResponses?.map(resp => { + return WrapClearResponse.from(resp) + }) + council.treasury = Coin.from(json.treasury) + council.status = CouncelingStatus[json.status] + return council + } +} + +class WrapClearResponse { + user: string + response: Response + suggestion: string + + static from(json) { + return Object.assign(new WrapClearResponse(), json); + } +} + +class WrapHashResponse { + user: string + hash: string + + static from(json) { + return Object.assign(new WrapHashResponse(), json); + } +} + +enum Response { + Yes, + No, + Suggestion, +} + +enum CouncelingStatus { + councilDoesNotExist, + councilOpen, + councilCreated, + councilClosed, + commited, + revealed, + suggestionsMade, +} \ No newline at end of file diff --git a/src/model/User.js b/src/model/User.js index 78c2042f..73079a1d 100644 --- a/src/model/User.js +++ b/src/model/User.js @@ -42,6 +42,8 @@ class CouncilParticipation { this.status = ""; } static from(json) { - return Object.assign(new CouncilParticipation(), json); + let cp = Object.assign(new CouncilParticipation(), json); + cp.council = parseInt(json.council); + return cp; } } diff --git a/src/model/User.ts b/src/model/User.ts index 60d7c9d6..7e7c2aab 100644 --- a/src/model/User.ts +++ b/src/model/User.ts @@ -37,6 +37,8 @@ class CouncilParticipation { status: string = "" static from(json) { - return Object.assign(new CouncilParticipation(), json); + let cp = Object.assign(new CouncilParticipation(), json); + cp.council = parseInt(json.council) + return cp } } \ No newline at end of file