feat: garden care reminder bodies, task sync, upload cleanup
- care reminders now fire with plant-specific body ("Time to water Pothos")
via title/body columns on the reminders table (migration 0016)
- bi-directional task sync: checking off a garden-linked task list item
creates a care log; logging care from garden marks the linked task done
(list_items.metadata stores gardenPlantId + gardenCareType linkage)
- upload error response no longer leaks debug detail; error message
corrected from "5 MB" to "100 MB"
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
import { z } from "zod";
|
||||
import { and, eq, sql } from "drizzle-orm";
|
||||
import { db } from "@/lib/db";
|
||||
import { registerItemToggleHook } from "../_core/registry";
|
||||
import type { ModuleManifest, WidgetContext } from "../_core/module";
|
||||
import {
|
||||
loadContainerForShare,
|
||||
@@ -193,4 +196,45 @@ const gardenManifest: ModuleManifest = {
|
||||
],
|
||||
};
|
||||
|
||||
import { gardenCareLogs, gardenPlants } from "./schema";
|
||||
|
||||
registerItemToggleHook("garden.care-task", async ({ metadata, done, userId }) => {
|
||||
if (!done) return;
|
||||
const plantId = metadata.gardenPlantId;
|
||||
const careType = metadata.gardenCareType;
|
||||
if (typeof plantId !== "string" || typeof careType !== "string") return;
|
||||
|
||||
const [plant] = await db
|
||||
.select({ householdId: gardenPlants.householdId })
|
||||
.from(gardenPlants)
|
||||
.where(eq(gardenPlants.id, plantId))
|
||||
.limit(1);
|
||||
|
||||
if (!plant) return;
|
||||
|
||||
// Avoid duplicate log if care was already logged within the last 10 minutes
|
||||
const recentLog = await db
|
||||
.select({ id: gardenCareLogs.id })
|
||||
.from(gardenCareLogs)
|
||||
.where(
|
||||
and(
|
||||
eq(gardenCareLogs.plantId, plantId),
|
||||
eq(gardenCareLogs.careType, careType),
|
||||
sql`${gardenCareLogs.performedAt} > now() - interval '10 minutes'`,
|
||||
),
|
||||
)
|
||||
.limit(1);
|
||||
|
||||
if (recentLog[0]) return;
|
||||
|
||||
await db.insert(gardenCareLogs).values({
|
||||
plantId,
|
||||
householdId: plant.householdId,
|
||||
careType,
|
||||
performedBy: userId,
|
||||
notes: "Logged via task list",
|
||||
performedAt: new Date(),
|
||||
});
|
||||
});
|
||||
|
||||
export default gardenManifest;
|
||||
|
||||
Reference in New Issue
Block a user