Add create account functionality
This commit is contained in:
parent
598b9fd7d6
commit
8ef4636635
8 changed files with 145 additions and 12 deletions
|
@ -9,6 +9,7 @@ import { generateDemoSchedule, generateDemoAccounts } from "./generate-demo-sche
|
|||
const schedulePath = "data/schedule.json";
|
||||
const subscriptionsPath = "data/subscriptions.json";
|
||||
const accountsPath = "data/accounts.json";
|
||||
const nextAccountIdPath = "data/next-account-id.json";
|
||||
const sessionsPath = "data/sessions.json";
|
||||
const nextSessionIdPath = "data/next-session-id.json";
|
||||
|
||||
|
@ -45,6 +46,15 @@ export async function writeSubscriptions(subscriptions: Subscription[]) {
|
|||
await writeFile(subscriptionsPath, JSON.stringify(subscriptions, undefined, "\t") + "\n", "utf-8");
|
||||
}
|
||||
|
||||
export async function nextAccountId() {
|
||||
let nextId = await readJson(nextAccountIdPath, 0);
|
||||
if (nextId === 0) {
|
||||
nextId = Math.max(...(await readAccounts()).map(account => account.id), -1) + 1;
|
||||
}
|
||||
await writeFile(nextAccountIdPath, String(nextId + 1), "utf-8");
|
||||
return nextId;
|
||||
}
|
||||
|
||||
export async function readAccounts() {
|
||||
return await readJson(accountsPath, generateDemoAccounts);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue