From 1b450b21ff47c23c40e74d9dfa00f4a426637417 Mon Sep 17 00:00:00 2001 From: Michael Holley Date: Sat, 11 Jan 2025 16:14:00 +0100 Subject: [PATCH] sorted values --- README.md | 2 ++ src/lib/server/habit.ts | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7f3b6f2..985f341 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,8 @@ # HabitKit +[![Build & Publish](https://github.com/MichaelHolley/HabitKit/actions/workflows/nixpacks_publish.yml/badge.svg?branch=main)](https://github.com/MichaelHolley/HabitKit/actions/workflows/nixpacks_publish.yml) + A simple and intuitive app to track, build, and maintain your habits for a better you! ![image](https://github.com/user-attachments/assets/1fcd0733-f82f-474f-a1b5-844f9167aae8) diff --git a/src/lib/server/habit.ts b/src/lib/server/habit.ts index 87aedbe..4539b08 100644 --- a/src/lib/server/habit.ts +++ b/src/lib/server/habit.ts @@ -1,12 +1,19 @@ +import { Prisma } from '@prisma/client'; import { prisma } from './prisma'; export const getHabitForUser = async (id: string, userId: string) => { - return await prisma.habit.findUnique({ + let habit = await prisma.habit.findUnique({ where: { id: id, userId: userId } }); + + if (!habit) return null; + + habit = { ...habit, dates: (habit.dates as Prisma.JsonArray).sort().reverse() }; + + return habit; }; export const getUserHabits = async (userId: string) => {