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

    ${userName}'s Plans:

    ${userName}'s Deleted Plans:

    `; };