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,19 +11,8 @@ export interface LedgerEntry {
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() {
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;
}