Adds habit edit, archive, and undo log features
Enables users to update or archive habits and to undo the latest habit log. Adds PATCH/DELETE API endpoints for habit edit and soft deletion. Introduces UI dialogs and controls for editing and archiving habits, as well as for undoing the most recent log entry directly from the dashboard. Improves log statistics handling by ordering and simplifies last log detection.
This commit is contained in:
@@ -33,26 +33,22 @@ export async function GET() {
|
||||
// Then get aggregated log data for each habit
|
||||
const habitsWithStats = await Promise.all(
|
||||
userHabitsBase.map(async (habit) => {
|
||||
// Get all logs for this habit
|
||||
// Get all logs for this habit, ordered by date desc
|
||||
const logs = await db
|
||||
.select({
|
||||
id: habitLogs.id,
|
||||
loggedAt: habitLogs.loggedAt,
|
||||
})
|
||||
.from(habitLogs)
|
||||
.where(eq(habitLogs.habitId, habit.id));
|
||||
.where(eq(habitLogs.habitId, habit.id))
|
||||
.orderBy(desc(habitLogs.loggedAt));
|
||||
|
||||
// Calculate statistics
|
||||
const totalLogs = logs.length;
|
||||
const logsLastWeek = logs.filter((log) => log.loggedAt >= sevenDaysAgo).length;
|
||||
const logsLastMonth = logs.filter((log) => log.loggedAt >= thirtyDaysAgo).length;
|
||||
const lastLoggedAt =
|
||||
logs.length > 0
|
||||
? logs.reduce(
|
||||
(latest, log) => (log.loggedAt > latest ? log.loggedAt : latest),
|
||||
logs[0].loggedAt,
|
||||
)
|
||||
: null;
|
||||
|
||||
const lastLoggedAt = logs.length > 0 ? logs[0].loggedAt : null;
|
||||
|
||||
return {
|
||||
id: habit.id,
|
||||
name: habit.name,
|
||||
|
||||
Reference in New Issue
Block a user