import config from '~config'; import dbClient from 'db/client.ts'; interface Plan { id: string; name: string; folder: string; lastUpdated: Date; } const makePlanButtons = (planId: string, deleted: boolean) => deleted ? `` : ``; const makePlanItem = (plan: Plan, deleted: boolean) => `
  • ${plan.folder}${plan.folder && '/'}${plan.name} - ${plan.lastUpdated.toLocaleString()} - ${makePlanButtons(plan.id, deleted)}
  • `; export default async (userId: string, userName: string) => { let failed = false; const plans: Plan[] = await dbClient .query('SELECT id, name, folder, lastUpdated FROM plans WHERE ownerId = ? AND deleted = 0 GROUP BY folder,name,id ORDER BY folder ASC,name ASC', [userId]) .catch((e) => { failed = true; }); if (failed) return "Couldn't read DB."; const deletedPlans: Plan[] = await dbClient .query('SELECT id, name, folder, lastUpdated FROM plans WHERE ownerId = ? AND deleted = 1 GROUP BY folder,name,id ORDER BY folder ASC,name ASC', [userId]) .catch(() => { failed = true; }); if (failed) return "Couldn't read DB."; return `

    This is a very basic management page. Please excuse the number of alert/prompts that will come up when you click on things as it was the quickest way to build it out.

    Please note: anything modifying data will require you to enter your PIN again as both the web view you are looking at and server behind it are completely stateless for simplicity.

    DateTimeStamps on this page are all displayed in the US Eastern time zone. I don't care enough to make this extremely basic page dynamic.

    ${userName}'s Plans:

    ${userName}'s Deleted Plans:

    `; };