Refactor member

This commit is contained in:
Chegele 2023-07-06 15:45:55 -04:00
parent 07323708b8
commit 824e0a6b39
1 changed files with 19 additions and 17 deletions

View File

@ -11,18 +11,7 @@ export interface LedgerEntry {
export class Member { export class Member {
static localStore: Map<string, Member>; private static localStore = new Map<string, Member>();
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() { public static getAllMembers() {
return Array.from(Member.localStore.values()); return Array.from(Member.localStore.values());
@ -32,9 +21,20 @@ export class Member {
return Member.localStore.get(id); return Member.localStore.get(id);
} }
public getId() { return this.id; } private _id: string;
public getReputation() { return this.reputation; } private _reputation: number;
public getLedger() { return this.ledger; } 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) { public postReputation(postId: string, amount: number) {
const entry: LedgerEntry = { const entry: LedgerEntry = {
@ -45,7 +45,8 @@ export class Member {
change: amount, change: amount,
balance: this.reputation + amount balance: this.reputation + amount
} }
this.reputation = entry.balance; this._ledger.push(entry);
this._reputation = entry.balance;
return entry; return entry;
} }
@ -58,7 +59,8 @@ export class Member {
change: amount, change: amount,
balance: this.reputation + amount balance: this.reputation + amount
} }
this.reputation = entry.balance; this._ledger.push(entry);
this._reputation = entry.balance;
return entry; return entry;
} }