Refactor member
This commit is contained in:
parent
07323708b8
commit
824e0a6b39
|
@ -11,18 +11,7 @@ export interface LedgerEntry {
|
|||
|
||||
export class Member {
|
||||
|
||||
static localStore: 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);
|
||||
}
|
||||
private static localStore = new Map<string, Member>();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue