Initial import of zappier-edge from zapier monorepo
This commit is contained in:
commit
dd605a746c
125 changed files with 20148 additions and 0 deletions
29
src/credits.ts
Normal file
29
src/credits.ts
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
export interface CreditAdjustment {
|
||||
id: string;
|
||||
customerId: string;
|
||||
cents: number;
|
||||
reason: string;
|
||||
agent: string;
|
||||
at: string;
|
||||
}
|
||||
|
||||
export class CreditLedger {
|
||||
private rows: CreditAdjustment[] = [];
|
||||
|
||||
add(row: Omit<CreditAdjustment, 'id' | 'at'> & { id?: string; at?: string }): CreditAdjustment {
|
||||
const rec: CreditAdjustment = {
|
||||
id: row.id || `crd_${Date.now().toString(36)}`,
|
||||
customerId: row.customerId,
|
||||
cents: row.cents,
|
||||
reason: row.reason,
|
||||
agent: row.agent,
|
||||
at: row.at || new Date().toISOString(),
|
||||
};
|
||||
this.rows.unshift(rec);
|
||||
return rec;
|
||||
}
|
||||
|
||||
list(customerId?: string): CreditAdjustment[] {
|
||||
return customerId ? this.rows.filter((r) => r.customerId === customerId) : this.rows;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue