diff --git a/lib/block-service.ts b/lib/block-service.ts new file mode 100644 index 0000000..9288267 --- /dev/null +++ b/lib/block-service.ts @@ -0,0 +1,35 @@ +import { getSelf } from "./auth-service"; +import { db } from "./db"; + +export const isBlockedByUser = async (id: string) => { + try { + const self = await getSelf(); + + const otherUser = await db.user.findUnique({ + where: { + id, + }, + }); + + if (!otherUser) { + throw new Error("User not found"); + } + + if (otherUser.id === self.id) { + return false; + } + + const existingBlock = await db.block.findUnique({ + where: { + blockerId_blockedId: { + blockerId: otherUser.id, + blockedId: self.id, + }, + }, + }); + + return !!existingBlock; + } catch { + return false; + } +};