diff --git a/src/services/reputation/reputation/member.ts b/src/services/reputation/reputation/member.ts index 7642a7b..6e898ec 100644 --- a/src/services/reputation/reputation/member.ts +++ b/src/services/reputation/reputation/member.ts @@ -11,19 +11,8 @@ export interface LedgerEntry { export class Member { - static localStore: Map; + private static localStore = new Map(); - private id: string; - private reputation: number; - private ledger: LedgerEntry[]; - - constructor(id?: string) { - this.id = id ? id : randomUUID(); - this.reputation = 0; - this.ledger = []; - Member.localStore.set(this.id, this); - } - public static getAllMembers() { return Array.from(Member.localStore.values()); } @@ -32,9 +21,20 @@ export class Member { return Member.localStore.get(id); } - public getId() { return this.id; } - public getReputation() { return this.reputation; } - public getLedger() { return this.ledger; } + private _id: string; + private _reputation: number; + private _ledger: LedgerEntry[]; + + constructor(id?: string) { + this._id = id ? id : randomUUID(); + this._reputation = 0; + this._ledger = []; + Member.localStore.set(this.id, this); + } + + public get id() { return this._id; } + public get reputation() { return this._reputation; } + public get ledger() { return this._ledger; } public postReputation(postId: string, amount: number) { const entry: LedgerEntry = { @@ -45,7 +45,8 @@ export class Member { change: amount, balance: this.reputation + amount } - this.reputation = entry.balance; + this._ledger.push(entry); + this._reputation = entry.balance; return entry; } @@ -58,7 +59,8 @@ export class Member { change: amount, balance: this.reputation + amount } - this.reputation = entry.balance; + this._ledger.push(entry); + this._reputation = entry.balance; return entry; }