feat: update dose retrieval to remove 30-day limit and add sharedBy field in share routes
This commit is contained in:
@@ -2,7 +2,7 @@ import { FastifyInstance } from "fastify";
|
||||
import { z } from "zod";
|
||||
import { db } from "../db/client.js";
|
||||
import { doseTracking, shareTokens } from "../db/schema.js";
|
||||
import { eq, and, gte } from "drizzle-orm";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { requireAuth, getAnonymousUserId } from "../plugins/auth.js";
|
||||
import { env } from "../plugins/env.js";
|
||||
import type { AuthUser } from "../types/fastify.js";
|
||||
@@ -47,17 +47,10 @@ export async function doseRoutes(app: FastifyInstance) {
|
||||
async (request, reply) => {
|
||||
const userId = await getUserId(request, reply);
|
||||
|
||||
// Get doses from last 30 days (to avoid loading too much data)
|
||||
const thirtyDaysAgo = new Date(Date.now() - 30 * 24 * 60 * 60 * 1000);
|
||||
|
||||
// Get all taken doses for this user (no time limit)
|
||||
const doses = await db.select()
|
||||
.from(doseTracking)
|
||||
.where(
|
||||
and(
|
||||
eq(doseTracking.userId, userId),
|
||||
gte(doseTracking.takenAt, thirtyDaysAgo)
|
||||
)
|
||||
);
|
||||
.where(eq(doseTracking.userId, userId));
|
||||
|
||||
return {
|
||||
doses: doses.map((d) => ({
|
||||
@@ -148,17 +141,10 @@ export async function doseRoutes(app: FastifyInstance) {
|
||||
return reply.notFound("Share link not found");
|
||||
}
|
||||
|
||||
// Get doses from last 30 days
|
||||
const thirtyDaysAgo = new Date(Date.now() - 30 * 24 * 60 * 60 * 1000);
|
||||
|
||||
// Get all taken doses for this user (no time limit)
|
||||
const doses = await db.select()
|
||||
.from(doseTracking)
|
||||
.where(
|
||||
and(
|
||||
eq(doseTracking.userId, share.userId),
|
||||
gte(doseTracking.takenAt, thirtyDaysAgo)
|
||||
)
|
||||
);
|
||||
.where(eq(doseTracking.userId, share.userId));
|
||||
|
||||
return {
|
||||
doses: doses.map((d) => ({
|
||||
|
||||
@@ -341,7 +341,7 @@ export async function sendShoutrrrNotification(urlStr: string, title: string, me
|
||||
if (urlStr.startsWith("ntfy://")) {
|
||||
const parsed = new URL(urlStr.replace("ntfy://", "https://"));
|
||||
targetUrl = `https://${parsed.host}${parsed.pathname}`;
|
||||
headers = { "Title": cleanTitle, "Tags": "warning" };
|
||||
headers = { "Title": cleanTitle, "Tags": "pill" };
|
||||
body = message;
|
||||
|
||||
if (parsed.username && parsed.password) {
|
||||
@@ -349,7 +349,7 @@ export async function sendShoutrrrNotification(urlStr: string, title: string, me
|
||||
}
|
||||
} else if (urlStr.startsWith("https://ntfy.") || urlStr.includes("ntfy.sh") || urlStr.includes("/ntfy/")) {
|
||||
targetUrl = urlStr;
|
||||
headers = { "Title": cleanTitle, "Tags": "warning" };
|
||||
headers = { "Title": cleanTitle, "Tags": "pill" };
|
||||
body = message;
|
||||
} else if (urlStr.startsWith("http://") || urlStr.startsWith("https://")) {
|
||||
targetUrl = urlStr;
|
||||
|
||||
@@ -81,6 +81,9 @@ export async function shareRoutes(app: FastifyInstance) {
|
||||
// Get user settings for stock thresholds
|
||||
const [settings] = await db.select().from(userSettings).where(eq(userSettings.userId, share.userId));
|
||||
|
||||
// Get the username of the owner who created this share link
|
||||
const [owner] = await db.select({ username: users.username }).from(users).where(eq(users.id, share.userId));
|
||||
|
||||
// Get medications for this user filtered by takenBy (search in JSON array)
|
||||
// Use SQLite JSON function to check if takenBy is in the array
|
||||
const allMeds = await db.select().from(medications).where(eq(medications.userId, share.userId));
|
||||
@@ -129,6 +132,7 @@ export async function shareRoutes(app: FastifyInstance) {
|
||||
|
||||
return {
|
||||
takenBy: share.takenBy,
|
||||
sharedBy: owner?.username ?? null,
|
||||
scheduleDays: share.scheduleDays,
|
||||
medications: medicationsWithBlisters,
|
||||
stockThresholds: {
|
||||
|
||||
@@ -3390,6 +3390,7 @@ type SharedMedication = {
|
||||
|
||||
type SharedScheduleData = {
|
||||
takenBy: string;
|
||||
sharedBy: string | null;
|
||||
scheduleDays: number;
|
||||
medications: SharedMedication[];
|
||||
stockThresholds?: {
|
||||
@@ -4086,7 +4087,7 @@ function SharedSchedule() {
|
||||
</div>
|
||||
|
||||
<footer className="shared-schedule-footer">
|
||||
<p>{t('share.generatedBy')} MedAssist</p>
|
||||
<p>{t('share.generatedBy')} {data?.sharedBy && <><strong>{data.sharedBy}</strong> · </>}<a href="/">MedAssist</a></p>
|
||||
</footer>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user