import config from '~config'; import dbClient from 'db/client.ts'; interface Plan { id: string; name: string; folder: string; lastUpdated: Date; } const zeroPad = (s: number) => s.toString().padStart(2, '0'); const formatDateTime = (d: Date) => `${d.getFullYear()}/${zeroPad(d.getMonth() + 1)}/${zeroPad(d.getDate())} ${d.getHours() === 12 ? 12 : d.getHours() % 12}:${zeroPad(d.getMinutes())} ${d.getHours() >= 12 ? 'PM' : 'AM'}`; const makePlanButtons = (planId: string, deleted: boolean) => deleted ? `` : ``; const makePlanItem = (plan: Plan, deleted: boolean) => `
  • ${plan.folder}${plan.folder && '/'}${plan.name} - ${formatDateTime(plan.lastUpdated)} - ${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.

    ${userName}'s Plans:

    ${userName}'s Deleted Plans:

    `; };