fix: tighten sharing and shadcn composition
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { eq } from "drizzle-orm";
|
||||
import { and, eq } from "drizzle-orm";
|
||||
import { db } from "@/lib/db";
|
||||
import type { PublicShareContext, ShareContext } from "@/modules/_core/module";
|
||||
import { notes } from "../schema";
|
||||
|
||||
export type NoteShareData = {
|
||||
@@ -10,7 +11,20 @@ export type NoteShareData = {
|
||||
updatedAt: string;
|
||||
};
|
||||
|
||||
export async function loadNoteForShare(id: string): Promise<NoteShareData | null> {
|
||||
export async function canShareNote(id: string, ctx: ShareContext): Promise<boolean> {
|
||||
const [note] = await db
|
||||
.select({ id: notes.id })
|
||||
.from(notes)
|
||||
.where(and(eq(notes.id, id), eq(notes.householdId, ctx.householdId)))
|
||||
.limit(1);
|
||||
|
||||
return !!note;
|
||||
}
|
||||
|
||||
export async function loadNoteForShare(
|
||||
id: string,
|
||||
ctx: PublicShareContext,
|
||||
): Promise<NoteShareData | null> {
|
||||
const [note] = await db
|
||||
.select({
|
||||
id: notes.id,
|
||||
@@ -20,7 +34,7 @@ export async function loadNoteForShare(id: string): Promise<NoteShareData | null
|
||||
updatedAt: notes.updatedAt,
|
||||
})
|
||||
.from(notes)
|
||||
.where(eq(notes.id, id))
|
||||
.where(and(eq(notes.id, id), eq(notes.householdId, ctx.householdId)))
|
||||
.limit(1);
|
||||
|
||||
if (!note) return null;
|
||||
|
||||
Reference in New Issue
Block a user